A complexType with mixed="true" and no sequence/choice/all (only attributes) was compiled to the empty content type, which forbids text, so a mixed element carrying only character data was rejected. It is now mixed content over an empty particle: text is permitted, child elements are still disallowed. Non-mixed empty types are unchanged. XSTS: valid instances rejected 311 to 308. Baseline updated; regression tests cover text accepted, an empty element, a child element rejected, and the non-mixed control still rejecting text. Refs #147, #129.
35 lines
1.4 KiB
Swift
35 lines
1.4 KiB
Swift
@testable import PureXML
|
|
import Testing
|
|
|
|
/// A `mixed="true"` complex type with no content model (only attributes) still
|
|
/// permits character data: it is mixed content over an empty particle, not the
|
|
/// empty content type, which forbids text (#147, XSTS attgD set). Child elements
|
|
/// are still not allowed, and a non-mixed empty type still rejects text.
|
|
@Suite("Mixed content with no element model")
|
|
struct SchemaMixedEmptyTests {
|
|
private func schema(mixed: Bool) throws -> PureXML.Schema.Document {
|
|
try PureXML.Schema.Document("""
|
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
<xs:element name="doc">
|
|
<xs:complexType\(mixed ? " mixed=\"true\"" : "")>
|
|
<xs:attribute name="a" type="xs:string"/>
|
|
</xs:complexType>
|
|
</xs:element>
|
|
</xs:schema>
|
|
""")
|
|
}
|
|
|
|
@Test("A mixed empty type permits text and stays empty of elements")
|
|
func test_mixedAllowsText() throws {
|
|
let doc = try schema(mixed: true)
|
|
#expect(try doc.validate(#"<doc a="x">hello</doc>"#).isEmpty) // text allowed
|
|
#expect(try doc.validate(#"<doc a="x"/>"#).isEmpty) // empty allowed
|
|
#expect(try !doc.validate(#"<doc a="x"><child/></doc>"#).isEmpty) // no element content
|
|
}
|
|
|
|
@Test("A non-mixed empty type still rejects text")
|
|
func test_nonMixedRejectsText() throws {
|
|
#expect(try !schema(mixed: false).validate(#"<doc a="x">hello</doc>"#).isEmpty)
|
|
}
|
|
}
|