@testable import PureYAML import Testing @Suite("An alias node can serve as an implicit mapping key") struct AliasAsMappingKeyTests { /// yaml-test-suite E76Z: an alias may stand where a mapping key is expected (`*b : value`). The /// scanner now emits the implicit-key indicator before an alias followed by a `:`, exactly as it /// does for a scalar key, and the alias resolves to the anchored node's value. @Test("An alias followed by a value indicator is a mapping key") func test_aliasIsImplicitKey() throws { let mapping = try requireMapping(PureYAML.parse("&a a: &b b\n*b : *a\n")) #expect(mapping?["a"] == .string("b")) #expect(mapping?["b"] == .string("a")) } /// yaml-test-suite 26DV exercises an alias key nested inside a block-mapping value, where the /// alias resolves to an earlier anchored scalar and becomes that nested mapping's key. @Test("An alias key resolves inside a nested block mapping value") func test_aliasKeyInNestedMapping() throws { let root = try requireMapping(PureYAML.parse("top1: &x scalar1\ntop3:\n *x : scalar3\n")) #expect(root?["top1"] == .string("scalar1")) let nested = try requireMapping(#require(root?["top3"])) #expect(nested?["scalar1"] == .string("scalar3")) } /// A `:` written directly against an alias with no separating space is part of the alias name, /// not a value indicator (`:` is a valid anchor-name character), so the alias is not a key here. @Test("An alias with an adjacent colon keeps the colon in its name") func test_adjacentColonStaysInName() throws { let mapping = try requireMapping(PureYAML.parse("key: &a: scalar\nref: *a:\n")) #expect(mapping?["key"] == .string("scalar")) #expect(mapping?["ref"] == .string("scalar")) } }