Merge pull request #151 from EPashkin/fix_table_values_sorting

Fixed sorting of table values
This commit is contained in:
Alex Crichton 2017-02-21 09:31:19 -06:00 committed by GitHub
commit c680668d22
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.
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)?;
}
}

View file

@ -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");
}