From 52f9ecfc4dac65d305fd920e8c7f748889a0804f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 12 Aug 2019 23:24:48 +0200 Subject: Move api into its own crate --- serde_dhall/tests/traits.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 serde_dhall/tests/traits.rs (limited to 'serde_dhall/tests') diff --git a/serde_dhall/tests/traits.rs b/serde_dhall/tests/traits.rs new file mode 100644 index 0000000..99f1109 --- /dev/null +++ b/serde_dhall/tests/traits.rs @@ -0,0 +1,68 @@ +#![feature(proc_macro_hygiene)] +use serde_dhall::de::{from_str, StaticType, Type}; + +#[test] +fn test_static_type() { + fn parse(s: &str) -> Type { + from_str(s, None).unwrap() + } + + assert_eq!(bool::static_type(), parse("Bool")); + assert_eq!(String::static_type(), parse("Text")); + assert_eq!(>::static_type(), parse("Optional Bool")); + assert_eq!( + <(bool, Vec)>::static_type(), + parse("{ _1: Bool, _2: List Text }") + ); + + #[derive(serde_dhall::de::StaticType)] + #[allow(dead_code)] + struct A { + field1: bool, + field2: Option, + } + assert_eq!( + ::static_type(), + parse("{ field1: Bool, field2: Optional Bool }") + ); + + #[derive(StaticType)] + #[allow(dead_code)] + struct B<'a, T: 'a> { + field1: &'a T, + field2: Option, + } + assert_eq!(>::static_type(), A::static_type()); + + #[derive(StaticType)] + #[allow(dead_code)] + struct C(T, Option); + assert_eq!( + >::static_type(), + <(bool, Option)>::static_type() + ); + + #[derive(StaticType)] + #[allow(dead_code)] + struct D(); + assert_eq!( + >::static_type(), + parse("{ _1: {}, _2: Optional Text }") + ); + + #[derive(StaticType)] + #[allow(dead_code)] + enum E { + A(T), + B(String), + }; + assert_eq!(>::static_type(), parse("< A: Bool | B: Text >")); + + #[derive(StaticType)] + #[allow(dead_code)] + enum F { + A, + B(bool), + }; + assert_eq!(F::static_type(), parse("< A | B: Bool >")); +} -- cgit v1.2.3 From 1ea8b10051d29c634399304273d6ee565d039bc2 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 15:25:53 +0200 Subject: Merge `Type` and `Value` in serde_dhall There was no point in separating them --- serde_dhall/tests/traits.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'serde_dhall/tests') diff --git a/serde_dhall/tests/traits.rs b/serde_dhall/tests/traits.rs index 99f1109..40ac1d7 100644 --- a/serde_dhall/tests/traits.rs +++ b/serde_dhall/tests/traits.rs @@ -1,9 +1,9 @@ #![feature(proc_macro_hygiene)] -use serde_dhall::de::{from_str, StaticType, Type}; +use serde_dhall::de::{from_str, StaticType, Value}; #[test] fn test_static_type() { - fn parse(s: &str) -> Type { + fn parse(s: &str) -> Value { from_str(s, None).unwrap() } -- cgit v1.2.3 From bf5d33f3ba991afe398d58fb4fed38ec72d6f4c7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 13 Aug 2019 16:31:41 +0200 Subject: Rework API to resemble that of serde_json --- serde_dhall/tests/traits.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'serde_dhall/tests') diff --git a/serde_dhall/tests/traits.rs b/serde_dhall/tests/traits.rs index 40ac1d7..55be63b 100644 --- a/serde_dhall/tests/traits.rs +++ b/serde_dhall/tests/traits.rs @@ -1,10 +1,10 @@ #![feature(proc_macro_hygiene)] -use serde_dhall::de::{from_str, StaticType, Value}; +use serde_dhall::{from_str, StaticType, Value}; #[test] fn test_static_type() { fn parse(s: &str) -> Value { - from_str(s, None).unwrap() + from_str(s).unwrap() } assert_eq!(bool::static_type(), parse("Bool")); @@ -15,14 +15,14 @@ fn test_static_type() { parse("{ _1: Bool, _2: List Text }") ); - #[derive(serde_dhall::de::StaticType)] + #[derive(serde_dhall::StaticType)] #[allow(dead_code)] struct A { field1: bool, field2: Option, } assert_eq!( - ::static_type(), + ::static_type(), parse("{ field1: Bool, field2: Optional Bool }") ); -- cgit v1.2.3 From 816f616479cfa277e19b2e69be6c41bc8210e032 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 15 Aug 2019 22:12:06 +0200 Subject: Disable some unused unstable features --- serde_dhall/tests/traits.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'serde_dhall/tests') diff --git a/serde_dhall/tests/traits.rs b/serde_dhall/tests/traits.rs index 55be63b..15a91ed 100644 --- a/serde_dhall/tests/traits.rs +++ b/serde_dhall/tests/traits.rs @@ -1,4 +1,3 @@ -#![feature(proc_macro_hygiene)] use serde_dhall::{from_str, StaticType, Value}; #[test] -- cgit v1.2.3