From dae106b3de0888e8a704c0efa3f9d991590f7858 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 9 May 2019 21:54:45 +0200 Subject: Rewrite the StaticType trait and everything around it --- dhall/tests/traits.rs | 67 ++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'dhall/tests') 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) -> dhall::de::SimpleType { - x.into() + fn mktype(x: SubExpr) -> 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)) + >::static_type(), + mktype(subexpr!(Optional Bool)) ); assert_eq!( - String::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(Text)) - ); - assert_eq!( - >::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(Optional Bool)) - ); - assert_eq!( - <(bool, Option)>::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!({ _1: Bool, _2: Optional Text })) + <(bool, Vec)>::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, } assert_eq!( - ::get_simple_static_type(), - mktype( - dhall_proc_macros::subexpr!({ field1: Bool, field2: Optional Bool }) - ) + ::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, } - assert_eq!( - >::get_simple_static_type(), - A::get_simple_static_type() - ); + assert_eq!(>::static_type(), A::static_type()); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] struct C(T, Option); assert_eq!( - >::get_simple_static_type(), - <(bool, Option)>::get_simple_static_type() + >::static_type(), + <(bool, Option)>::static_type() ); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] struct D(); assert_eq!( - >::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!({ _1: {}, _2: Optional Text })) + >::static_type(), + mktype(subexpr!({ _1: {}, _2: Optional Text })) ); - #[derive(SimpleStaticType)] + #[derive(StaticType)] #[allow(dead_code)] enum E { A(T), B(String), }; assert_eq!( - >::get_simple_static_type(), - mktype(dhall_proc_macros::subexpr!(< A: Bool | B: Text >)) + >::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 >))); } -- cgit v1.2.3