@testable import PureYAML import Testing /// The tagged validator enforces mapping-key uniqueness, the invariant the coverage manifest claims /// for `Tagged.Mapping` and `Tagged.Node`. `Tagged.Mapping` preserves every parsed pair, so a /// duplicate key survives into the tree and must be reported, exactly as in the plain model. @Suite("Tagged mapping key uniqueness") struct TaggedKeyUniquenessTests { @Test("A duplicate key in a tagged mapping is reported at the key's path") func test_reportsDuplicateTaggedKey() throws { let node = try PureYAML.parseTagged("a: 1\na: 2") #expect(PureYAML.Tagged.Validator().collect(node).values == [ .init( severity: .error, reason: "Duplicate mapping key 'a'", path: .init([.key("a")]), ), ]) #expect(throws: PureYAML.Validation.ValidationErrorCollection.self) { try PureYAML.Tagged.Validator().validate(node) } } @Test("The near miss, a tagged mapping whose keys differ by one character, passes") func test_uniqueTaggedKeysPass() throws { let node = try PureYAML.parseTagged("a: 1\nb: 2") _ = try PureYAML.Tagged.Validator().validate(node) } @Test("A duplicate key nested under a tag is reported at its nested path") func test_reportsNestedDuplicateTaggedKey() throws { let node = try PureYAML.parseTagged("outer:\n a: 1\n a: 2") #expect(PureYAML.Tagged.Validator().collect(node).values == [ .init( severity: .error, reason: "Duplicate mapping key 'a'", path: .init([.key("outer"), .key("a")]), ), ]) } @Test("The default tagged validator runs exactly its two built-in checks") func test_defaultTaggedCheckDescriptions() { #expect(PureYAML.Tagged.Validator().validationDescriptions == [ "Built-in tags are supported and kind-consistent", "Mapping keys are unique", ]) } }