@testable import PureYAML import Testing @Suite("A node property may sit indented above a zero-indent block sequence") struct SequencePropertyIndentTests { /// yaml-test-suite SKE5: a block sequence may sit at its parent mapping key's indentation while a /// property written above it is more indented (`seq:` / ` &anchor` / `- a`). The property binds to /// the sequence, not to an empty anchored value, so the entries are not orphaned. @Test("An anchor indented above a zero-indent block sequence binds to the sequence") func test_anchorAboveZeroIndentSequence() throws { let mapping = try requireMapping(PureYAML.parse("---\nseq:\n &anchor\n- a\n- b\n")) #expect(mapping?["seq"] == .sequence([.string("a"), .string("b")])) } /// The plain zero-indent block sequence (no property) keeps working: a sequence whose entries are /// at the mapping key's own column is the value of that key. @Test("A zero-indent block sequence without a property is unaffected") func test_zeroIndentSequenceWithoutProperty() throws { let mapping = try requireMapping(PureYAML.parse("seq:\n- a\n- b\n")) #expect(mapping?["seq"] == .sequence([.string("a"), .string("b")])) } /// A property on its own indented line above an indented nested mapping still binds to that /// mapping, so an alias resolves to the whole mapping rather than the sequence path above. @Test("An anchor above an indented nested mapping still binds to the mapping") func test_anchorAboveNestedMapping() throws { let mapping = try requireMapping(PureYAML.parse("key:\n &a\n nested: v\nx: *a\n")) let key = try requireMapping(#require(mapping?["key"])) let alias = try requireMapping(#require(mapping?["x"])) #expect(key?["nested"] == .string("v")) #expect(alias?["nested"] == .string("v")) } }