summaryrefslogtreecommitdiff
path: root/serde_dhall/tests
diff options
context:
space:
mode:
authorNadrieril2020-04-05 17:57:07 +0100
committerGitHub2020-04-05 17:57:07 +0100
commit7e977f282fb6a0eff0ef45738b9b5c98dc4c6fee (patch)
treead4249609707fd8720a44469152105c2f6a67c79 /serde_dhall/tests
parent5a5aa49e64197899006751db72e404f4b2292d4e (diff)
parent820214615547101f8f2b5de209b5189968bddfee (diff)
Merge pull request #154 from Nadrieril/cleanup-api
Rewrite serde_dhall API
Diffstat (limited to '')
-rw-r--r--serde_dhall/tests/de.rs28
-rw-r--r--serde_dhall/tests/traits.rs6
-rw-r--r--serde_dhall/tests/version_numbers.rs17
3 files changed, 42 insertions, 9 deletions
diff --git a/serde_dhall/tests/de.rs b/serde_dhall/tests/de.rs
index 74912dd..a5c42fd 100644
--- a/serde_dhall/tests/de.rs
+++ b/serde_dhall/tests/de.rs
@@ -1,10 +1,10 @@
use serde::Deserialize;
-use serde_dhall::{from_str, from_str_auto_type, StaticType};
+use serde_dhall::{from_str, FromDhall, StaticType};
#[test]
fn test_de_typed() {
- fn parse<T: serde_dhall::de::Deserialize + StaticType>(s: &str) -> T {
- from_str_auto_type(s).unwrap()
+ fn parse<T: FromDhall + StaticType>(s: &str) -> T {
+ from_str(s).static_type_annotation().parse().unwrap()
}
assert_eq!(parse::<bool>("True"), true);
@@ -51,12 +51,17 @@ fn test_de_typed() {
Y(i64),
}
assert_eq!(parse::<Baz>("< X | Y: Integer >.X"), Baz::X);
+
+ assert!(from_str("< X | Y: Integer >.Y")
+ .static_type_annotation()
+ .parse::<Baz>()
+ .is_err());
}
#[test]
fn test_de_untyped() {
- fn parse<T: serde_dhall::de::Deserialize>(s: &str) -> T {
- from_str(s).unwrap()
+ fn parse<T: FromDhall>(s: &str) -> T {
+ from_str(s).parse().unwrap()
}
// Test tuples on record of wrong type
@@ -83,6 +88,17 @@ fn test_de_untyped() {
expected_map
);
+ #[derive(Debug, PartialEq, Eq, Deserialize)]
+ struct Foo {
+ x: u64,
+ y: Option<u64>,
+ }
+ // Omit optional field
+ assert_eq!(parse::<Foo>("{ x = 1 }"), Foo { x: 1, y: None });
+
// https://github.com/Nadrieril/dhall-rust/issues/155
- assert!(from_str::<bool>("List/length [True, 42]").is_err());
+ assert!(from_str("List/length [True, 42]").parse::<bool>().is_err());
}
+
+// TODO: test various builder configurations
+// In particular test cloning and reusing builder
diff --git a/serde_dhall/tests/traits.rs b/serde_dhall/tests/traits.rs
index 15a91ed..3c6fbfe 100644
--- a/serde_dhall/tests/traits.rs
+++ b/serde_dhall/tests/traits.rs
@@ -1,9 +1,9 @@
-use serde_dhall::{from_str, StaticType, Value};
+use serde_dhall::{from_str, SimpleType, StaticType};
#[test]
fn test_static_type() {
- fn parse(s: &str) -> Value {
- from_str(s).unwrap()
+ fn parse(s: &str) -> SimpleType {
+ from_str(s).parse().unwrap()
}
assert_eq!(bool::static_type(), parse("Bool"));
diff --git a/serde_dhall/tests/version_numbers.rs b/serde_dhall/tests/version_numbers.rs
new file mode 100644
index 0000000..8307e47
--- /dev/null
+++ b/serde_dhall/tests/version_numbers.rs
@@ -0,0 +1,17 @@
+#[test]
+fn test_readme_deps() {
+ version_sync::assert_markdown_deps_updated!("../README.md");
+}
+
+#[test]
+fn test_html_root_url() {
+ version_sync::assert_html_root_url_updated!("src/lib.rs");
+}
+
+#[test]
+fn test_readme_mentions_version() {
+ version_sync::assert_contains_regex!(
+ "../README.md",
+ "^#### \\[{version}\\]"
+ );
+}