import Testing
@testable import PureXML
/// cvc-identity-constraint.3 / c-fields-xpaths: an identity-constraint field must
/// identify a node with a simple type (a simple-typed element, an element with simple
/// content, or an attribute). A field whose target is a complex type with non-simple
/// content is invalid, whether the instance node has element children (idK012) or is
/// empty/attributes-only (idG006). A simple or simpleContent target stays valid.
@Suite("XSD identity-constraint field simple-content")
struct SchemaIdentityFieldTypeTests {
private func validate(_ xsd: String, _ xml: String) throws -> [PureXML.Validation.ValidationError] {
try PureXML.Schema.Document(xsd).validate(xml)
}
private let head = ""
@Test("a field selecting a complex-content element is rejected (idK012)")
func test_fieldWithElementChildrenRejected() throws {
let complexField = """
\(head)
"""
#expect(try !validate(complexField, "x").isEmpty)
let simpleField = """
\(head)
"""
#expect(try validate(simpleField, "ab").isEmpty)
}
@Test("a field whose declared type is an empty/attributes-only complex type is rejected (idG006)")
func test_emptyComplexFieldRejected() throws {
let emptyComplex = """
\(head)
"""
#expect(try !validate(emptyComplex, "").isEmpty)
let simpleContent = """
\(head)
"""
#expect(try validate(simpleContent, "a").isEmpty)
}
}