@testable import PureYAML import Testing @Suite("An inline property before the first key binds to the key, not the mapping") struct InlineKeyPropertyAnchorTests { /// A property written inline before the first key (`&k key: v`) anchors that key, so the anchor /// registers with the key and resolves early, before the enclosing mapping ends. Binding it to /// the mapping would register only at the mapping's end, too late for an alias inside a value. @Test("An inline anchor on the first key resolves from a later value") func test_inlineFirstKeyAnchorResolves() throws { let mapping = try requireMapping(PureYAML.parse("&k key: v\nx: *k\n")) #expect(mapping?["key"] == .string("v")) #expect(mapping?["x"] == .string("key")) } /// yaml-test-suite 2SXE: anchor names include `:` (a valid `ns-anchor-char`), so `&a:` and `&a` /// are distinct anchors. The alias `*a:` resolves to the `&a:`-anchored key `key`, not the /// `&a`-anchored value, and the inline anchor binds to the key rather than the whole mapping. @Test("Distinct anchor names differing only by a trailing colon resolve independently") func test_anchorNamesIncludingColon() throws { let mapping = try requireMapping(PureYAML.parse("&a: key: &a value\nfoo:\n *a:\n")) #expect(mapping?["key"] == .string("value")) #expect(mapping?["foo"] == .string("key")) } /// yaml-test-suite HMQ5: a key may carry both a tag and an anchor (`!!str &a1 "foo"`); the anchor /// registers the resolved key value so a later `*a1` comes back as that value. @Test("A first key carrying both a tag and an anchor registers for its alias") func test_inlineFirstKeyTagAndAnchor() throws { let mapping = try requireMapping(PureYAML.parse("!!str &a1 \"foo\":\n !!str bar\n&a2 baz : *a1\n")) #expect(mapping?["foo"] == .string("bar")) #expect(mapping?["baz"] == .string("foo")) } }