Files
plak/Tests/PlakCoreTests/JSONFormatterTests.swift
T
2026-10-17 17:33:13 +02:00

27 lines
708 B
Swift

import PlakCore
import Testing
@Suite struct JSONFormatterTests {
@Test("pretty-printing keeps the key order and the spelling of numbers and strings")
func keepsOrder() {
let pretty = JSONFormatter.pretty(#"{"z":1.50,"a":[2e3,-0.1],"m":{"q":"a, b: \"c\" {"}}"#)
#expect(pretty == """
{
"z": 1.50,
"a": [
2e3,
-0.1
],
"m": {
"q": "a, b: \\"c\\" {"
}
}
""")
}
@Test("empty objects and arrays stay on one line, and spaces outside strings go")
func empty() {
#expect(JSONFormatter.pretty(#"[ {}, [ ], "a b" ]"#) == "[\n {},\n [],\n \"a b\"\n]")
}
}