import Testing
@testable import PureXML
/// The strict internal-subset profile (#128): under
/// `Limits(strictInternalSubset: true)` the internal DTD subset is held to
/// the letter of XML 1.0, rejecting conditional sections and parameter-entity
/// references inside markup declarations, both of which PureXML otherwise
/// supports as features. Defaults are unchanged.
@Suite("Strict internal-subset profile")
struct StrictSubsetProfileTests {
private let strict = PureXML.Parsing.Limits(allowDoctype: true, strictInternalSubset: true)
private let lenient = PureXML.Parsing.Limits(allowDoctype: true)
private func parses(_ xml: String, _ limits: PureXML.Parsing.Limits) -> Bool {
(try? PureXML.parse(xml, limits: limits)) != nil
}
@Test("Conditional sections in the internal subset reject under the profile only")
func test_conditionalSections() {
let xml = "\n]>\n"
#expect(!parses(xml, strict))
#expect(parses(xml, lenient))
}
@Test("PE references inside declarations reject under the profile only")
func test_referencesInDeclarations() {
let inEntityValue = "]>\n"
let inContentModel = "]>\n"
let inPEValue = "]>\n"
let inAttList = "]>\n"
for xml in [inEntityValue, inContentModel, inPEValue, inAttList] {
#expect(!parses(xml, strict))
#expect(parses(xml, lenient))
}
}
@Test("DeclSep references and quoted defaults stay legal under the profile")
func test_legalShapesUnaffected() {
// A bare %pe; between declarations is production 28a DeclSep.
let declSep = "\">%pe;]>\n"
#expect(parses(declSep, strict))
// '%e;' inside a quoted default is an AttValue: literal text.
let quotedDefault = "]>\n"
#expect(parses(quotedDefault, strict))
}
}