PureYAML/Tests/BlockEntryAfterFlowTests.swift
Mihaela M d79df8c4bc fix(parsing): reject a block entry after a flow collection on a line
A block sequence entry cannot follow a flow collection that closed earlier
on the same line ('- { y: z }- invalid', '- [a] - b'): the entry would
begin a sequence inline after a complete node. The scanner accepted it,
producing extra sequence items.

The scanner now records when a flow collection closes at the top level on
the current line and rejects a following block entry. The flag resets at
each line break, so a flow collection on its own line is unaffected, and a
nested block entry ('- -') has no preceding flow close, so it stays valid.

Measured against the official YAML test-suite, parse-level conformance
rises from 276/333 (82.9%) to 277/333 (83.2%) with no regression.
2026-06-28 01:34:55 +02:00

26 lines
993 B
Swift

@testable import PureYAML
import Testing
@Suite("A block entry after a flow collection")
struct BlockEntryAfterFlowTests {
@Test("A block entry on the same line as a closed flow collection is rejected", arguments: [
"---\n- { y: z }- invalid\n", // a block entry after a flow mapping
"- [a] - b\n", // a block entry after a flow sequence
])
func test_blockEntryAfterFlowRejected(_ yaml: String) throws {
#expect(throws: PureYAML.Parsing.ParseError.self) {
try PureYAML.parse(yaml)
}
}
@Test("Nested entries and flow collections on their own line stay valid", arguments: [
"- - a\n- - b\n", // a nested block sequence
"- [a]\n- [b]\n", // flow sequences, each on its own line
"- {a: b}\n- c\n", // a flow mapping item then a sibling entry
"[[a], [b]]\n", // nested flow sequences
])
func test_validBlockAndFlowEntries(_ yaml: String) throws {
_ = try PureYAML.parse(yaml)
}
}