A block implicit key must lie on a single line, so a quoted scalar whose opening and closing quotes sit on different lines cannot be one. The scanner synthesized the implicit key regardless, so '"c\n d": 1' and the single-quoted form parsed as a mapping with a folded key. When synthesizing the implicit key for a quoted scalar followed by ':', the scanner now rejects the construct if the scalar spanned a line break. The restriction is block-only: a flow mapping key may span lines, so the check is gated on block context, and a multiline quoted value, a single- line quoted key, and an explicit key (which carries no ':' directly after the scalar) are all unaffected. Measured against the official YAML test-suite, parse-level conformance rises from 261/333 (78.4%) to 264/333 (79.3%) with no regression.
27 lines
1.0 KiB
Swift
27 lines
1.0 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Multiline implicit keys")
|
|
struct MultilineImplicitKeyTests {
|
|
@Test("A quoted block implicit key that spans lines is rejected", arguments: [
|
|
"\"c\n d\": 1\n", // a double-quoted key across two lines
|
|
"'c\n d': 1\n", // a single-quoted key across two lines
|
|
])
|
|
func test_multilineBlockKeyRejected(_ yaml: String) throws {
|
|
#expect(throws: PureYAML.Parsing.ParseError.self) {
|
|
try PureYAML.parse(yaml)
|
|
}
|
|
}
|
|
|
|
@Test("Single-line keys, multiline values, flow keys, and explicit keys stay valid", arguments: [
|
|
"\"a b\": 1\n", // a single-line quoted key
|
|
"k: \"a\nb\"\n", // a multiline quoted value (not a key)
|
|
"{ \"a\nb\": 1 }\n", // a flow mapping key may span lines
|
|
"---\n- { \"multi\n line\": value}\n", // a multiline flow key inside a sequence
|
|
"? \"a\nb\"\n: v\n", // an explicit key may span lines
|
|
])
|
|
func test_validQuotedKeysAndValues(_ yaml: String) throws {
|
|
_ = try PureYAML.parse(yaml)
|
|
}
|
|
}
|