A quoted mapping key followed by a space and then ':' ('"key" : value')
failed to parse: the scanner synthesizes the implicit mapping-key token by
checking the character immediately after the key, but a quoted scalar
stops at its closing quote, leaving the separating space, whereas a plain
scalar consumes that space into itself and ends at the colon. The quoted
path now looks past spaces for the colon, which the spec allows between an
implicit key and its value indicator.
Quoted keys with no space, quoted values, and plain keys (which already
worked with a space) are unaffected. Measured against the official YAML
test-suite, parse-level conformance rises from 238/333 (71.5%) to
240/333 (72.1%), with no regression.
20 lines
835 B
Swift
20 lines
835 B
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Quoted mapping keys")
|
|
struct QuotedKeyTests {
|
|
@Test("A quoted key may have a space before its colon")
|
|
func test_quotedKeyWithSpaceBeforeColon() throws {
|
|
let expected = PureYAML.Model.Value.mapping(.init([.init(key: "key", value: .string("value"))]))
|
|
#expect(try PureYAML.parse("\"key\" : value\n") == expected)
|
|
#expect(try PureYAML.parse("'key' : value\n") == expected)
|
|
// The no-space form keeps working.
|
|
#expect(try PureYAML.parse("\"key\": value\n") == expected)
|
|
}
|
|
|
|
@Test("A quoted value, with or without a preceding space, is unaffected")
|
|
func test_quotedValueUnaffected() throws {
|
|
#expect(try PureYAML.parse("k: \"quoted value\"\n") == .mapping(.init([.init(key: "k", value: .string("quoted value"))])))
|
|
}
|
|
}
|