diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bac7db3c4..51af20e59 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [nightly] # This should be reverted back to [stable, nightly] when 1.74 is made the rustc stable version + rust: [stable, nightly] env: CRATE_NAME: gluon CARGO_INCREMENTAL: 0 # Incremental compilation is slower and bloats the cache diff --git a/tests/api.rs b/tests/api.rs index 1d121a4c5..2055ef8f6 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -16,7 +16,6 @@ use gluon::{ query::Compilation, vm::{ api::{ - de::De, scoped::{Ref, RefMut}, FunctionRef, FutureResult, Hole, OpaqueValue, OwnedFunction, RuntimeResult, VmType, IO, }, @@ -298,47 +297,6 @@ fn tuples_start_at_0() { ); } -#[test] -fn use_type_from_type_field() { - let _ = ::env_logger::try_init(); - let vm = make_vm(); - - #[derive(Serialize, Deserialize, PartialEq, Debug)] - enum Test { - A(i32), - B(String), - C, - } - impl VmType for Test { - type Type = Self; - fn make_type(vm: &Thread) -> ArcType { - if let Some(typ) = vm.get_type::() { - return typ; - } - - let (name, typ) = gluon::vm::api::typ::from_rust::(vm).unwrap(); - vm.register_type_as( - name.clone(), - Alias::new(name, Vec::new(), typ), - ::std::any::TypeId::of::(), - ) - .unwrap() - } - } - - add_extern_module(&vm, "test_types", |vm| { - ExternModule::new(vm, record! { type Test => Test }) - }); - let text = r#" - let { Test } = import! test_types - B "abc" - "#; - let (De(actual), _) = vm - .run_expr::>("test", text) - .unwrap_or_else(|err| panic!("{}", err)); - assert_eq!(actual, Test::B("abc".to_string())); -} - #[test] fn use_rust_created_tuple_as_polymorphic() { let _ = ::env_logger::try_init(); @@ -368,41 +326,6 @@ fn use_rust_created_record_as_polymorphic() { assert_eq!(result, 1); } -#[test] -fn return_btreemap() { - let _ = ::env_logger::try_init(); - - let vm = make_vm(); - - add_extern_module_with_deps( - &vm, - "test", - |vm| { - ExternModule::new( - vm, - primitive!(1, "test", |()| { - vec![("a".to_string(), 1), ("b".to_string(), 2)] - .into_iter() - .collect::>() - }), - ) - }, - vec!["std.map".into(), "std.json.de".into()], - ); - - vm.run_expr::<()>("", "let _ = import! test in ()") - .unwrap_or_else(|err| panic!("{}", err)); - let (result, _) = vm - .run_expr::>("", "(import! test) ()") - .unwrap_or_else(|err| panic!("{}", err)); - assert_eq!( - result, - vec![("a".to_string(), 1), ("b".to_string(), 2)] - .into_iter() - .collect::>() - ); -} - #[test] fn get_value_boxed_or_unboxed() { let _ = ::env_logger::try_init(); @@ -777,3 +700,86 @@ fn clone_userdata() { assert_eq!(*result, Test(123)); } + +#[cfg(feature = "serialization")] +mod serialization { + use super::*; + + use gluon::vm::api::de::De; + + #[test] + fn use_type_from_type_field() { + let _ = ::env_logger::try_init(); + let vm = make_vm(); + + #[derive(Serialize, Deserialize, PartialEq, Debug)] + enum Test { + A(i32), + B(String), + C, + } + impl VmType for Test { + type Type = Self; + fn make_type(vm: &Thread) -> ArcType { + if let Some(typ) = vm.get_type::() { + return typ; + } + + let (name, typ) = gluon::vm::api::typ::from_rust::(vm).unwrap(); + vm.register_type_as( + name.clone(), + Alias::new(name, Vec::new(), typ), + ::std::any::TypeId::of::(), + ) + .unwrap() + } + } + + add_extern_module(&vm, "test_types", |vm| { + ExternModule::new(vm, record! { type Test => Test }) + }); + let text = r#" + let { Test } = import! test_types + B "abc" + "#; + let (De(actual), _) = vm + .run_expr::>("test", text) + .unwrap_or_else(|err| panic!("{}", err)); + assert_eq!(actual, Test::B("abc".to_string())); + } + + #[test] + fn return_btreemap() { + let _ = ::env_logger::try_init(); + + let vm = make_vm(); + + add_extern_module_with_deps( + &vm, + "test", + |vm| { + ExternModule::new( + vm, + primitive!(1, "test", |()| { + vec![("a".to_string(), 1), ("b".to_string(), 2)] + .into_iter() + .collect::>() + }), + ) + }, + vec!["std.map".into(), "std.json.de".into()], + ); + + vm.run_expr::<()>("", "let _ = import! test in ()") + .unwrap_or_else(|err| panic!("{}", err)); + let (result, _) = vm + .run_expr::>("", "(import! test) ()") + .unwrap_or_else(|err| panic!("{}", err)); + assert_eq!( + result, + vec![("a".to_string(), 1), ("b".to_string(), 2)] + .into_iter() + .collect::>() + ); + } +}