import Testing @testable import PureXML @Suite("XSD value constraint valid against a user type (e-props-correct.2 / a-props-correct.2)") struct SchemaUserTypeValueConstraintTests { private let xsd = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" private func compiles(_ body: String) -> Bool { (try? PureXML.Schema.Document("\(body)")) != nil } @Test("A default invalid against a named simpleType's pattern is rejected") func test_namedSimpleTypePatternRejected() { #expect(!compiles( "" + "" + "", )) } @Test("A fixed invalid for a named simpleType restricting a built-in is rejected") func test_namedSimpleTypeLexicalRejected() { #expect(!compiles( "" + "", )) } @Test("A fixed invalid against a complexType's simpleContent base is rejected") func test_simpleContentExtensionRejected() { #expect(!compiles( "" + "" + "" + "", )) } @Test("A value valid for its user type compiles") func test_validValueAccepted() { // Matches the pattern. #expect(compiles( "" + "" + "", )) // Valid float. #expect(compiles( "" + "", )) // Valid against the simpleContent base. #expect(compiles( "" + "" + "", )) } /// A value valid for one of a union's member types must compile: the compiled /// `SimpleType` validator admits any member, so no special-casing is needed. @Test("A value valid for a union member compiles") func test_unionMemberAccepted() { #expect(compiles( "" + "", )) } /// A restriction whose base is an inline `` list must preserve the /// list variety, so a `length` facet counts items and a list-valued default of /// the right length is valid. Reading the base only from the `base` attribute /// dropped the inline list, made the type an atomic string, and counted /// characters, wrongly rejecting this schema. @Test("A list-valued default on an inline-list-base restriction compiles") func test_inlineListBaseRestrictionAccepted() { #expect(compiles( "" + "" + "" + "", )) // The same type with a list of the wrong length is still correctly rejected. #expect(!compiles( "" + "" + "" + "", )) } }