An explicit key (`?`) may have no key node: `? : v`, a trailing `? }` / `? ]` / `? ,`, or `?` at the end of a flow mapping all denote a null key. The parser now emits an empty key in those positions instead of failing to find a node before the value indicator or terminator. Fixes suite case DFF7 (parse-level conformance 316 -> 317); adds tests.
34 lines
1.3 KiB
Swift
34 lines
1.3 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
/// An explicit key (`?`) in a flow mapping may have no key node: `? : v`, a trailing `? }` or
|
|
/// `? ]` or `? ,`, all denote a null key. The parser emits an empty key rather than failing to
|
|
/// find a node before the value indicator or terminator.
|
|
@Suite("Flow explicit empty key")
|
|
struct FlowExplicitEmptyKeyTests {
|
|
@Test("An explicit key with a value but no key node is a null key")
|
|
func test_explicitEmptyKeyWithValue() throws {
|
|
#expect(try PureYAML.parse("{ ? : v }") == .mapping(.init([
|
|
.init(keyNode: .string(""), value: .string("v")),
|
|
])))
|
|
}
|
|
|
|
@Test("A trailing explicit key with no node maps a null key to null")
|
|
func test_trailingExplicitEmptyKey() throws {
|
|
#expect(try PureYAML.parse("{ a, ? }") == .mapping(.init([
|
|
.init(key: "a", value: .null),
|
|
.init(keyNode: .string(""), value: .null),
|
|
])))
|
|
}
|
|
|
|
@Test("Suite case DFF7: a flow mapping ending with an empty explicit key")
|
|
func test_dff7() throws {
|
|
let yaml = "{\n? explicit: entry,\nimplicit: entry,\n?\n}\n"
|
|
#expect(try PureYAML.parse(yaml) == .mapping(.init([
|
|
.init(key: "explicit", value: .string("entry")),
|
|
.init(key: "implicit", value: .string("entry")),
|
|
.init(keyNode: .string(""), value: .null),
|
|
])))
|
|
}
|
|
}
|