Fixed sorting of table values

This commit is contained in:
Evgenii Pashkin 2017-02-19 18:15:58 +03:00
parent a47c66a81d
commit ded040ae9e
2 changed files with 8 additions and 2 deletions

View file

@ -367,12 +367,12 @@ impl ser::Serialize for Value {
// array-of-tables) as all keys must be emitted first. // array-of-tables) as all keys must be emitted first.
for (k, v) in t { for (k, v) in t {
if !v.is_table() && !v.is_array() || 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)?; map.serialize_entry(k, v)?;
} }
} }
for (k, v) in t { 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)?; map.serialize_entry(k, v)?;
} }
} }

View file

@ -94,4 +94,10 @@ fn table() {
\n\ \n\
[[test2]]\n\ [[test2]]\n\
test = [[2, 3], [\"foo\", \"bar\"]]\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");
} }