From e1a30c6f248c0c17c97598290a0d94993dbb0325 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 10 Apr 2019 19:16:11 +0200 Subject: Add SimpleType and SimpeStaticType. Derive the latter --- dhall/tests/traits.rs | 54 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'dhall/tests/traits.rs') diff --git a/dhall/tests/traits.rs b/dhall/tests/traits.rs index ac6b5e6..1e9b3c2 100644 --- a/dhall/tests/traits.rs +++ b/dhall/tests/traits.rs @@ -1,53 +1,71 @@ #![feature(proc_macro_hygiene)] -use dhall::StaticType; +use dhall::SimpleStaticType; +use dhall_core::{SubExpr, X}; use dhall_generator::dhall_expr; #[test] -fn test_dhall_type() { - assert_eq!(bool::get_type(), dhall_expr!(Bool)); - assert_eq!(String::get_type(), dhall_expr!(Text)); +fn test_static_type() { + fn mktype(x: SubExpr) -> dhall::expr::SimpleType { + x.into() + } + + assert_eq!(bool::get_simple_static_type(), mktype(dhall_expr!(Bool))); + assert_eq!(String::get_simple_static_type(), mktype(dhall_expr!(Text))); assert_eq!( - <(bool, Option)>::get_type(), - dhall_expr!({ _1: Bool, _2: Optional Text }) + >::get_simple_static_type(), + mktype(dhall_expr!(Optional Bool)) + ); + assert_eq!( + <(bool, Option)>::get_simple_static_type(), + mktype(dhall_expr!({ _1: Bool, _2: Optional Text })) ); - #[derive(dhall::StaticType)] + #[derive(dhall::SimpleStaticType)] #[allow(dead_code)] struct A { field1: bool, field2: Option, } assert_eq!( - ::get_type(), - dhall_expr!({ field1: Bool, field2: Optional Bool }) + ::get_simple_static_type(), + mktype(dhall_expr!({ field1: Bool, field2: Optional Bool })) ); - #[derive(StaticType)] + #[derive(SimpleStaticType)] #[allow(dead_code)] struct B<'a, T: 'a> { field1: &'a T, field2: Option, } - assert_eq!(>::get_type(), A::get_type()); + assert_eq!( + >::get_simple_static_type(), + A::get_simple_static_type() + ); - #[derive(StaticType)] + #[derive(SimpleStaticType)] #[allow(dead_code)] struct C(T, Option); - assert_eq!(>::get_type(), <(bool, Option)>::get_type()); + assert_eq!( + >::get_simple_static_type(), + <(bool, Option)>::get_simple_static_type() + ); - #[derive(StaticType)] + #[derive(SimpleStaticType)] #[allow(dead_code)] struct D(); assert_eq!( - >::get_type(), - dhall_expr!({ _1: {}, _2: Optional Text }) + >::get_simple_static_type(), + mktype(dhall_expr!({ _1: {}, _2: Optional Text })) ); - #[derive(StaticType)] + #[derive(SimpleStaticType)] #[allow(dead_code)] enum E { A(T), B(String), }; - assert_eq!(>::get_type(), dhall_expr!(< A: Bool | B: Text >)); + assert_eq!( + >::get_simple_static_type(), + mktype(dhall_expr!(< A: Bool | B: Text >)) + ); } -- cgit v1.2.3