aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett Berg <vitiral@gmail.com>2017-07-26 22:08:22 -0600
committerGarrett Berg <vitiral@gmail.com>2017-07-27 07:03:52 -0600
commit219de2dd4d60420f810cb60496d41f164e5c06b0 (patch)
tree7bb58a9c5a5965403f3741f8fdee4cfc0ebd956b /tests
parent71ac3e25f63edac92b4f6cc4ea709491390796ff (diff)
downloadmilf-rs-219de2dd4d60420f810cb60496d41f164e5c06b0.tar.gz
milf-rs-219de2dd4d60420f810cb60496d41f164e5c06b0.zip
close #199: add header information for empty structs
- also add test which fails without this change - also add a few helpful unit tests to table
Diffstat (limited to 'tests')
-rw-r--r--tests/serde.rs22
-rw-r--r--tests/valid.rs3
-rw-r--r--tests/valid/table-multi-empty.json5
-rw-r--r--tests/valid/table-multi-empty.toml5
4 files changed, 35 insertions, 0 deletions
diff --git a/tests/serde.rs b/tests/serde.rs
index c61edf5..57fa5db 100644
--- a/tests/serde.rs
+++ b/tests/serde.rs
@@ -554,3 +554,25 @@ fn newtypes2() {
}),
}
}
+
+#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
+struct CanBeEmpty {
+ a: Option<String>,
+ b: Option<String>,
+}
+
+#[test]
+fn table_structs_empty() {
+ let text = "[bar]\n\n[baz]\n\n[bazv]\na = \"foo\"\n\n[foo]\n";
+ let value: BTreeMap<String, CanBeEmpty> = toml::from_str(text).unwrap();
+ let mut expected: BTreeMap<String, CanBeEmpty> = BTreeMap::new();
+ expected.insert("bar".to_string(), CanBeEmpty::default());
+ expected.insert("baz".to_string(), CanBeEmpty::default());
+ expected.insert(
+ "bazv".to_string(),
+ CanBeEmpty {a: Some("foo".to_string()), b: None},
+ );
+ expected.insert("foo".to_string(), CanBeEmpty::default());
+ assert_eq!(value, expected);
+ assert_eq!(toml::to_string(&value).unwrap(), text);
+}
diff --git a/tests/valid.rs b/tests/valid.rs
index e7577ad..6a04866 100644
--- a/tests/valid.rs
+++ b/tests/valid.rs
@@ -162,6 +162,9 @@ test!(table_empty,
test!(table_sub_empty,
include_str!("valid/table-sub-empty.toml"),
include_str!("valid/table-sub-empty.json"));
+test!(table_multi_empty,
+ include_str!("valid/table-multi-empty.toml"),
+ include_str!("valid/table-multi-empty.json"));
test!(table_whitespace,
include_str!("valid/table-whitespace.toml"),
include_str!("valid/table-whitespace.json"));
diff --git a/tests/valid/table-multi-empty.json b/tests/valid/table-multi-empty.json
new file mode 100644
index 0000000..a6e17c9
--- /dev/null
+++ b/tests/valid/table-multi-empty.json
@@ -0,0 +1,5 @@
+{
+ "a": { "b": {} },
+ "b": {},
+ "c": { "a": {} }
+}
diff --git a/tests/valid/table-multi-empty.toml b/tests/valid/table-multi-empty.toml
new file mode 100644
index 0000000..2266ed2
--- /dev/null
+++ b/tests/valid/table-multi-empty.toml
@@ -0,0 +1,5 @@
+[a]
+[a.b]
+[b]
+[c]
+[c.a]