@testable import PureYAML import Testing @Suite("Anchor on a null or typed value resolves through its alias") struct AnchorOnNullValueTests { /// An anchor on a `key:` with no value anchors that key's implicit null node, so a later alias /// resolves to null rather than failing as undefined (yaml-test-suite 6KGN). The empty value is /// followed by a sibling mapping key, which must not be absorbed as a nested mapping. @Test("An anchor on an empty mapping value registers a null node for its alias") func test_anchorOnEmptyValueResolvesToNull() throws { let value = try PureYAML.parse("a: &anchor\nb: *anchor\n") let mapping = try requireMapping(value) #expect(mapping?["a"] == .null) #expect(mapping?["b"] == .null) } /// The anchored node is resolved before registration, so a typed scalar anchors its typed value /// (here an integer), not its raw text: the alias must come back as the same `.int(42)`. @Test("An anchor on a typed scalar registers the resolved value, not its raw text") func test_anchorOnTypedScalarResolvesToTypedValue() throws { let value = try PureYAML.parse("a: &a 42\nb: *a\n") let mapping = try requireMapping(value) #expect(mapping?["a"] == .int(42)) #expect(mapping?["b"] == .int(42)) } }