A block collection must begin on the line after its node properties, so a
block sequence whose first entry sits on the same line as its anchor or tag
('&a - x', '!!seq - x') is malformed. The parser accepted it, anchoring or
tagging the inline sequence.
parseBlockSequence now rejects a sequence whose first block entry shares a
line with the anchor or tag that introduced it, via a small helper to stay
within the complexity and brace-style limits. An anchor or tag on its own
line above the sequence, inside a sequence item ('- &a x'), before a flow
sequence ('&a [x]'), or on a scalar is unaffected; the mapping form is
left alone, since '&a key: value' is a valid anchored key.
Measured against the official YAML test-suite, parse-level conformance
rises from 267/333 (80.2%) to 268/333 (80.5%) with no regression.
27 lines
1.1 KiB
Swift
27 lines
1.1 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("A block sequence after a node property")
|
|
struct BlockSequenceAfterPropertyTests {
|
|
@Test("A block sequence on the same line as its anchor or tag is rejected", arguments: [
|
|
"&anchor - sequence entry\n", // an anchor immediately before a block entry
|
|
"!!seq - x\n", // a tag immediately before a block entry
|
|
])
|
|
func test_inlineBlockSequenceAfterPropertyRejected(_ yaml: String) throws {
|
|
#expect(throws: PureYAML.Parsing.ParseError.self) {
|
|
try PureYAML.parse(yaml)
|
|
}
|
|
}
|
|
|
|
@Test("Properties positioned correctly around a sequence stay valid", arguments: [
|
|
"&anchor\n- a\n- b\n", // the anchor on its own line, sequence below
|
|
"- &anchor x\n- y\n", // the anchor inside a sequence item
|
|
"&anchor [a, b]\n", // a flow sequence may follow an anchor inline
|
|
"key: &anchor\n - a\n - b\n", // the anchor then an indented sequence
|
|
"&anchor value\n", // a scalar may follow an anchor inline
|
|
])
|
|
func test_validSequencePropertyPlacement(_ yaml: String) throws {
|
|
_ = try PureYAML.parse(yaml)
|
|
}
|
|
}
|