28 lines
1.1 KiB
Swift
28 lines
1.1 KiB
Swift
import HelderCore
|
|
import Testing
|
|
|
|
@Suite struct JSONGrammarTests {
|
|
@Test("keys read as properties, values keep their own roles")
|
|
func keysAndValues() {
|
|
let text = "{\"name\": \"helder\", \"n\": -1.5e2, \"ok\": true, \"none\": null, \"list\": [\"a\"]}"
|
|
#expect(role("\"name\"", in: text, .json) == .variable)
|
|
#expect(role("\"helder\"", in: text, .json) == .string)
|
|
#expect(role("-1.5e2", in: text, .json) == .number)
|
|
#expect(role("true", in: text, .json) == .number)
|
|
#expect(role("null", in: text, .json) == .number)
|
|
#expect(role("\"a\"", in: text, .json) == .string)
|
|
}
|
|
|
|
@Test("an escaped quote does not end the string")
|
|
func escapedQuote() {
|
|
#expect(role("\"a \\\" b\"", in: "{\"k\": \"a \\\" b\"}", .json) == .string)
|
|
}
|
|
|
|
@Test("tsconfig-style comments are allowed")
|
|
func comments() {
|
|
let text = "{\n // line\n /* block */ \"a\": 1\n}"
|
|
#expect(role("// line", in: text, .json) == .comment)
|
|
#expect(role("/* block */", in: text, .json) == .comment)
|
|
}
|
|
}
|