PureYAML/Tests/ValuePropertyIndentationTests.swift
Mihaela M 25b1388dbb fix(parsing): reject a later under-indented property on a mapping value
The value-property indentation check used only the first property's mark,
so it caught a sole under-indented property ('seq:' then '&anchor') but not
a second one after an inline first ('key: &x' then a '!!tag' in column 1),
which still parsed.

The last consumed property is cursor.previous after consumeProperties, so
the check now uses it instead of the first mark, catching an under-indented
property whether it is the only one or a later one. Inline properties, a
property indented under the key, and a properly indented anchor-and-tag pair
are unaffected.

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

28 lines
1.2 KiB
Swift

@testable import PureYAML
import Testing
@Suite("A mapping value's property indentation")
struct ValuePropertyIndentationTests {
@Test("An under-indented value property is rejected, whether it is the first or a later one", arguments: [
"---\nseq:\n&anchor\n- a\n- b\n", // a sole anchor at the key's indent
"key: &x\n!!map\n a: b\n", // a second property (a tag) at the key's indent
])
func test_underIndentedValuePropertyRejected(_ yaml: String) throws {
#expect(throws: PureYAML.Parsing.ParseError.self) {
try PureYAML.parse(yaml)
}
}
@Test("Properties indented past the key, or inline, stay valid", arguments: [
"seq:\n &a\n - x\n", // an anchor indented under the key
"key: &a value\n", // an inline anchor on the value
"key: &a !!str value\n", // an inline anchor and tag
"key:\n &a !!map\n a: b\n", // properly indented anchor and tag
"seq:\n- a\n- b\n", // a block sequence at the key's indent (no property)
"key:\n &a sub: v\n", // an indented anchored key
])
func test_validValuePropertyPlacement(_ yaml: String) throws {
_ = try PureYAML.parse(yaml)
}
}