import Testing @testable import PureXML @Suite("DTD attribute validation") struct DTDAttributeTests { private func issues(_ xml: String, strict: Bool = false) throws -> [PureXML.Validation.ValidationError] { try PureXML.validateAgainstInternalDTD(xml, strict: strict) } @Test("#REQUIRED attribute must be present") func test_required() throws { let dtd = "]>" try #expect(issues("\(dtd)").isEmpty) try #expect(!issues("\(dtd)").isEmpty) } @Test("#FIXED attribute must match when present and may be omitted") func test_fixed() throws { let dtd = "]>" try #expect(issues("\(dtd)").isEmpty) try #expect(issues("\(dtd)").isEmpty) try #expect(!issues("\(dtd)").isEmpty) } @Test("Enumerated attribute must take a listed value") func test_enumeration() throws { let dtd = "]>" try #expect(issues("\(dtd)").isEmpty) try #expect(issues("\(dtd)").isEmpty) try #expect(!issues("\(dtd)").isEmpty) } @Test("Multiple attributes in one ATTLIST are each checked") func test_multipleAttributes() throws { let dtd = "]>" try #expect(issues("\(dtd)").isEmpty) // a is missing and b is out of its enumeration: two violations. try #expect(issues("\(dtd)").count == 2) } @Test("Tokenized types (ID) do not constrain the value") func test_idTypeUnconstrained() throws { let dtd = "]>" try #expect(issues("\(dtd)").isEmpty) } }