import Testing
@testable import PureXML
@Suite("DTD located content-model errors")
struct DTDLocatedContentTests {
private func reasons(_ xml: String) throws -> [String] {
try PureXML.validateAgainstInternalDTD(xml).map(\.reason)
}
@Test("A stray child outside the model is named individually")
func test_strayChild() throws {
let dtd = "]>"
let found = try reasons("\(dtd)")
#expect(found.contains { $0.contains("") && $0.contains("not allowed in ") })
}
@Test("Two distinct stray children are each reported (recovery)")
func test_multipleStray() throws {
let dtd = "]>"
let found = try reasons("\(dtd)")
#expect(found.contains { $0.contains("") })
#expect(found.contains { $0.contains("") })
}
@Test("An ordering-only violation lists the allowed elements as a hint")
func test_orderingHint() throws {
// Both children are in the alphabet, but reversed against (a, b).
let dtd = "]>"
let found = try reasons("\(dtd)")
#expect(found.contains { $0.contains("do not match its content model") && $0.contains("") && $0.contains("") })
}
@Test("A conforming document has no content errors")
func test_valid() throws {
let dtd = "]>"
#expect(try reasons("\(dtd)").isEmpty)
}
}