summaryrefslogtreecommitdiff
path: root/serde_dhall/tests
diff options
context:
space:
mode:
authorNadrieril2020-10-27 23:33:26 +0000
committerNadrieril2020-10-27 23:33:26 +0000
commit77258af83dfe93293ad854ccb401d1ce7453edfc (patch)
treea349d40ab3b9f5bee0ebbe2d3da4a87f50d90ae8 /serde_dhall/tests
parentf84609a06372eedcf4727ceb91430b82c99e6039 (diff)
Make `SimpleValue` deserializable within other types
Fixes https://github.com/Nadrieril/dhall-rust/issues/184
Diffstat (limited to 'serde_dhall/tests')
-rw-r--r--serde_dhall/tests/de.rs34
1 files changed, 33 insertions, 1 deletions
diff --git a/serde_dhall/tests/de.rs b/serde_dhall/tests/de.rs
index a418563..549a753 100644
--- a/serde_dhall/tests/de.rs
+++ b/serde_dhall/tests/de.rs
@@ -1,5 +1,5 @@
use serde::Deserialize;
-use serde_dhall::{from_str, FromDhall, StaticType};
+use serde_dhall::{from_str, FromDhall, NumKind, SimpleValue, StaticType};
#[test]
fn test_de_typed() {
@@ -116,5 +116,37 @@ fn test_de_untyped() {
assert!(from_str("List/length [True, 42]").parse::<bool>().is_err());
}
+#[test]
+fn test_de_simplevalue() {
+ let bool_true = SimpleValue::Num(NumKind::Bool(true));
+ // https://github.com/Nadrieril/dhall-rust/issues/184
+ assert_eq!(
+ from_str("[ True ]").parse::<Vec<SimpleValue>>().unwrap(),
+ vec![bool_true.clone()]
+ );
+
+ assert_eq!(
+ from_str("< Foo >.Foo").parse::<SimpleValue>().unwrap(),
+ SimpleValue::Union("Foo".into(), None)
+ );
+ assert_eq!(
+ from_str("< Foo: Bool >.Foo True")
+ .parse::<SimpleValue>()
+ .unwrap(),
+ SimpleValue::Union("Foo".into(), Some(Box::new(bool_true.clone())))
+ );
+
+ #[derive(Debug, PartialEq, Eq, Deserialize)]
+ struct Foo {
+ foo: SimpleValue,
+ }
+ assert_eq!(
+ from_str("{ foo = True }").parse::<Foo>().unwrap(),
+ Foo {
+ foo: bool_true.clone()
+ },
+ );
+}
+
// TODO: test various builder configurations
// In particular test cloning and reusing builder