aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/value.rs4
-rw-r--r--tests/display.rs6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/value.rs b/src/value.rs
index 4d56023..3a366d8 100644
--- a/src/value.rs
+++ b/src/value.rs
@@ -367,12 +367,12 @@ impl ser::Serialize for Value {
// array-of-tables) as all keys must be emitted first.
for (k, v) in t {
if !v.is_table() && !v.is_array() ||
- (v.as_array().map(|a| a.len() == 0).unwrap_or(false)) {
+ (v.as_array().map(|a| !a.iter().any(|v| v.is_table())).unwrap_or(false)) {
map.serialize_entry(k, v)?;
}
}
for (k, v) in t {
- if v.as_array().map(|a| a.len() > 0).unwrap_or(false) {
+ if v.as_array().map(|a| a.iter().any(|v| v.is_table())).unwrap_or(false) {
map.serialize_entry(k, v)?;
}
}
diff --git a/tests/display.rs b/tests/display.rs
index c38355a..ca4fdd8 100644
--- a/tests/display.rs
+++ b/tests/display.rs
@@ -94,4 +94,10 @@ fn table() {
\n\
[[test2]]\n\
test = [[2, 3], [\"foo\", \"bar\"]]\n");
+ assert_eq!(Table(map! {
+ "test" => Array(vec![Integer(2)]),
+ "test2" => Integer(2)
+ }).to_string(),
+ "test = [2]\n\
+ test2 = 2\n");
}