diff --git a/src/export_instance.rs b/src/export_instance.rs index d0d4381..036b32c 100644 --- a/src/export_instance.rs +++ b/src/export_instance.rs @@ -50,7 +50,7 @@ impl InstanceWalker { instances: Default::default(), } } - fn add_instance(&mut self, name: Cow<'static, str>) { + fn add_instance(&mut self, name: Cow<'static, str>) { let teal_type = T::get_type_parts_as_global(); let z = T::get_type_kind(); let is_external = matches!(z, KindOfType::External); @@ -60,6 +60,7 @@ impl InstanceWalker { teal_type, is_external, doc, + ty: T::to_typename(), }); } fn document_instance(&mut self, doc: &'static str) { diff --git a/src/lib.rs b/src/lib.rs index c71707e..7766980 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -351,12 +351,13 @@ pub fn new_type_to_old(a: Type, is_callback: bool) -> Cow<'static, [NamePart]> { } parts.push(NamePart::symbol(")")); if !returns.is_empty() { - parts.push(NamePart::symbol(":")); + parts.push(NamePart::symbol(":(")); for ret in returns { parts.extend(new_type_to_old(ret, true).iter().cloned()); parts.push(NamePart::symbol(" , ")) } parts.pop(); + parts.push(NamePart::symbol(")")); } Cow::Owned(parts) diff --git a/src/type_generator.rs b/src/type_generator.rs index 57c8d97..0817d5d 100644 --- a/src/type_generator.rs +++ b/src/type_generator.rs @@ -232,17 +232,31 @@ pub struct Field { ///the name of the field pub name: NameContainer, - ///the type of the field + ///the type of the field, according to the old format #[cfg_attr( all(any(feature = "rlua", feature = "mlua"), feature = "derive", not(all(feature = "rlua", feature = "mlua"))), tealr(remote = V) )] pub teal_type: Cow<'static, [NamePart]>, + /// the type of the field + pub ty: Type, } -impl From<(NameContainer, Cow<'static, [NamePart]>)> for Field { - fn from((name, teal_type): (NameContainer, Cow<'static, [NamePart]>)) -> Self { - Self { name, teal_type } +impl From<(NameContainer, Type)> for Field { + fn from((name, ty): (NameContainer, Type)) -> Self { + #[allow(deprecated)] + let teal_type = crate::new_type_to_old(ty.clone(), false); + Self { + name, + teal_type, + ty, + } + } +} +impl Field { + ///creates a new field + pub fn new(name: impl Into>) -> Self { + (NameContainer::from(name.into()), A::to_typename()).into() } } @@ -842,7 +856,7 @@ where { self.copy_docs(name.as_ref()); self.fields - .push((name.as_ref().to_vec().into(), R::get_type_parts()).into()); + .push((name.as_ref().to_vec().into(), R::to_typename()).into()); } fn add_field_method_set(&mut self, name: &S, _: M) @@ -853,7 +867,7 @@ where { self.copy_docs(name.as_ref()); self.fields - .push((name.as_ref().to_vec().into(), A::get_type_parts()).into()); + .push((name.as_ref().to_vec().into(), A::to_typename()).into()); } fn add_field_function_get(&mut self, name: &S, _: F) @@ -864,7 +878,7 @@ where { self.copy_docs(name.as_ref()); self.static_fields - .push((name.as_ref().to_vec().into(), R::get_type_parts()).into()); + .push((name.as_ref().to_vec().into(), R::to_typename()).into()); } fn add_field_function_set(&mut self, name: &S, _: F) @@ -875,7 +889,7 @@ where { self.copy_docs(name.as_ref()); self.static_fields - .push((name.as_ref().to_vec().into(), A::get_type_parts()).into()); + .push((name.as_ref().to_vec().into(), A::to_typename()).into()); } fn add_meta_field_with(&mut self, meta: MetaMethodM, _: F) @@ -887,7 +901,7 @@ where let name: Cow<'_, str> = Cow::Owned(x.name().to_string()); self.copy_docs(name.as_bytes()); self.static_fields - .push((NameContainer::from(name), R::get_type_parts()).into()); + .push((NameContainer::from(name), R::to_typename()).into()); } fn document(&mut self, documentation: &str) { diff --git a/src/type_walker.rs b/src/type_walker.rs index e980a3f..685d93f 100644 --- a/src/type_walker.rs +++ b/src/type_walker.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, string::FromUtf8Error}; -use crate::{type_parts_to_str, NamePart, ToTypename, TypeBody, TypeGenerator}; +use crate::{type_parts_to_str, NamePart, ToTypename, Type, TypeBody, TypeGenerator}; type V = Vec; @@ -24,11 +24,13 @@ pub struct GlobalInstance { all(any(feature = "rlua", feature = "mlua"), feature = "derive", not(all(feature = "rlua", feature = "mlua"))), tealr(remote = String))] pub name: Cow<'static, str>, - ///the type + ///the type according to the old format #[cfg_attr( all(any(feature = "rlua", feature = "mlua"), feature = "derive", not(all(feature = "rlua", feature = "mlua"))), tealr(remote = V))] pub teal_type: Cow<'static, [NamePart]>, + ///the type + pub ty: Type, ///if the type is external pub is_external: bool, ///documentation for this global @@ -180,6 +182,7 @@ impl TypeWalker { teal_type, is_external, doc, + ty: _, } = global; let doc = doc .lines() diff --git a/tealr_derive/src/from_to_lua.rs b/tealr_derive/src/from_to_lua.rs index 9a53d86..b6f3dbf 100644 --- a/tealr_derive/src/from_to_lua.rs +++ b/tealr_derive/src/from_to_lua.rs @@ -129,6 +129,7 @@ fn implement_for_struct(structure: Struct, config: BasicConfig) -> TokenStream { .enumerate() .map(|(key, x)| { let ty = &x.0.ty; + let name = format!("param{key}"); let key_as_str = Literal::usize_unsuffixed(key); let (set_value, get_value, type_name) = find_tag_with_value("remote", &x.0.attributes) @@ -154,8 +155,8 @@ fn implement_for_struct(structure: Struct, config: BasicConfig) -> TokenStream { gen .fields .push( - ::std::convert::From::from((::std::borrow::Cow::Borrowed(stringify!(#key_as_str)).into(), - <(#type_name) as #type_name_path>::to_old_type_parts())) + ::std::convert::From::from((::std::borrow::Cow::Borrowed(#name).into(), + <(#type_name) as #type_name_path>::to_typename())) ); }, ), @@ -197,7 +198,7 @@ fn implement_for_struct(structure: Struct, config: BasicConfig) -> TokenStream { .fields .push( ::std::convert::From::from((::std::borrow::Cow::Borrowed(stringify!(#name)).into(), - <(#type_name) as #type_name_path>::to_old_type_parts())) + <(#type_name) as #type_name_path>::to_typename())) ); gen.copy_docs(stringify!(#name).as_bytes()); }, diff --git a/tests/mlua/async.json b/tests/mlua/async.json new file mode 100644 index 0000000..485a6c3 --- /dev/null +++ b/tests/mlua/async.json @@ -0,0 +1 @@ +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"example_method","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false}],"mut_methods":[],"functions":[{"name":"example_method_mut","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}},{"param_name":null,"ty":{"Single":{"name":"string","kind":"Builtin"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}}],"is_meta_method":false},{"name":"example_function","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":"}"},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Array":{"Single":{"name":"string","kind":"Builtin"}}}}],"returns":[{"Array":{"Single":{"name":"string","kind":"Builtin"}}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false}],"mut_functions":[{"name":"example_function_mut","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Single":{"name":"boolean","kind":"Builtin"}}},{"param_name":null,"ty":{"Single":{"name":"Example","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}},{"Single":{"name":"Example","kind":"External"}}],"is_meta_method":false}],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/async.rs b/tests/mlua/async.rs index 290f826..ef73cd0 100644 --- a/tests/mlua/async.rs +++ b/tests/mlua/async.rs @@ -39,16 +39,21 @@ fn async_fn() -> Result<()> { //add more calls to process_type to generate more types in the same file .process_type::() //generate the file - .generate_global("test") - //the name parameter for TealDataMethods::{add_method,add_method_mut,add_function,add_function_mut} - //takes anything that can be used as a &[u8] - //this is to match the types from UserDataMethods - //however, as we turn it back into a string it is technically possible to get an error - //in this case, as &str's where used it can't happen though, so the .expect is fine + .to_json() .expect("oh no :("); - assert_eq!(file_contents, "global record test\n\trecord Example\n\t\tuserdata\n\n\t\t-- Pure methods\n\t\texample_method: function(self:Example , integer):integer\n\n\t\t-- Pure functions\n\t\texample_method_mut: function(integer , string):string\n\n\t\texample_function: function({string}):{string} , integer\n\n\t\t-- Mutating functions\n\t\texample_function_mut: function(boolean , Example):boolean , Example\n\n\n\tend\nend\nreturn test"); - //normally you would now save the file somewhere. - println!("{}\n ", file_contents); + + let generated: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); + + let mut original: serde_json::Value = + serde_json::from_str(include_str!("./async.json")).unwrap(); + let x = original + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = x { + *x = tealr::get_tealr_version().to_string(); + } + + assert_eq!(generated, original); //how you pass this type to lua hasn't changed: let lua = Lua::new(); diff --git a/tests/mlua/export_instances.json b/tests/mlua/export_instances.json index 60cef8e..b591176 100644 --- a/tests/mlua/export_instances.json +++ b/tests/mlua/export_instances.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"limited_callback","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}]}}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false},{"name":"limited_array","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}}],"returns":[{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"is_meta_method":false},{"name":"limited_simple","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[{"name":"test","teal_type":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"is_external":true,"doc":""},{"name":"example_a","teal_type":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"is_external":true,"doc":"a simple function that does a + 1\nit is just for testing purposes\n"},{"name":"example_generic","teal_type":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"X","type_kind":"Generic","generics":null}}],"is_external":true,"doc":"A simple generic function to make sure generic functions in global context stay working\n"}],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"limited_callback","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}]}}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false},{"name":"limited_array","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}}],"returns":[{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"is_meta_method":false},{"name":"limited_simple","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[{"name":"test","teal_type":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"ty":{"Single":{"name":"Example","kind":"External"}},"is_external":true,"doc":""},{"name":"example_a","teal_type":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"ty":{"Function":{"params":[{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"integer","kind":"Builtin"}}]}},"is_external":true,"doc":"a simple function that does a + 1\nit is just for testing purposes\n"},{"name":"example_generic","teal_type":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"}],"ty":{"Function":{"params":[{"param_name":null,"ty":{"Single":{"name":"X","kind":"Generic"}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}]}},"is_external":true,"doc":"A simple generic function to make sure generic functions in global context stay working\n"}],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/export_instances.rs b/tests/mlua/export_instances.rs index 35f3213..899165d 100644 --- a/tests/mlua/export_instances.rs +++ b/tests/mlua/export_instances.rs @@ -53,9 +53,17 @@ fn test_limited() { .unwrap() .to_json() .expect("oh no :("); + let generated: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let original: serde_json::Value = + let mut original: serde_json::Value = serde_json::from_str(include_str!("./export_instances.json")).unwrap(); + + let mut x = original + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(generated, original); let lua = mlua::Lua::new(); diff --git a/tests/mlua/function_wrapper.rs b/tests/mlua/function_wrapper.rs index e39898c..7d1f9b1 100644 --- a/tests/mlua/function_wrapper.rs +++ b/tests/mlua/function_wrapper.rs @@ -9,14 +9,14 @@ fn generate_correct_type() { #[allow(deprecated)] TypedFunction::::to_old_type_parts() ), - "function(string):string" + "function(string):(string)" ); assert_eq!( type_parts_to_str( #[allow(deprecated)] TypedFunction::, f32>::to_old_type_parts() ), - "function(function(integer , string):string , integer):number" + "function(function(integer , string):(string , integer)):(number)" ); } #[test] diff --git a/tests/mlua/generics.json b/tests/mlua/generics.json index ecb52dd..49675c2 100644 --- a/tests/mlua/generics.json +++ b/tests/mlua/generics.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"generic_function_callback","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"X","type_kind":"Generic","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Single":{"name":"X","kind":"Generic"}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}]}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}],"is_meta_method":false},{"name":"generic_array","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"{"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Single":{"name":"X","kind":"Generic"}}}}],"returns":[{"Array":{"Single":{"name":"X","kind":"Generic"}}}],"is_meta_method":false},{"name":"generic_hashmap","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" : "},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" : "},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Map":{"key":{"Single":{"name":"string","kind":"Builtin"}},"value":{"Single":{"name":"X","kind":"Generic"}}}}}],"returns":[{"Map":{"key":{"Single":{"name":"string","kind":"Builtin"}},"value":{"Single":{"name":"X","kind":"Generic"}}}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false},{"name":"just_generics","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"X","type_kind":"Generic","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Single":{"name":"X","kind":"Generic"}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}],"is_meta_method":false},{"name":"non_generic_container","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":"}"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Single":{"name":"string","kind":"Builtin"}}}}],"returns":[{"Array":{"Single":{"name":"string","kind":"Builtin"}}}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"generic_function_callback","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Single":{"name":"X","kind":"Generic"}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}]}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}],"is_meta_method":false},{"name":"generic_array","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Single":{"name":"X","kind":"Generic"}}}}],"returns":[{"Array":{"Single":{"name":"X","kind":"Generic"}}}],"is_meta_method":false},{"name":"generic_hashmap","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" : "},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" : "},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":"}"},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Map":{"key":{"Single":{"name":"string","kind":"Builtin"}},"value":{"Single":{"name":"X","kind":"Generic"}}}}}],"returns":[{"Map":{"key":{"Single":{"name":"string","kind":"Builtin"}},"value":{"Single":{"name":"X","kind":"Generic"}}}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false},{"name":"just_generics","signature":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Single":{"name":"X","kind":"Generic"}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}],"is_meta_method":false},{"name":"non_generic_container","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":"}"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Single":{"name":"string","kind":"Builtin"}}}}],"returns":[{"Array":{"Single":{"name":"string","kind":"Builtin"}}}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/generics.rs b/tests/mlua/generics.rs index d3f1c80..0d7ded4 100644 --- a/tests/mlua/generics.rs +++ b/tests/mlua/generics.rs @@ -38,7 +38,13 @@ fn make_generic() { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./generics.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); } diff --git a/tests/mlua/inlined_type.json b/tests/mlua/inlined_type.json index ccafe03..c00b433 100644 --- a/tests/mlua/inlined_type.json +++ b/tests/mlua/inlined_type.json @@ -53,7 +53,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -61,6 +61,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -141,7 +144,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -149,6 +152,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -218,7 +224,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "{" @@ -242,6 +248,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -307,7 +316,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -325,6 +334,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -426,7 +438,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -434,6 +446,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -514,7 +529,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -522,6 +537,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -591,7 +609,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "{" @@ -615,6 +633,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -680,7 +701,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -698,6 +719,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ diff --git a/tests/mlua/inlined_type.rs b/tests/mlua/inlined_type.rs index d1ae8ff..40014c8 100644 --- a/tests/mlua/inlined_type.rs +++ b/tests/mlua/inlined_type.rs @@ -37,7 +37,13 @@ fn make_inline_type() { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./inlined_type.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); } diff --git a/tests/mlua/meta_methods.json b/tests/mlua/meta_methods.json index 019fac3..7fc24fe 100644 --- a/tests/mlua/meta_methods.json +++ b/tests/mlua/meta_methods.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[{"name":"__add","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"Example","kind":"External"}}],"is_meta_method":true}],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[{"name":"__add","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"Example","kind":"External"}}],"is_meta_method":true}],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/meta_methods.rs b/tests/mlua/meta_methods.rs index 3803048..892c133 100644 --- a/tests/mlua/meta_methods.rs +++ b/tests/mlua/meta_methods.rs @@ -29,7 +29,13 @@ fn test() { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./meta_methods.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); } diff --git a/tests/mlua/named_parameters.json b/tests/mlua/named_parameters.json index 86c5348..ab5139d 100644 --- a/tests/mlua/named_parameters.json +++ b/tests/mlua/named_parameters.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"example_method","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"field_1"},{"Symbol":":"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Symbol":"field_2"},{"Symbol":":"},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":"field_1","ty":{"Single":{"name":"string","kind":"Builtin"}}},{"param_name":"field_2","ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"example_method","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"field_1"},{"Symbol":":"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Symbol":"field_2"},{"Symbol":":"},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":"field_1","ty":{"Single":{"name":"string","kind":"Builtin"}}},{"param_name":"field_2","ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/named_parameters.rs b/tests/mlua/named_parameters.rs index 2aea0ac..b68a2ed 100644 --- a/tests/mlua/named_parameters.rs +++ b/tests/mlua/named_parameters.rs @@ -29,8 +29,16 @@ fn main() -> Result<()> { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./named_parameters.json")).unwrap(); + + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } + assert_eq!(new_value, old_value); let lua = Lua::new(); diff --git a/tests/mlua/to_from_derived.json b/tests/mlua/to_from_derived.json index 3795dd4..e140e21 100644 --- a/tests/mlua/to_from_derived.json +++ b/tests/mlua/to_from_derived.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":false,"type_name":[{"Type":{"name":"V","type_kind":"External","generics":null}}],"fields":[{"name":"0","teal_type":[{"Type":{"name":"string","type_kind":"Builtin","generics":null}}]}],"static_fields":[],"methods":[],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}},{"Enum":{"name":[{"Type":{"name":"ExampleCStyleEnum","type_kind":"External","generics":null}}],"variants":["This","Is","A","Basic","Example"],"type_doc":""}},{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"TestCreatorOfDOOM","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[],"mut_methods":[],"functions":[{"name":"NewAmazingFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"V","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"params":[{"param_name":null,"ty":{"Single":{"name":"V","kind":"External"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewLessSo","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"params":[],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewOWowADoubleFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"params":[{"param_name":null,"ty":{"Single":{"name":"string","kind":"Builtin"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false}],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}},{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"IsAmazing","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetAmazing","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"V","type_kind":"External","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}},{"Single":{"name":"V","kind":"External"}}],"is_meta_method":false},{"name":"GetAmazingOrNil","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"V","type_kind":"External","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"V","kind":"External"}}],"is_meta_method":false},{"name":"IsLessSo","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}}],"is_meta_method":false},{"name":"IsOWowADouble","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetOWowADouble","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}},{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetOWowADoubleOrNil","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetTypeName","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"string","type_kind":"Builtin","generics":null}}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}}],"is_meta_method":false}],"mut_methods":[],"functions":[{"name":"NewAmazingFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"V","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"params":[{"param_name":null,"ty":{"Single":{"name":"V","kind":"External"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewLessSo","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"params":[],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewOWowADoubleFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"params":[{"param_name":null,"ty":{"Single":{"name":"string","kind":"Builtin"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false}],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}},{"Record":{"should_be_inlined":false,"is_user_data":false,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[{"name":"field1","teal_type":[{"Type":{"name":"Test2","type_kind":"External","generics":null}}]},{"name":"nice","teal_type":[{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}]},{"name":"v","teal_type":[{"Type":{"name":"ExampleCStyleEnum","type_kind":"External","generics":null}}]}],"static_fields":[],"methods":[],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":false,"type_name":[{"Type":{"name":"V","type_kind":"External","generics":null}}],"fields":[{"name":"param0","teal_type":[{"Type":{"name":"string","type_kind":"Builtin","generics":null}}],"ty":{"Single":{"name":"string","kind":"Builtin"}}}],"static_fields":[],"methods":[],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}},{"Enum":{"name":[{"Type":{"name":"ExampleCStyleEnum","type_kind":"External","generics":null}}],"variants":["This","Is","A","Basic","Example"],"type_doc":""}},{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"TestCreatorOfDOOM","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[],"mut_methods":[],"functions":[{"name":"NewAmazingFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"V","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Single":{"name":"V","kind":"External"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewLessSo","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewOWowADoubleFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Single":{"name":"string","kind":"Builtin"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false}],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}},{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"IsAmazing","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetAmazing","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"V","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}},{"Single":{"name":"V","kind":"External"}}],"is_meta_method":false},{"name":"GetAmazingOrNil","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"V","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"V","kind":"External"}}],"is_meta_method":false},{"name":"IsLessSo","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}}],"is_meta_method":false},{"name":"IsOWowADouble","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetOWowADouble","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"boolean","kind":"Builtin"}},{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetOWowADoubleOrNil","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"integer","kind":"Builtin"}}],"is_meta_method":false},{"name":"GetTypeName","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Test2","kind":"External"}}}],"returns":[{"Single":{"name":"string","kind":"Builtin"}}],"is_meta_method":false}],"mut_methods":[],"functions":[{"name":"NewAmazingFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"V","type_kind":"External","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Single":{"name":"V","kind":"External"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewLessSo","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false},{"name":"NewOWowADoubleFrom","signature":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" , "},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"Test2","type_kind":"External","generics":null}},{"Symbol":")"}],"params":[{"param_name":null,"ty":{"Single":{"name":"string","kind":"Builtin"}}},{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"Test2","kind":"External"}}],"is_meta_method":false}],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}},{"Record":{"should_be_inlined":false,"is_user_data":false,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[{"name":"field1","teal_type":[{"Type":{"name":"Test2","type_kind":"External","generics":null}}],"ty":{"Single":{"name":"Test2","kind":"External"}}},{"name":"nice","teal_type":[{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"ty":{"Single":{"name":"integer","kind":"Builtin"}}},{"name":"v","teal_type":[{"Type":{"name":"ExampleCStyleEnum","type_kind":"External","generics":null}}],"ty":{"Single":{"name":"ExampleCStyleEnum","kind":"External"}}}],"static_fields":[],"methods":[],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/to_from_derived.rs b/tests/mlua/to_from_derived.rs index 59b5888..f9076f5 100644 --- a/tests/mlua/to_from_derived.rs +++ b/tests/mlua/to_from_derived.rs @@ -69,8 +69,16 @@ fn main() -> Result<(), Box> { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./to_from_derived.json")).unwrap(); + + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } + assert_eq!(new_value, old_value); let mut to_pass = Example { diff --git a/tests/mlua/type_picker.json b/tests/mlua/type_picker.json index fb4aeb7..827bd61 100644 --- a/tests/mlua/type_picker.json +++ b/tests/mlua/type_picker.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"limited_callback","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}]}}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false},{"name":"limited_array","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}}],"returns":[{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"is_meta_method":false},{"name":"limited_simple","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"limited_callback","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}]}}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false},{"name":"limited_array","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}}],"returns":[{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"is_meta_method":false},{"name":"limited_simple","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[],"extra_page":[]} \ No newline at end of file diff --git a/tests/mlua/type_picker.rs b/tests/mlua/type_picker.rs index c7cd140..87dfcb3 100644 --- a/tests/mlua/type_picker.rs +++ b/tests/mlua/type_picker.rs @@ -32,8 +32,16 @@ fn test_limited() { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./type_picker.json")).unwrap(); + + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } + assert_eq!(new_value, old_value); let lua = Lua::new(); let globals = lua.globals(); diff --git a/tests/rlua/export_instance.json b/tests/rlua/export_instance.json index 6777ddd..4a038a1 100644 --- a/tests/rlua/export_instance.json +++ b/tests/rlua/export_instance.json @@ -1 +1 @@ -{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"limited_callback","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}]}}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false},{"name":"limited_array","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}}],"returns":[{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"is_meta_method":false},{"name":"limited_simple","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[{"name":"test","teal_type":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"is_external":true,"doc":""},{"name":"example_a","teal_type":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}}],"is_external":true,"doc":"a simple function that does a + 1\nit is just for testing purposes\n"},{"name":"example_generic","teal_type":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":"},{"Type":{"name":"X","type_kind":"Generic","generics":null}}],"is_external":true,"doc":""}],"extra_page":[]} \ No newline at end of file +{"tealr_version_used":"0.9.0-alpha4","given_types":[{"Record":{"should_be_inlined":false,"is_user_data":true,"type_name":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"fields":[],"static_fields":[],"methods":[{"name":"limited_callback","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"function"},{"Symbol":"("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Function":{"params":[{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}]}}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false},{"name":"limited_array","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"{"},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":"}"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}}],"returns":[{"Array":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"is_meta_method":false},{"name":"limited_simple","signature":[{"Symbol":"function"},{"Symbol":"("},{"Symbol":"self"},{"Symbol":":"},{"Type":{"name":"Example","type_kind":"External","generics":null}},{"Symbol":" , "},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"},{"Symbol":":("},{"Symbol":"("},{"Type":{"name":"string","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"number","type_kind":"Builtin","generics":null}},{"Symbol":" | "},{"Type":{"name":"boolean","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":")"}],"params":[{"param_name":"self","ty":{"Single":{"name":"Example","kind":"External"}}},{"param_name":null,"ty":{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}}],"returns":[{"Or":[{"Single":{"name":"string","kind":"Builtin"}},{"Single":{"name":"number","kind":"Builtin"}},{"Single":{"name":"boolean","kind":"Builtin"}}]}],"is_meta_method":false}],"mut_methods":[],"functions":[],"mut_functions":[],"meta_method":[],"meta_method_mut":[],"meta_function":[],"meta_function_mut":[],"documentation":{},"type_doc":"","next_docs":null,"should_generate_help_method":true}}],"global_instances_off":[{"name":"test","teal_type":[{"Type":{"name":"Example","type_kind":"External","generics":null}}],"ty":{"Single":{"name":"Example","kind":"External"}},"is_external":true,"doc":""},{"name":"example_a","teal_type":[{"Symbol":"function"},{"Symbol":"("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"integer","type_kind":"Builtin","generics":null}},{"Symbol":")"}],"ty":{"Function":{"params":[{"param_name":null,"ty":{"Single":{"name":"integer","kind":"Builtin"}}}],"returns":[{"Single":{"name":"integer","kind":"Builtin"}}]}},"is_external":true,"doc":"a simple function that does a + 1\nit is just for testing purposes\n"},{"name":"example_generic","teal_type":[{"Symbol":"function"},{"Symbol":"<"},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":">"},{"Symbol":"("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"},{"Symbol":":("},{"Type":{"name":"X","type_kind":"Generic","generics":null}},{"Symbol":")"}],"ty":{"Function":{"params":[{"param_name":null,"ty":{"Single":{"name":"X","kind":"Generic"}}}],"returns":[{"Single":{"name":"X","kind":"Generic"}}]}},"is_external":true,"doc":""}],"extra_page":[]} \ No newline at end of file diff --git a/tests/rlua/export_instances.rs b/tests/rlua/export_instances.rs index 5631357..e8bda2c 100644 --- a/tests/rlua/export_instances.rs +++ b/tests/rlua/export_instances.rs @@ -53,9 +53,14 @@ fn test_limited() { .to_json() .expect("oh no :("); let generated: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let original: serde_json::Value = + let mut original: serde_json::Value = serde_json::from_str(include_str!("./export_instance.json")).unwrap(); - + let x = original + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(generated, original); let res: bool = rlua::Lua::new() .context(|ctx| { diff --git a/tests/rlua/function_wrapper.rs b/tests/rlua/function_wrapper.rs index 6f0d8a6..ce47db6 100644 --- a/tests/rlua/function_wrapper.rs +++ b/tests/rlua/function_wrapper.rs @@ -9,14 +9,14 @@ fn generate_correct_type() { #[allow(deprecated)] TypedFunction::::to_old_type_parts() ), - "function(string):string" + "function(string):(string)" ); assert_eq!( type_parts_to_str( #[allow(deprecated)] TypedFunction::, f32>::to_old_type_parts() ), - "function(function(integer , string):string , integer):number" + "function(function(integer , string):(string , integer)):(number)" ); } #[test] diff --git a/tests/rlua/generics.json b/tests/rlua/generics.json index ffb0a8d..17df73b 100644 --- a/tests/rlua/generics.json +++ b/tests/rlua/generics.json @@ -72,7 +72,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -85,7 +85,10 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ")" + }, + { + "Symbol": ":(" }, { "Type": { @@ -93,6 +96,9 @@ "type_kind": "Generic", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -197,7 +203,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "{" @@ -211,6 +217,9 @@ }, { "Symbol": "}" + }, + { + "Symbol": ")" } ], "params": [ @@ -312,7 +321,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "{" @@ -346,6 +355,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -453,7 +465,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -461,6 +473,9 @@ "type_kind": "Generic", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -535,7 +550,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "{" @@ -549,6 +564,9 @@ }, { "Symbol": "}" + }, + { + "Symbol": ")" } ], "params": [ diff --git a/tests/rlua/generics.rs b/tests/rlua/generics.rs index a6d2dbc..f2afb60 100644 --- a/tests/rlua/generics.rs +++ b/tests/rlua/generics.rs @@ -33,9 +33,14 @@ fn make_generic() { .process_type::() .to_json_pretty() .unwrap(); - let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./generics.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); } diff --git a/tests/rlua/meta_methods.json b/tests/rlua/meta_methods.json index e683fa1..00bb814 100644 --- a/tests/rlua/meta_methods.json +++ b/tests/rlua/meta_methods.json @@ -57,7 +57,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -65,6 +65,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ diff --git a/tests/rlua/meta_methods.rs b/tests/rlua/meta_methods.rs index d52b20e..b35372b 100644 --- a/tests/rlua/meta_methods.rs +++ b/tests/rlua/meta_methods.rs @@ -27,7 +27,13 @@ fn test() { .to_json_pretty() .unwrap(); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./meta_methods.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); } diff --git a/tests/rlua/named_parameters.json b/tests/rlua/named_parameters.json index dbda67d..7f2b948 100644 --- a/tests/rlua/named_parameters.json +++ b/tests/rlua/named_parameters.json @@ -75,7 +75,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -93,6 +93,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ diff --git a/tests/rlua/named_parameters.rs b/tests/rlua/named_parameters.rs index 94d4cab..16a37a5 100644 --- a/tests/rlua/named_parameters.rs +++ b/tests/rlua/named_parameters.rs @@ -26,8 +26,14 @@ fn main() -> Result<()> { .unwrap(); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./named_parameters.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); tealr::rlu::rlua::Lua::new().context(|ctx| { diff --git a/tests/rlua/to_from_derived.json b/tests/rlua/to_from_derived.json index b53df9f..6188a13 100644 --- a/tests/rlua/to_from_derived.json +++ b/tests/rlua/to_from_derived.json @@ -16,7 +16,7 @@ ], "fields": [ { - "name": "0", + "name": "param0", "teal_type": [ { "Type": { @@ -25,7 +25,13 @@ "generics": null } } - ] + ], + "ty": { + "Single": { + "name": "string", + "kind": "Builtin" + } + } } ], "static_fields": [], @@ -102,7 +108,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -110,6 +116,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -146,7 +155,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -154,6 +163,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [], @@ -197,7 +209,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -205,6 +217,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -291,7 +306,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -299,6 +314,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -348,7 +366,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -366,6 +384,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -421,7 +442,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -429,6 +450,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -478,7 +502,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -486,6 +510,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -535,7 +562,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -543,6 +570,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -592,7 +622,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -620,6 +650,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -681,7 +714,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -699,6 +732,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -754,7 +790,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -762,6 +798,9 @@ "type_kind": "Builtin", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -808,7 +847,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -816,6 +855,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -852,7 +894,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -860,6 +902,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [], @@ -903,7 +948,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Type": { @@ -911,6 +956,9 @@ "type_kind": "External", "generics": null } + }, + { + "Symbol": ")" } ], "params": [ @@ -979,7 +1027,13 @@ "generics": null } } - ] + ], + "ty": { + "Single": { + "name": "Test2", + "kind": "External" + } + } }, { "name": "nice", @@ -991,7 +1045,13 @@ "generics": null } } - ] + ], + "ty": { + "Single": { + "name": "integer", + "kind": "Builtin" + } + } }, { "name": "v", @@ -1003,7 +1063,13 @@ "generics": null } } - ] + ], + "ty": { + "Single": { + "name": "ExampleCStyleEnum", + "kind": "External" + } + } } ], "static_fields": [], diff --git a/tests/rlua/to_from_derived.rs b/tests/rlua/to_from_derived.rs index faa63dc..f151091 100644 --- a/tests/rlua/to_from_derived.rs +++ b/tests/rlua/to_from_derived.rs @@ -69,8 +69,14 @@ fn main() -> Result<(), Box> { .expect("oh no :("); let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./to_from_derived.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); let mut to_pass = Example { field1: String::from("nice"), diff --git a/tests/rlua/type_picker.json b/tests/rlua/type_picker.json index 452ad7f..1679b29 100644 --- a/tests/rlua/type_picker.json +++ b/tests/rlua/type_picker.json @@ -85,7 +85,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "(" @@ -124,7 +124,10 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ")" + }, + { + "Symbol": ":(" }, { "Symbol": "(" @@ -156,6 +159,9 @@ "generics": null } }, + { + "Symbol": ")" + }, { "Symbol": ")" } @@ -323,7 +329,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "{" @@ -363,6 +369,9 @@ }, { "Symbol": "}" + }, + { + "Symbol": ")" } ], "params": [ @@ -493,7 +502,7 @@ "Symbol": ")" }, { - "Symbol": ":" + "Symbol": ":(" }, { "Symbol": "(" @@ -525,6 +534,9 @@ "generics": null } }, + { + "Symbol": ")" + }, { "Symbol": ")" } diff --git a/tests/rlua/type_picker.rs b/tests/rlua/type_picker.rs index 275e72d..9ac3fd6 100644 --- a/tests/rlua/type_picker.rs +++ b/tests/rlua/type_picker.rs @@ -30,9 +30,16 @@ fn test_limited() { .process_type::() .to_json_pretty() .unwrap(); + let new_value: serde_json::Value = serde_json::from_str(&file_contents).unwrap(); - let old_value: serde_json::Value = + let mut old_value: serde_json::Value = serde_json::from_str(include_str!("./type_picker.json")).unwrap(); + let mut x = old_value + .get_mut("tealr_version_used") + .expect("missing tealr_version_used in original"); + if let serde_json::Value::String(x) = &mut x { + *x = tealr::get_tealr_version().to_string(); + } assert_eq!(new_value, old_value); let res: bool = rlua::Lua::new() .context(|ctx| {