Skip to content

Commit

Permalink
RUST-876 Quote keys in Document's Display format (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickfreed authored Jun 25, 2021
1 parent b55e958 commit c537546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Display for Document {
fmt.write_str(", ")?;
}

write!(fmt, "{}: {}", k, v)?;
write!(fmt, "\"{}\": {}", k, v)?;
}

write!(fmt, "{}}}", if !first { " " } else { "" })
Expand Down
13 changes: 7 additions & 6 deletions src/tests/modules/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ fn standard_format() {
};

let expected = format!(
"{{ float: 2.4, string: \"hello\", array: [\"testing\", 1, true, [1, 2]], doc: {{ fish: \
\"in\", a: \"barrel\", !: 1 }}, bool: true, null: null, regexp: /s[ao]d/i, \
with_wrapped_parens: -20, code: function(x) {{ return x._id; }}, i32: 12, i64: -55, \
timestamp: Timestamp(0, 229999444), binary: Binary(0x5, {}), encrypted: Binary(0x6, {}), \
_id: ObjectId(\"{}\"), date: DateTime(\"{}\") }}",
"{{ \"float\": 2.4, \"string\": \"hello\", \"array\": [\"testing\", 1, true, [1, 2]], \
\"doc\": {{ \"fish\": \"in\", \"a\": \"barrel\", \"!\": 1 }}, \"bool\": true, \"null\": \
null, \"regexp\": /s[ao]d/i, \"with_wrapped_parens\": -20, \"code\": function(x) {{ \
return x._id; }}, \"i32\": 12, \"i64\": -55, \"timestamp\": Timestamp(0, 229999444), \
\"binary\": Binary(0x5, {}), \"encrypted\": Binary(0x6, {}), \"_id\": ObjectId(\"{}\"), \
\"date\": DateTime(\"{}\") }}",
base64::encode("thingies"),
base64::encode("secret"),
hex::encode(id_string),
Expand All @@ -59,7 +60,7 @@ fn non_trailing_comma() {
"b": { "ok": "then" }
};

let expected = "{ a: \"foo\", b: { ok: \"then\" } }".to_string();
let expected = "{ \"a\": \"foo\", \"b\": { \"ok\": \"then\" } }".to_string();
assert_eq!(expected, format!("{}", doc));
}

Expand Down

0 comments on commit c537546

Please sign in to comment.