aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-02-11 09:13:28 -0800
committerAlex Crichton <alex@alexcrichton.com>2017-02-11 09:13:33 -0800
commitfba7778782193f0d0899f82d6b322da59a9044a0 (patch)
tree9530708b15876b4113194ff0ca7ad540bd204050 /tests
parent3e8f87febd59b550349b1edb6cc328c9e7db3cbf (diff)
downloadmilf-rs-fba7778782193f0d0899f82d6b322da59a9044a0.tar.gz
milf-rs-fba7778782193f0d0899f82d6b322da59a9044a0.zip
Fix displaying empty arrays
Closes #145
Diffstat (limited to 'tests')
-rw-r--r--tests/display-tricky.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/display-tricky.rs b/tests/display-tricky.rs
new file mode 100644
index 0000000..069e0f9
--- /dev/null
+++ b/tests/display-tricky.rs
@@ -0,0 +1,49 @@
+extern crate toml;
+#[macro_use] extern crate serde_derive;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct Recipe {
+ pub name: String,
+ pub description: Option<String>,
+ #[serde(default)]
+ pub modules: Vec<Modules>,
+ #[serde(default)]
+ pub packages: Vec<Packages>
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct Modules {
+ pub name: String,
+ pub version: Option<String>
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct Packages {
+ pub name: String,
+ pub version: Option<String>
+}
+
+#[test]
+fn both_ends() {
+ let recipe_works = toml::from_str::<Recipe>(r#"
+ name = "testing"
+ description = "example"
+ modules = []
+
+ [[packages]]
+ name = "base"
+ "#).unwrap();
+ toml::to_string(&recipe_works).unwrap();
+
+ let recipe_fails = toml::from_str::<Recipe>(r#"
+ name = "testing"
+ description = "example"
+ packages = []
+
+ [[modules]]
+ name = "base"
+ "#).unwrap();
+
+ let recipe_toml = toml::Value::try_from(recipe_fails).unwrap();
+ recipe_toml.to_string();
+}