import Testing @testable import PureXML @Suite("Catalog suffix entries and prefer attribute") struct CatalogSuffixPreferTests { @Test("systemSuffix resolves by longest matching suffix") func test_systemSuffix() throws { let catalog = """ """ let resolver = try PureXML.Catalog.Resolver(catalog) #expect(resolver.resolveSystem("http://x/foo.dtd") == "generic.dtd") // The longer matching suffix wins. #expect(resolver.resolveSystem("http://x/docbook.dtd") == "docbook.dtd") #expect(resolver.resolveSystem("http://x/foo.xsd") == nil) } @Test("uriSuffix resolves a URI name by suffix") func test_uriSuffix() throws { let catalog = """ """ let resolver = try PureXML.Catalog.Resolver(catalog) #expect(resolver.resolveURI("http://x/types.xsd") == "schema.xsd") #expect(resolver.resolveURI("http://x/types.dtd") == nil) } @Test("An exact system entry still wins over a suffix") func test_exactBeatsSuffix() throws { let catalog = """ """ let resolver = try PureXML.Catalog.Resolver(catalog) #expect(resolver.resolveSystem("http://x/foo.dtd") == "exact.dtd") } @Test("prefer=public falls back to a public entry when the system id is unmatched") func test_preferPublic() throws { let catalog = """ """ let resolver = try PureXML.Catalog.Resolver(catalog) let resolved = resolver.resolveExternalIdentifier(publicID: "-//X//DTD//EN", systemID: "http://x/unmatched.dtd") #expect(resolved == "bypublic.dtd") } @Test("prefer=system does not fall back to public when a system id is present") func test_preferSystem() throws { let catalog = """ """ let resolver = try PureXML.Catalog.Resolver(catalog) // A system id is present but unmatched, and prefer=system, so no fallback. #expect(resolver.resolveExternalIdentifier(publicID: "-//X//DTD//EN", systemID: "http://x/unmatched.dtd") == nil) // With no system id, the public entry is still used. #expect(resolver.resolveExternalIdentifier(publicID: "-//X//DTD//EN", systemID: nil) == "bypublic.dtd") } }