Skip to content

Commit 0b4a67a

Browse files
Merge pull request #25 from bobroberts177/fix-rt-parser-string-output
Fix rt parser string output and trailing comma example and test
2 parents 96cc58d + fc64058 commit 0b4a67a

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

examples/json5-trailing-comma-formatter/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ output
2929
// My Document
3030
{
3131
breakfast: [
32-
bacon,
33-
eggs,
34-
spam, // <-- a trailing comma will be added here
32+
'bacon',
33+
'eggs',
34+
'spam', // <-- a trailing comma will be added here
3535
],
3636
objekt: {
37-
nested: value, // <-- and here
37+
nested: "value", // <-- and here
3838
}, // <--- and here
3939
}
4040

examples/json5-trailing-comma-formatter/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ fn test() {
8686
let expected = String::from(r#"// My Document
8787
{
8888
breakfast: [
89-
bacon,
90-
eggs,
91-
spam, // <-- a trailing comma will be added here
89+
'bacon',
90+
'eggs',
91+
'spam', // <-- a trailing comma will be added here
9292
],
9393
objekt: {
94-
nested: value, // <-- and here
94+
nested: "value", // <-- and here
9595
}, // <--- and here
9696
}"#);
9797
assert_eq!(res, expected)

src/rt/parser.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,12 @@ impl JSONValue {
286286
JSONValue::NaN => {String::from("Nan")}
287287
JSONValue::Hexadecimal(s) => {s.clone()}
288288
JSONValue::Bool(b) => b.to_string(),
289-
JSONValue::DoubleQuotedString(s) => {s.clone()}
290-
JSONValue::SingleQuotedString(s) => {s.clone()}
289+
JSONValue::DoubleQuotedString(s) => {
290+
format!("\"{s}\"")
291+
}
292+
JSONValue::SingleQuotedString(s) => {
293+
format!("'{s}'")
294+
}
291295
JSONValue::Unary { operator, value} => {
292296
format!("{operator}{value}")
293297
}

0 commit comments

Comments
 (0)