From a5417687f5ef1efcbe007740c4bfea724fc56445 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Thu, 5 Dec 2024 21:50:28 +0100 Subject: [PATCH] feat: recursive types in model definition --- Cargo.lock | 56 ++-- Cargo.toml | 4 +- .../src/plugins/typescript/generator/enum.rs | 9 +- .../plugins/typescript/generator/interface.rs | 8 +- .../src/plugins/typescript/generator/mod.rs | 260 +++++++++++++++++- .../plugins/typescript/generator/schema.rs | 23 +- 6 files changed, 308 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41ff1b29b5..76312c16a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2469,15 +2469,15 @@ dependencies = [ [[package]] name = "cainome" version = "0.4.8" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.8#53f989af513adc30c5576898c4a586bb3cd71d63" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.10#6fefd8bf4370c77d8834d18a2ae3c59d3a5e8dd5" dependencies = [ "anyhow", "async-trait", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-cairo-serde-derive 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-rs-macro 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-cairo-serde-derive 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-rs-macro 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", "camino", "clap", "clap_complete", @@ -2495,9 +2495,11 @@ dependencies = [ [[package]] name = "cainome-cairo-serde" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.10#6fefd8bf4370c77d8834d18a2ae3c59d3a5e8dd5" dependencies = [ + "num-bigint", "serde", + "serde_with 3.11.0", "starknet 0.12.0", "thiserror", ] @@ -2505,11 +2507,9 @@ dependencies = [ [[package]] name = "cainome-cairo-serde" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.8#53f989af513adc30c5576898c4a586bb3cd71d63" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ - "num-bigint", "serde", - "serde_with 3.11.0", "starknet 0.12.0", "thiserror", ] @@ -2527,7 +2527,7 @@ dependencies = [ [[package]] name = "cainome-cairo-serde-derive" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.8#53f989af513adc30c5576898c4a586bb3cd71d63" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.10#6fefd8bf4370c77d8834d18a2ae3c59d3a5e8dd5" dependencies = [ "proc-macro2", "quote", @@ -2549,7 +2549,7 @@ dependencies = [ [[package]] name = "cainome-parser" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.10#6fefd8bf4370c77d8834d18a2ae3c59d3a5e8dd5" dependencies = [ "convert_case 0.6.0", "quote", @@ -2562,7 +2562,7 @@ dependencies = [ [[package]] name = "cainome-parser" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.8#53f989af513adc30c5576898c4a586bb3cd71d63" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "convert_case 0.6.0", "quote", @@ -2588,11 +2588,11 @@ dependencies = [ [[package]] name = "cainome-rs" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.10#6fefd8bf4370c77d8834d18a2ae3c59d3a5e8dd5" dependencies = [ "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", "camino", "prettyplease", "proc-macro2", @@ -2606,11 +2606,11 @@ dependencies = [ [[package]] name = "cainome-rs" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.8#53f989af513adc30c5576898c4a586bb3cd71d63" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "camino", "prettyplease", "proc-macro2", @@ -2642,12 +2642,12 @@ dependencies = [ [[package]] name = "cainome-rs-macro" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.10#6fefd8bf4370c77d8834d18a2ae3c59d3a5e8dd5" dependencies = [ "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", - "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", "proc-macro-error", "proc-macro2", "quote", @@ -2660,12 +2660,12 @@ dependencies = [ [[package]] name = "cainome-rs-macro" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.8#53f989af513adc30c5576898c4a586bb3cd71d63" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.4.2#4e3924fb82b7299d56d3619aa5d7b9863f581e0a" dependencies = [ "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", - "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.2)", "proc-macro-error", "proc-macro2", "quote", @@ -8380,7 +8380,7 @@ dependencies = [ "alloy-primitives", "anyhow", "assert_matches", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.8)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.10)", "clap", "console", "dojo-utils", diff --git a/Cargo.toml b/Cargo.toml index eebf5294a5..d99ac8043e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,8 +71,8 @@ debug = true inherits = "release" [workspace.dependencies] -cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.8", features = [ "abigen-rs" ] } -cainome-cairo-serde = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.8" } +cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.10", features = [ "abigen-rs" ] } +cainome-cairo-serde = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.4.10" } dojo-utils = { path = "crates/dojo/utils" } # metrics diff --git a/crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs b/crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs index c28a5fd37a..a80df627c4 100644 --- a/crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs +++ b/crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs @@ -1,13 +1,14 @@ use cainome::parser::tokens::{Composite, CompositeType}; +use super::constants::{CAIRO_ENUM_IMPORT, CAIRO_ENUM_TOKEN, SN_IMPORT_SEARCH}; +use super::token_is_custom_enum; use crate::error::BindgenResult; use crate::plugins::typescript::generator::JsType; use crate::plugins::{BindgenModelGenerator, Buffer}; -use super::constants::{CAIRO_ENUM_IMPORT, CAIRO_ENUM_TOKEN, SN_IMPORT_SEARCH}; -use super::token_is_custom_enum; - -const CAIRO_ENUM_TYPE_IMPL: &str = "export type TypedCairoEnum = CairoCustomEnum & {\n\tvariant: { [K in keyof T]: T[K] | undefined };\n\tunwrap(): T[keyof T];\n}\n"; +const CAIRO_ENUM_TYPE_IMPL: &str = "export type TypedCairoEnum = CairoCustomEnum & \ + {\n\tvariant: { [K in keyof T]: T[K] | undefined \ + };\n\tunwrap(): T[keyof T];\n}\n"; pub(crate) struct TsEnumGenerator; diff --git a/crates/dojo/bindgen/src/plugins/typescript/generator/interface.rs b/crates/dojo/bindgen/src/plugins/typescript/generator/interface.rs index e58b3f6d9c..15defd7bcd 100644 --- a/crates/dojo/bindgen/src/plugins/typescript/generator/interface.rs +++ b/crates/dojo/bindgen/src/plugins/typescript/generator/interface.rs @@ -40,6 +40,11 @@ impl BindgenModelGenerator for TsInterfaceGenerator { if token.r#type != CompositeType::Struct || token.inners.is_empty() { return Ok(String::new()); } + if buffer + .has(format!("// Type definition for `{path}` struct", path = token.type_path).as_str()) + { + return Ok(String::new()); + } self.check_import(token, buffer); self.add_input_type(buffer); @@ -124,7 +129,8 @@ mod tests { result, "// Type definition for `core::test::TestStruct` struct\nexport interface TestStruct \ {\n\tfieldOrder: string[];\n\tfield1: BigNumberish;\n\tfield2: \ - BigNumberish;\n\tfield3: BigNumberish;\n}\nexport type InputTestStruct = RemoveFieldOrder;\n" + BigNumberish;\n\tfield3: BigNumberish;\n}\nexport type InputTestStruct = \ + RemoveFieldOrder;\n" ); } diff --git a/crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs b/crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs index 786d8d0380..9d080322c2 100644 --- a/crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs +++ b/crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs @@ -1,4 +1,3 @@ -use crate::plugins::typescript::generator::constants::CAIRO_OPTION_TYPE_PATH; use cainome::parser::tokens::{Composite, CompositeType, Token}; use constants::{ CAIRO_BOOL, CAIRO_BYTE_ARRAY, CAIRO_CONTRACT_ADDRESS, CAIRO_FELT252, CAIRO_I128, CAIRO_U128, @@ -7,6 +6,8 @@ use constants::{ }; use convert_case::{Case, Casing}; +use crate::plugins::typescript::generator::constants::CAIRO_OPTION_TYPE_PATH; + pub(crate) mod constants; pub(crate) mod r#enum; pub(crate) mod erc; @@ -58,14 +59,12 @@ pub(crate) fn generate_type_init(token: &Composite) -> String { /// Checks if Token::Composite is an Option /// * token - The token to check -/// pub(crate) fn token_is_option(token: &Composite) -> bool { token.type_path.starts_with(CAIRO_OPTION_TYPE_PATH) } /// Checks if Token::Composite is an custom enum (enum with nested Composite types) /// * token - The token to check -/// pub(crate) fn token_is_custom_enum(token: &Composite) -> bool { token.r#type == CompositeType::Enum && token.inners.iter().any(|inner| inner.token.to_composite().is_ok()) @@ -111,14 +110,24 @@ impl From<&Token> for JsType { ), Token::Composite(c) => { if token_is_option(c) { - return JsType::from(format!("CairoOption<{}>", c.generic_args.iter().map(|(_, t)| JsType::from(t.type_name().as_str()).to_string()).collect::>().join(", ")).as_str()); + return JsType::from( + format!( + "CairoOption<{}>", + c.generic_args + .iter() + .map(|(_, t)| JsType::from(t.type_name().as_str()).to_string()) + .collect::>() + .join(", ") + ) + .as_str(), + ); } if token_is_custom_enum(c) { // we defined a type wrapper with Enum suffix let's use it there return JsType::from(format!("{}Enum", value.type_name()).as_str()); } - return JsType::from(value.type_name().as_str()) - }, + return JsType::from(value.type_name().as_str()); + } _ => JsType::from(value.type_name().as_str()), } } @@ -155,7 +164,12 @@ impl From<&Composite> for JsDefaultValue { fn from(value: &Composite) -> Self { match value.r#type { cainome::parser::tokens::CompositeType::Enum => { - JsDefaultValue(format!("{}.{}", value.type_name(), value.inners[0].name)) + match value.inners[0].token.to_composite() { + Ok(c) => JsDefaultValue::from(c), + Err(_) => { + JsDefaultValue(format!("{}.{}", value.type_name(), value.inners[0].name)) + } + } } cainome::parser::tokens::CompositeType::Struct => JsDefaultValue(format!( "{{ fieldOrder: [{}], {} }}", @@ -163,7 +177,18 @@ impl From<&Composite> for JsDefaultValue { value .inners .iter() - .map(|i| format!("{}: {},", i.name, JsDefaultValue::from(&i.token))) + .map(|i| format!( + "{}: {},", + i.name, + match i.token.to_composite() { + Ok(c) => { + JsDefaultValue::from(c) + } + Err(_) => { + JsDefaultValue::from(&i.token) + } + } + )) .collect::>() .join(" ") )), @@ -281,7 +306,7 @@ mod tests { ( "A".to_owned(), Token::Composite( - Composite { + Composite { type_path: "tournament::ls15_components::models::tournament::GatedType".to_owned(), inners: vec![ CompositeInner { @@ -394,6 +419,223 @@ mod tests { ) } + #[test] + fn test_enum_default_value() { + assert_eq!( + "Direction.Up", + JsDefaultValue::from(&Token::Composite(Composite { + type_path: "dojo_starter::Direction".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "Up".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { type_path: "()".to_owned() }) + }, + CompositeInner { + index: 1, + name: "Down".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { type_path: "()".to_owned() }) + }, + CompositeInner { + index: 2, + name: "Left".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { type_path: "()".to_owned() }) + }, + CompositeInner { + index: 3, + name: "Right".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { type_path: "()".to_owned() }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Enum, + is_event: false, + alias: None, + })) + ) + } + + #[test] + fn test_cairo_custom_enum_default_value() { + assert_eq!( + "{ fieldOrder: ['id', 'xp'], id: 0, xp: 0, }", + JsDefaultValue::from(&Token::Composite(Composite { + type_path: "dojo_starter::Direction".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "item".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::Composite(Composite { + type_path: "dojo_starter::Item".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "id".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "xp".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Struct, + is_event: false, + alias: None, + }) + }, + CompositeInner { + index: 1, + name: "address".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { type_path: "()".to_owned() }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Enum, + is_event: false, + alias: None, + })) + ) + } + + #[test] + fn test_composite_default_value() { + assert_eq!( + "{ fieldOrder: ['id', 'xp'], id: 0, xp: 0, }", + JsDefaultValue::from(&Token::Composite(Composite { + type_path: "dojo_starter::Item".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "id".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "xp".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Struct, + is_event: false, + alias: None, + })) + ) + } + + #[test] + fn test_nested_composite_default_value() { + assert_eq!( + "{ fieldOrder: ['id', 'xp', 'item'], id: 0, xp: 0, item: { fieldOrder: ['id', 'xp', \ + 'item'], id: 0, xp: 0, item: { fieldOrder: ['id', 'xp'], id: 0, xp: 0, }, }, }", + JsDefaultValue::from(&Token::Composite(Composite { + type_path: "dojo_starter::Item".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "id".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "xp".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "item".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::Composite(Composite { + type_path: "dojo_starter::Item".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "id".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "xp".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "item".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::Composite(Composite { + type_path: "dojo_starter::Item".to_owned(), + inners: vec![ + CompositeInner { + index: 0, + name: "id".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + CompositeInner { + index: 1, + name: "xp".to_owned(), + kind: CompositeInnerKind::NotUsed, + token: Token::CoreBasic(CoreBasic { + type_path: "core::felt252".to_owned(), + }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Struct, + is_event: false, + alias: None, + }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Struct, + is_event: false, + alias: None, + }) + }, + ], + generic_args: vec![], + r#type: CompositeType::Struct, + is_event: false, + alias: None, + })) + ) + } + #[test] fn test_generate_type_init() { let token = create_test_struct_token("TestStruct"); diff --git a/crates/dojo/bindgen/src/plugins/typescript/generator/schema.rs b/crates/dojo/bindgen/src/plugins/typescript/generator/schema.rs index b25ba2d3dc..91cc83b0f8 100644 --- a/crates/dojo/bindgen/src/plugins/typescript/generator/schema.rs +++ b/crates/dojo/bindgen/src/plugins/typescript/generator/schema.rs @@ -26,8 +26,8 @@ impl TsSchemaGenerator { let schema_type = "export interface SchemaType extends ISchemaType"; if !buffer.has(schema_type) { buffer.push(format!( - "export interface SchemaType extends ISchemaType {{\n\t{ns}: \ - {{\n\t\t{}: {},\n\t}},\n}}", + "export interface SchemaType extends ISchemaType {{\n\t{ns}: {{\n\t\t{}: \ + {},\n\t}},\n}}", type_name, type_name )); return; @@ -64,8 +64,7 @@ impl TsSchemaGenerator { let const_type = "export const schema: SchemaType"; if !buffer.has(const_type) { buffer.push(format!( - "export const schema: SchemaType = {{\n\t{ns}: {{\n\t\t{}: \ - {},\n\t}},\n}};", + "export const schema: SchemaType = {{\n\t{ns}: {{\n\t\t{}: {},\n\t}},\n}};", type_name, generate_type_init(token) )); @@ -203,14 +202,16 @@ mod tests { generator.handle_schema_type(&token_3, &mut buffer); assert_eq!( "export interface SchemaType extends ISchemaType {\n\tonchain_dash: \ - {\n\t\tTestStruct: TestStruct,\n\t\tAvailableTheme: AvailableTheme,\n\t},\n\tcombat: {\n\t\tPlayer: Player,\n\t},\n}", + {\n\t\tTestStruct: TestStruct,\n\t\tAvailableTheme: AvailableTheme,\n\t},\n\tcombat: \ + {\n\t\tPlayer: Player,\n\t},\n}", buffer[0] ); let token_4 = create_test_struct_token("Position", "combat"); generator.handle_schema_type(&token_4, &mut buffer); assert_eq!( "export interface SchemaType extends ISchemaType {\n\tonchain_dash: \ - {\n\t\tTestStruct: TestStruct,\n\t\tAvailableTheme: AvailableTheme,\n\t},\n\tcombat: {\n\t\tPlayer: Player,\n\t\tPosition: Position,\n\t},\n}", + {\n\t\tTestStruct: TestStruct,\n\t\tAvailableTheme: AvailableTheme,\n\t},\n\tcombat: \ + {\n\t\tPlayer: Player,\n\t\tPosition: Position,\n\t},\n}", buffer[0] ); } @@ -251,7 +252,9 @@ mod tests { {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: \ 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t\tAvailableTheme: \ {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: \ - 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n\tcombat: {\n\t\tPlayer: {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n};" + 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n\tcombat: {\n\t\tPlayer: \ + {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: \ + 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n};" ); let token_4 = create_test_struct_token("Position", "combat"); @@ -263,7 +266,11 @@ mod tests { {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: \ 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t\tAvailableTheme: \ {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: \ - 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n\tcombat: {\n\t\tPlayer: {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t\tPosition: {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n};" + 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t},\n\tcombat: {\n\t\tPlayer: \ + {\n\t\t\tfieldOrder: ['field1', 'field2', 'field3'],\n\t\t\tfield1: \ + 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: 0,\n\t\t},\n\t\tPosition: {\n\t\t\tfieldOrder: \ + ['field1', 'field2', 'field3'],\n\t\t\tfield1: 0,\n\t\t\tfield2: 0,\n\t\t\tfield3: \ + 0,\n\t\t},\n\t},\n};" ); }