class test markup grammar
implicit import ideal • runtime • texts • text library
import ideal • machine • characters • normal handler
import ideal • machine • channels • string writer
var string error message
markup grammar make grammar()
grammar : markup grammar • new(normal handler • instance)
grammar • complete()
return grammar
testcase 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 ref • parse("<") == LT
assert entity ref • parse(">") == GT
assert entity ref • parse("'") == APOS
assert entity ref • parse(""") == QUOT
assert entity ref • parse("—") == MDASH
assert entity ref • parse(" ") == NBSP
testcase 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 quot • parse("\"\"") • to string == ""
assert attribute value in quot • parse("\"foo\"") • to string == "foo"
assert attribute value in quot • parse("\"<\"") • to string == "<"
assert attribute value in quot • parse("\"foo<bar\"") • to string == "foo<bar"
assert attribute value in quot • parse("\""-'\"") • to string == ""-'"
assert attribute value in quot • parse("\"<foo>bar'baz\"") • to string == "<foo>bar'baz"
assert attribute value in apos • parse("''") • to string == ""
assert attribute value in apos • parse("'foo'") • to string == "foo"
assert attribute value in apos • parse("'<'") • to string == "<"
assert attribute value in apos • parse("'foo<bar'") • to string == "foo<bar"
assert attribute value in apos • parse("'"-''") • to string == ""-'"
assert attribute value in apos • parse("'<foo>bar\"baz'") • to string == "<foo>bar\"baz"
testcase 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 : attribute • parse("id = '68'")
assert attribute0 • id == text library • ID
assert (attribute0 • value !> string) == "68"
attribute1 : attribute • parse("href = \"https://theideal.org/\"")
assert attribute1 • id == text library • HREF
assert (attribute1 • value !> string) == "https://theideal.org/"
testcase 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 element • parse("<html/>")
assert element0 • get id == text library • HTML
assert element0 • children is null
assert element0 • attributes • is empty
element1 : empty element • parse("<body class=\"foo\" />")
assert element1 • get id == text library • BODY
assert element1 • children is null
assert element1 • attributes • size == 1
assert element1 • attributes • elements[0] • key == text library • CLASS
assert element1 • attributes • elements[0] • value !> base string == "foo"
element2 : empty element • parse("<a class='foo' href='https://theideal.org/'/>")
assert element2 • get id == text library • A
assert element2 • children is null
assert element2 • attributes • size == 2
attributes : element2 • attributes • elements
assert attributes[0] • key == text library • CLASS
assert attributes[0] • value !> base string == "foo"
assert attributes[1] • key == text library • HREF
assert attributes[1] • value !> base string == "https://theideal.org/"
testcase test content()
assert content(" hello, world!")
assert content("&lt;html&gt;")
assert !content("<bar>")
testcase 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 matcher • parse(" <html>foo</html> "), "<html>foo</html>")
assert matches(document matcher • parse(" <html >Hello &amp; goodbye!</html > "), "<html>Hello &amp; goodbye!</html>")
assert matches(document matcher • parse(" <html /> "), "<html />")
assert matches(document matcher • parse(" <html>Hello <em>world!</em></html> "), "<html>Hello <em>world!</em></html>")
assert matches(document matcher • parse(" <html><body > <p>Hello<br />world!</p> </body ></html> "), "<html><body> <p>Hello<br />world!</p> </body></html>")
assert matches(document matcher • parse("<html><p class='klass'>foo</p></html>"), "<html><p class='klass'>foo</p></html>")
assert matches(document matcher • parse("<html><p id='f&amp;f'>foo</p></html>"), "<html><p id='f&amp;f'>foo</p></html>")
assert matches(document matcher • parse("<html><a class = 'klass' href = 'link'>bar</a></html>"), "<html><a class='klass' href='link'>bar</a></html>")
assert matches(document matcher • parse("<html><p class = 'value\">==' id=\"foo'\">foo</p></html>"), "<html><p class='value&quot;&gt;==' id='foo&apos;'>foo</p></html>")
assert matches(document matcher • parse("<html><p class = '***' id=\"baz\">foo</p></html>"), "<html><p class='***' id='baz'>foo</p></html>")
testcase test parse errors()
parser : markup parser • new(grammar, report error)
assert matches with error(parser • parse("<html>&bug;</html>"), "<html>&_error_;</html>", "Unrecognized entity: bug")
assert matches with error(parser • parse("<html><foo>Hello!</foo></html>"), "<html><_error_>Hello!</_error_></html>", "Unrecognized element name: foo")
assert matches with error(parser • parse("<html><b attr=\"value\">Hello!</b></html>"), "<html><b _error_='value'>Hello!</b></html>", "Unrecognized attribute name: attr")
assert matches with error(parser • parse("<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 formatter • write(the text element)
return the writer • elements() == expected