test suite test markup grammar
implicit import idealruntimetextstext library
import idealmachinecharactersunicode handler
import idealmachinechannelsstring writer
var string error message
markup grammar make grammar()
grammar : markup grammar • new(unicode handlerinstance)
grammarcomplete()
return grammar
test case test entity ref()
assert entity ref("<")
assert entity ref("&")
assert entity ref("•")
assert !entity ref("foo")
assert !entity ref("&foo")
assert !entity ref("foo;")
assert entity refparse("<") == LT
assert entity refparse(">") == GT
assert entity refparse("'") == APOS
assert entity refparse(""") == QUOT
assert entity refparse("—") == MDASH
assert entity refparse(" ") == NBSP
test case test attribute value()
assert quot attr value("foo")
assert quot attr value("*bar*")
assert quot attr value("'baz'")
assert !quot attr value("<")
assert !quot attr value("\"a")
assert apos attr value("foo")
assert apos attr value("*bar*")
assert apos attr value("\"baz\"")
assert !apos attr value("<")
assert !apos attr value("'a")
assert attribute value in quotparse("\"\"") • to string == ""
assert attribute value in quotparse("\"foo\"") • to string == "foo"
assert attribute value in quotparse("\"<\"") • to string == "<"
assert attribute value in quotparse("\"foo<bar\"") • to string == "foo<bar"
assert attribute value in quotparse("\""-'\"") • to string == ""-'"
assert attribute value in quotparse("\"<foo>bar'baz\"") • to string == "<foo>bar'baz"
assert attribute value in aposparse("''") • to string == ""
assert attribute value in aposparse("'foo'") • to string == "foo"
assert attribute value in aposparse("'<'") • to string == "<"
assert attribute value in aposparse("'foo<bar'") • to string == "foo<bar"
assert attribute value in aposparse("'"-''") • to string == ""-'"
assert attribute value in aposparse("'<foo>bar\"baz'") • to string == "<foo>bar\"baz"
test case test attribute()
assert attribute("id = '68'")
assert attribute("href = \"https://theideal.org/\"")
assert attribute("clear='all'")
assert !attribute("<html>")
assert !attribute("foo")
assert !attribute("bar =")
assert !attribute("&lt;name&gt; = 'value'")
attribute0 : attributeparse("id = '68'")
assert attribute0id == text libraryID
assert (attribute0value !> string) == "68"
attribute1 : attributeparse("href = \"https://theideal.org/\"")
assert attribute1id == text libraryHREF
assert (attribute1value !> string) == "https://theideal.org/"
test case test empty element()
assert empty element("<html/>")
assert empty element("<body class=\"foo\" />")
assert !empty element("<html>")
assert !empty element("bar")
assert !empty element("&lt;html&gt;")
element0 : empty elementparse("<html/>")
assert element0get id == text libraryHTML
assert element0children is null
assert element0attributesis empty
element1 : empty elementparse("<body class=\"foo\" />")
assert element1get id == text libraryBODY
assert element1children is null
assert element1attributessize == 1
assert element1attributeselements[0] • key == text libraryCLASS
assert element1attributeselements[0] • value == "foo"
element2 : empty elementparse("<a class='foo' href='https://theideal.org/'/>")
assert element2get id == text libraryA
assert element2children is null
assert element2attributessize == 2
attributes : element2attributeselements
assert attributes[0] • key == text libraryCLASS
assert attributes[0] • value == "foo"
assert attributes[1] • key == text libraryHREF
assert attributes[1] • value == "https://theideal.org/"
test case test content()
assert content(" hello, world!")
assert content("&lt;html&gt;")
assert !content("<bar>")
test case test simple parse()
assert document matcher("<html>foo</html>")
assert document matcher(" <html>foo</html> ")
assert document matcher(" <html >foo</html > ")
assert document matcher(" <html >Hello &amp; goodbye!</html > ")
assert document matcher(" <html /> ")
assert document matcher("<html/>")
assert document matcher(" <html>Hello <em>world!</em></html> ")
assert document matcher(" <html><body ><p>Hello <em >world!</em ></p></body ></html> ")
assert document matcher(" <html><body > <p>Hello<br />world!</p> </body ></html> ")
assert document matcher(" <html><body > Hello &lt;world!&gt; </body ></html> ")
assert document matcher("<html><p class='klass'>foo</p></html>")
assert document matcher("<html><a class = 'klass' href = 'link'>bar</a></html>")
assert document matcher("<html><p class = 'value\">==' attr=\"foo'\">foo</p></html>")
assert document matcher("<html><p class = '***' attr=\"baz\">foo</p></html>")
assert !document matcher(" no markup ")
assert !document matcher(" <html>foo ")
assert !document matcher(" <html>foo<bar> ")
assert !document matcher(" <>foo ")
assert !document matcher(" &amp;<html>foo</html> ")
assert !document matcher("<html><p class='klass\">foo</p></html>")
assert !document matcher("<html><p class='klass'>foo</p class=\"foo\"></html>")
assert !document matcher("<html foo= ><p class='klass'>foo</p></html>")
assert !document matcher("<html foo=bar><p class='klass'>foo</p></html>")
assert document matcher(" <abc>foo</def> ")
assert matches(document matcherparse(" <html>foo</html> "), "<html>foo</html>")
assert matches(document matcherparse(" <html >Hello &amp; goodbye!</html > "), "<html>Hello &amp; goodbye!</html>")
assert matches(document matcherparse(" <html /> "), "<html />")
assert matches(document matcherparse(" <html>Hello <em>world!</em></html> "), "<html>Hello <em>world!</em></html>")
assert matches(document matcherparse(" <html><body > <p>Hello<br />world!</p> </body ></html> "), "<html><body> <p>Hello<br />world!</p> </body></html>")
assert matches(document matcherparse("<html><p class='klass'>foo</p></html>"), "<html><p class='klass'>foo</p></html>")
assert matches(document matcherparse("<html><p id='f&amp;f'>foo</p></html>"), "<html><p id='f&amp;f'>foo</p></html>")
assert matches(document matcherparse("<html><a class = 'klass' href = 'link'>bar</a></html>"), "<html><a class='klass' href='link'>bar</a></html>")
assert matches(document matcherparse("<html><p class = 'value\">==' id=\"foo'\">foo</p></html>"), "<html><p class='value&quot;&gt;==' id='foo&apos;'>foo</p></html>")
assert matches(document matcherparse("<html><p class = '***' id=\"baz\">foo</p></html>"), "<html><p class='***' id='baz'>foo</p></html>")
test case test parse errors()
parser : markup parser • new(grammar, report error)
assert matches with error(parserparse("<html>&bug;</html>"), "<html>&_error_;</html>", "Unrecognized entity: bug")
assert matches with error(parserparse("<html><foo>Hello!</foo></html>"), "<html><_error_>Hello!</_error_></html>", "Unrecognized element name: foo")
assert matches with error(parserparse("<html><b attr=\"value\">Hello!</b></html>"), "<html><b _error_='value'>Hello!</b></html>", "Unrecognized attribute name: attr")
assert matches with error(parserparse("<html><a>Hello!</b></html>"), "<html><a>Hello!</a></html>", "Mismatched element name: start a, end b")
private void report error(string error message)
this • error message = error message
private boolean matches with error(text element the text element, string expected, string expected error)
return matches(the text element, expected) && error message == expected error
private boolean matches(text element the text element, string expected)
the writer : string writer • new()
the formatter : markup formatter • new(the writer, "", false)
the formatterwrite(the text element)
return the writerelements() == expected