import Testing @testable import PureXML /// The Namespaces 1.0 constraints (#136): reserved prefixes and namespace /// names, qualified-name shape, duplicate expanded-name attributes, NCName /// rules for PI targets and entity/notation names, and DTD-typed /// normalization of binding values. @Suite("Namespace constraints") struct NamespaceConstraintTests { private func rejects(_ xml: String) -> Bool { (try? PureXML.parse(xml, limits: .init(allowDoctype: true))) == nil } @Test("Malformed qualified names are rejected") func test_qualifiedNameShape() { #expect(rejects("")) #expect(rejects("<:foo />")) #expect(rejects("")) #expect(rejects("")) #expect(!rejects("")) } @Test("Reserved prefixes and namespace names are protected") func test_reservedBindings() { #expect(rejects("")) #expect(!rejects("")) #expect(rejects("")) #expect(rejects("")) #expect(rejects("")) #expect(rejects("")) #expect(rejects("")) #expect(rejects("")) } @Test("A prefix may not be undeclared in Namespaces 1.0") func test_noPrefixUndeclaration() { #expect(rejects("")) #expect(!rejects("")) } @Test("Attributes must be distinct by expanded name") func test_duplicateExpandedNames() { let xml = "" #expect(rejects(xml)) let distinct = "" #expect(!rejects(distinct)) } @Test("PI targets and entity/notation names are NCNames") func test_ncNames() { #expect(rejects("\n")) #expect(rejects("]>\n")) #expect(rejects("]>\n")) } @Test("A DTD-typed xmlns value binds its normalized form") func test_typedBindingNormalization() { let xml = """ ]> """ #expect(rejects(xml)) } }