A compact nested block sequence (`- - x`) carries no indent or dedent tokens, only block entries at their source columns. The sibling-entry loop in parseBlockSequence collected every following block entry by kind alone, so the inner sequence absorbed an entry that belonged to an enclosing one: `- - x` then `- - y` parsed as a single outer item `[[x, [y]]]` instead of two items `[[x], [y]]`. Record the first entry's column as the sequence's column and continue the sibling loop only while the next entry sits at it. An entry at a smaller column ends this sequence and is handled by the enclosing one; entries at the same column still group, and flat sequences are unchanged. Raises yaml-test-suite value-level conformance to 190/194 (97.9%) with the parse-level and should-error rejection rates unchanged. 460 tests pass.
38 lines
1.4 KiB
Swift
38 lines
1.4 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
/// A compact nested block sequence (`- - x`) carries no indent/dedent tokens, only block entries at
|
|
/// their columns. A sequence collects sibling items only at its own column, so a later entry at a
|
|
/// smaller column ends it and belongs to the enclosing sequence: `- - x` then `- - y` is `[[x], [y]]`,
|
|
/// two outer items, not one outer item holding both.
|
|
@Suite("Compact nested sequence")
|
|
struct CompactNestedSequenceTests {
|
|
@Test("Two compact nested entries are two outer items")
|
|
func test_twoNestedItems() throws {
|
|
#expect(try PureYAML.parse("- - x\n- - y\n") == .sequence([
|
|
.sequence([.string("x")]),
|
|
.sequence([.string("y")]),
|
|
]))
|
|
}
|
|
|
|
@Test("Three levels of compact nesting separate at the outer column")
|
|
func test_threeLevels() throws {
|
|
#expect(try PureYAML.parse("- - - []\n- - - {}\n") == .sequence([
|
|
.sequence([.sequence([.sequence([])])]),
|
|
.sequence([.sequence([.mapping(.init([]))])]),
|
|
]))
|
|
}
|
|
|
|
@Test("Entries at the same column stay one sequence")
|
|
func test_sameColumnSiblings() throws {
|
|
#expect(try PureYAML.parse("- - a\n - b\n") == .sequence([
|
|
.sequence([.string("a"), .string("b")]),
|
|
]))
|
|
}
|
|
|
|
@Test("A flat sequence is unchanged")
|
|
func test_flatSequence() throws {
|
|
#expect(try PureYAML.parse("- a\n- b\n") == .sequence([.string("a"), .string("b")]))
|
|
}
|
|
}
|