Merge pull request #22433 from github/jketema/swift-json · microsoft/codeql@0780aca · GitHub
Skip to content

Commit 0780aca

Browse files
authored
Merge pull request github#22433 from github/jketema/swift-json
Unified: Hand-roll the mashalling of the JSON
2 parents 3ee0030 + f6efc34 commit 0780aca

3 files changed

Lines changed: 116 additions & 6 deletions

File tree

‎unified/swift-syntax-rs/BUILD.bazel‎

Lines changed: 2 additions & 0 deletions

‎unified/swift-syntax-rs/src/lib.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ mod tests {
120120
json.contains("\"kind\":\"sourceFile\""),
121121
"unexpected tree: {json}"
122122
);
123+
assert!(
124+
json.contains("\"statements\":[]"),
125+
"empty collections should be serialized as JSON arrays: {json}"
126+
);
127+
}
128+
129+
#[test]
130+
fn serializes_json_strings_and_keys_deterministically() {
131+
let source = "/* quote \" slash / backslash \\ tab \t newline\n emoji 😀 combining e\u{301} control \u{1} */\nlet x = 1";
132+
let json = parse_to_json(source).expect("parsing should succeed");
133+
134+
assert!(
135+
json.contains(
136+
r#""text":"\/* quote \" slash \/ backslash \\ tab \t newline\n emoji 😀 combining é control \u0001 *\/""#
137+
),
138+
"JSON string was not escaped correctly: {json}"
139+
);
140+
assert!(
141+
json.contains(r#""start":{"column":1,"line":1,"offset":0}"#),
142+
"JSON object keys were not sorted: {json}"
143+
);
123144
}
124145

125146
#[test]

‎unified/swift-syntax-rs/swift/Sources/SwiftSyntaxFFI/SwiftSyntaxFFI.swift‎

Lines changed: 93 additions & 6 deletions

0 commit comments

Comments
 (0)