dymokomi/luce-xml
Source of release 0.3.0
0.3.0 / tests / xml / text.lucb
#==============================================================================================
#
# tests/xml/text - Character data, references and line ends
#
#==============================================================================================
test "the predefined entities and character references":
try expect_record("<a><>&'" AB😀</a>", "<a><>&'\" AB\u{1F600}</a>")
test "text around markup arrives in single runs":
var recorder = Recorder()
defer recorder.release()
var parser = Parser()
defer parser.release()
var counter = TextCounter()
try parser.parse("<a>one & two<b/>three!</a>".bytes, &counter)
assert(counter.texts == 2)
test "line ends are normalised":
try expect_record("<a>x\r\ny\rz\n</a>", "<a>x y z </a>")
try expect_record("<a b='1\r\n2'/>", "<a b=\"1 2\"/></a>")
test "a character reference to CR survives normalisation":
try expect_record("<a> </a>", "<a> </a>")
test "']]>' is not allowed in text":
try expect_failure("<a>x]]>y</a>", "']]>' in text")
test "a bare ampersand is an error":
try expect_failure("<a>fish & chips</a>", "'&' must begin a reference")
test "a reference to a character that is not XML":
try expect_failure("<a>�</a>", "does not refer to an XML character")
try expect_failure("<a>�</a>", "does not refer to an XML character")
try expect_failure("<a>A</a>", "expected digits")
test "control characters and bad UTF-8 are errors":
try expect_failure("<a>\u{1}</a>", "control character")
try expect_failure("<a>\u{FFFE}</a>", "#xfffe")
test "comments may not contain two hyphens":
try expect_failure("<a><!-- a -- b --></a>", "'--' inside a comment")
try expect_failure("<a><!-- a ---></a>", "'--' inside a comment")
test "processing instructions":
try expect_record("<a><?target some data ?></a>", "<a><?target some data ?></a>")
try expect_failure("<a><?xml version='1.0'?></a>", "very start")
try expect_failure("<a><?XmL x?></a>", "reserved")
## Counts `text` events.
struct TextCounter: Listener:
var texts: usize = 0
pub func event(event: Event) -> !:
match event:
.text(text):
_ = text
self.texts += 1
_:
return
pub func resolve(request: const EntityRequest*) -> const u8[]?:
_ = request
return none