PureYAML/Tests/TaggedZeroIndentSequenceTests.swift
Mihaela M 5ea6fa668b fix(parsing): end a tagged zero-indent sequence at a sibling key
A block sequence value carrying an inline property (`sequence: !!seq` then
`- entry` at the key's column) is a zero-indent sequence: its entries sit at the
mapping key's own indentation, so a following sibling key ends it.

The untagged form was already parsed as a zero-indent sequence that stops at a
sibling mapping key, but the property-bearing form fell through to the generic
node path, which parsed the sequence without that terminator and read the
sibling key as a mixed sequence-and-mapping entry. The zero-indent sequence is
now handled before the generic path, carrying any property to the sequence.

Fixes yaml-test-suite 57H4; raises parse-level conformance to 313/333 (94.0%)
and value-level to 206/206 (100.0%), with the should-error rate unchanged.
2026-06-29 04:48:47 +02:00

28 lines
1.4 KiB
Swift

@testable import PureYAML
import Testing
@Suite("A tagged zero-indent block sequence is terminated by a sibling mapping key")
struct TaggedZeroIndentSequenceTests {
/// yaml-test-suite 57H4: a block sequence value carrying an inline tag (`sequence: !!seq` then
/// `- entry` at the key's column) is a zero-indent sequence whose entries sit at the mapping
/// key's indentation. A following sibling key (`mapping:`) ends the sequence rather than mixing
/// into it, the same as an untagged zero-indent sequence.
@Test("A tagged zero-indent sequence ends at the next sibling key")
func test_taggedZeroIndentSequence() throws {
let root = try requireMapping(PureYAML.parse(
"sequence: !!seq\n- entry\n- !!seq\n - nested\nmapping: !!map\n foo: bar\n",
))
#expect(root?["sequence"] == .sequence([.string("entry"), .sequence([.string("nested")])]))
let mapping = try requireMapping(#require(root?["mapping"]))
#expect(mapping?["foo"] == .string("bar"))
}
/// The untagged zero-indent sequence followed by a sibling key keeps working unchanged.
@Test("An untagged zero-indent sequence still ends at the next sibling key")
func test_untaggedZeroIndentSequence() throws {
let root = try requireMapping(PureYAML.parse("seq:\n- a\n- b\nother: x\n"))
#expect(root?["seq"] == .sequence([.string("a"), .string("b")]))
#expect(root?["other"] == .string("x"))
}
}