Skip to content

Commit c537546

Browse files
authored
RUST-876 Quote keys in Document's Display format (#274)
1 parent b55e958 commit c537546

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Display for Document {
8484
fmt.write_str(", ")?;
8585
}
8686

87-
write!(fmt, "{}: {}", k, v)?;
87+
write!(fmt, "\"{}\": {}", k, v)?;
8888
}
8989

9090
write!(fmt, "{}}}", if !first { " " } else { "" })

src/tests/modules/macros.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ fn standard_format() {
3737
};
3838

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

62-
let expected = "{ a: \"foo\", b: { ok: \"then\" } }".to_string();
63+
let expected = "{ \"a\": \"foo\", \"b\": { \"ok\": \"then\" } }".to_string();
6364
assert_eq!(expected, format!("{}", doc));
6465
}
6566

0 commit comments

Comments
 (0)