A node property always attaches to a node, and an empty node is allowed, so an anchor or tag with nothing after it (a bare '&anchor', a 'key: &a', or a '!!str'/'!!null' with no value) denotes that property applied to a null node. parseNode rejected it as a missing node. parseNode now emits a null scalar carrying the properties when a node position holds only an anchor or tag, via a small helper to stay within the complexity limit; with no properties, a missing node is still an error. A '!!str' empty node resolves to the empty string and '!!null' to null. The error-path test that asserted a dangling property throws is corrected, as the construct is valid per the grammar and the official test-suite. Measured against the official YAML test-suite, parse-level conformance rises from 287/333 (86.2%) to 288/333 (86.5%), with value-level up one and no regression.
22 lines
880 B
Swift
22 lines
880 B
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Empty tagged and anchored nodes")
|
|
struct EmptyTaggedNodeTests {
|
|
@Test("A tag with no following node tags an empty node")
|
|
func test_emptyTaggedNode() throws {
|
|
#expect(try PureYAML.parse("x: !!str\n") == .mapping(.init([.init(key: "x", value: .string(""))])))
|
|
#expect(try PureYAML.parse("x: !!null\n") == .mapping(.init([.init(key: "x", value: .null)])))
|
|
}
|
|
|
|
@Test("A tagged empty node works as the final sequence item")
|
|
func test_emptyTaggedSequenceItem() throws {
|
|
#expect(try PureYAML.parse("- a\n- !!str\n") == .sequence(.init([.string("a"), .string("")])))
|
|
}
|
|
|
|
@Test("A real tagged value is unaffected")
|
|
func test_taggedValueUnaffected() throws {
|
|
#expect(try PureYAML.parse("x: !!str hello\n") == .mapping(.init([.init(key: "x", value: .string("hello"))])))
|
|
}
|
|
}
|