PureYAML/Tests/MultilinePropertyIndentTests.swift
Mihaela M 4dcedbd6aa fix(parsing): carry spanned properties to a deeper indented node
An inline anchor with a tag on the next indented line, above a mapping indented
deeper still (`key: &anchor` / ` !!map` / `  a: b`), left the node introduced by
a further indent token after the properties were consumed. The parser could not
read a node from that indent and rejected it as a missing node.

The indented mapping value now descends through the deeper indent, carrying the
accumulated anchor and tag to the node it introduces, so the properties attach
to the mapping rather than to an empty value.

Fixes yaml-test-suite BU8L; raises parse-level conformance to 312/333 (93.7%)
and value-level to 205/205 (100.0%), with the should-error rate unchanged.
2026-06-29 04:05:04 +02:00

25 lines
1.3 KiB
Swift

@testable import PureYAML
import Testing
@Suite("Node properties may span indented lines above a further-indented node")
struct MultilinePropertyIndentTests {
/// yaml-test-suite BU8L: an inline anchor and a tag on the next indented line are both properties
/// of a mapping that is indented further still (`key: &anchor` / ` !!map` / ` a: b`). The parser
/// descends through the deeper indent to the node rather than rejecting it as a missing node.
@Test("An anchor then an indented tag attach to a further-indented mapping")
func test_anchorThenTagOnDeeperMapping() throws {
let root = try requireMapping(PureYAML.parse("key: &anchor\n !!map\n a: b\n"))
let value = try requireMapping(#require(root?["key"]))
#expect(value?["a"] == .string("b"))
}
/// The same anchored mapping is reachable through an alias, confirming the anchor registered with
/// the nested mapping and not with an empty node.
@Test("The anchor on the spanned properties registers the nested mapping")
func test_spannedPropertyAnchorRegisters() throws {
let root = try requireMapping(PureYAML.parse("key: &anchor\n !!map\n a: b\nref: *anchor\n"))
let aliased = try requireMapping(#require(root?["ref"]))
#expect(aliased?["a"] == .string("b"))
}
}