diff options
author | Nadrieril | 2019-05-09 21:54:45 +0200 |
---|---|---|
committer | Nadrieril | 2019-05-09 21:54:45 +0200 |
commit | dae106b3de0888e8a704c0efa3f9d991590f7858 (patch) | |
tree | 750daf7cb5b44bed4772ace3457c583c0ef86e4d /dhall/tests | |
parent | 6444faa2dee271e6d22226dc30b659e13fa8aead (diff) |
Rewrite the StaticType trait and everything around it
Diffstat (limited to 'dhall/tests')
-rw-r--r-- | dhall/tests/traits.rs | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/dhall/tests/traits.rs b/dhall/tests/traits.rs index 65220dc..75eaf75 100644 --- a/dhall/tests/traits.rs +++ b/dhall/tests/traits.rs @@ -1,79 +1,76 @@ #![feature(proc_macro_hygiene)] -use dhall::de::SimpleStaticType; -use dhall_proc_macros; +use dhall::de::{StaticType, Type}; +use dhall_proc_macros::subexpr; use dhall_syntax::{SubExpr, X}; #[test] fn test_static_type() { - fn mktype(x: SubExpr<X, X>) -> dhall::de::SimpleType { - x.into() + fn mktype(x: SubExpr<X, X>) -> Type { + Type::from_normalized_expr(x) } + assert_eq!(bool::static_type(), mktype(subexpr!(Bool))); + assert_eq!(String::static_type(), mktype(subexpr!(Text))); assert_eq!( - bool::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(Bool)) + <Option<bool>>::static_type(), + mktype(subexpr!(Optional Bool)) ); assert_eq!( - String::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(Text)) - ); - assert_eq!( - <Option<bool>>::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(Optional Bool)) - ); - assert_eq!( - <(bool, Option<String>)>::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!({ _1: Bool, _2: Optional Text })) + <(bool, Vec<String>)>::static_type(), + mktype(subexpr!({ _1: Bool, _2: List Text })) ); - #[derive(dhall::de::SimpleStaticType)] + #[derive(dhall::de::StaticType)] #[allow(dead_code)] struct A { field1: bool, field2: Option<bool>, } assert_eq!( - <A as dhall::de::SimpleStaticType>::get_simple_static_type(), - mktype( - dhall_proc_macros::subexpr!({ field1: Bool, field2: Optional Bool }) - ) + <A as dhall::de::StaticType>::static_type(), + mktype(subexpr!({ field1: Bool, field2: Optional Bool })) ); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] struct B<'a, T: 'a> { field1: &'a T, field2: Option<T>, } - assert_eq!( - <B<'static, bool>>::get_simple_static_type(), - A::get_simple_static_type() - ); + assert_eq!(<B<'static, bool>>::static_type(), A::static_type()); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] struct C<T>(T, Option<String>); assert_eq!( - <C<bool>>::get_simple_static_type(), - <(bool, Option<String>)>::get_simple_static_type() + <C<bool>>::static_type(), + <(bool, Option<String>)>::static_type() ); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] struct D(); assert_eq!( - <C<D>>::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!({ _1: {}, _2: Optional Text })) + <C<D>>::static_type(), + mktype(subexpr!({ _1: {}, _2: Optional Text })) ); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] enum E<T> { A(T), B(String), }; assert_eq!( - <E<bool>>::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(< A: Bool | B: Text >)) + <E<bool>>::static_type(), + mktype(subexpr!(< A: Bool | B: Text >)) ); + + #[derive(StaticType)] + #[allow(dead_code)] + enum F { + A, + B(bool), + }; + assert_eq!(F::static_type(), mktype(subexpr!(< A | B: Bool >))); } |