class CheckHTree
Public Instance Methods
assert_xhtml(expected, template, message=nil)
click to toggle source
# File vendor/qwik/lib/qwik/check-htree.rb, line 12 def assert_xhtml(expected, template, message=nil) # from htree/test prefix = "<html\n>" suffix = "</html\n>" result = HTree.expand_template(''){"<html>#{template}</html>"} assert_match(/\A#{Regexp.quote prefix}/, result) assert_match(/#{Regexp.quote suffix}\z/, result) result = result[prefix.length..(-suffix.length-1)] ok_eq(expected, result, message) end
test_htree()
click to toggle source
# File vendor/qwik/lib/qwik/check-htree.rb, line 22 def test_htree return # do not test. assert_xhtml("<b\n>t</b\n>", '<b>t</b>') assert_xhtml("<e\n>1</e\n>", '<e _text=1>d</e>') str = '<html><e _text=1>d</e></html>' doc = HTree(str) # doc is a template assert_instance_of(HTree::Doc, doc) assert_instance_of(HTree::Elem, doc.root) ok_eq('{http://www.w3.org/1999/xhtml}html', doc.root.name) assert_instance_of(HTree::Elem, doc.root.children[0]) assert_instance_of(HTree::Elem, doc.root.children[0]) assert_instance_of(HTree::Text, doc.root.children[0].children[0]) assert_instance_of(String, doc.root.children[0].children[0].rcdata) ok_eq('d', doc.root.children[0].children[0].rcdata) doc = HTree{str} # doc is a document. the template is evaluated. assert_instance_of(HTree::Doc, doc) assert_instance_of(HTree::Elem, doc.root) assert_instance_of(HTree::Elem, doc.root.children[0]) assert_instance_of(HTree::Text, doc.root.children[0].children[0]) ok_eq('1', doc.root.children[0].children[0].rcdata) str = "<html>\n <body _text=\"body\"></body>\n</html>" body = 'b' result = HTree.expand_template(''){str} ok_eq("<html\n><body\n>b</body\n></html\n>", result) end
test_htree_to_rexml()
click to toggle source
# File vendor/qwik/lib/qwik/check-htree-rexml.rb, line 12 def test_htree_to_rexml str = '<p>あ</p>' ok_eq("\202\240", 'あ') # Kanji code is SJIS. h = HTree(str) x = '' h.display_xml(x) ok_eq("<p\n>\202\240</p\n>", x) r = h.to_rexml ok_eq("<p>\202\240</p>", r.to_s) #ok_eq(" <p>\202\240</p>", r.to_s(1)) html = <<'EOT' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head id='header'><title>新規作成</title><link href="/.theme/base.css" rel='stylesheet' media="screen,tv" type="text/css"/><link href="/.theme/qwiksystem/qwiksystem.css" rel='stylesheet' media="screen,tv" type="text/css"/><meta name='ROBOTS' content="NOINDEX,NOFOLLOW"/><meta content="0; url=FirstPage.edit" http-equiv='Refresh'/></head><body><div class='container'><div class='header'><div><div><h1 id="view_title">新規作成</h1></div></div></div><div class="update day"><div class='form'><div class='msg' id='msg'><h2>新規作成</h2><p>新規ページを作成しました</p><p><a href="FirstPage.edit">新規ページを編集</a>してください。</p><p><a href="FirstPage.edit">FirstPage.edit</a></p></div></div></div><div class="update day"><div class='comment'></div></div></div></body></html> EOT h = HTree(html) r = h.to_rexml e = <<'EOT' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns='http://www.w3.org/1999/xhtml'><head id='header'><title>新規作成</title><link href='/.theme/base.css' rel='stylesheet' type='text/css' media='screen,tv'/><link href='/.theme/qwiksystem/qwiksystem.css' rel='stylesheet' type='text/css' media='screen,tv'/><meta name='ROBOTS' content='NOINDEX,NOFOLLOW'/><meta content='0; url=FirstPage.edit' http-equiv='Refresh'/></head><body><div class='container'><div class='header'><div><div><h1 id='view_title'>新規作成</h1></div></div></div><div class='update day'><div class='form'><div class='msg' id='msg'><h2>新規作成</h2><p>新規ページを作成しました</p><p><a href='FirstPage.edit'>新規ページを編集</a>してください。</p><p><a href='FirstPage.edit'>FirstPage.edit</a></p></div></div></div><div class='update day'><div class='comment'/></div></div></body></html> EOT ok_eq(e, r.to_s) e = <<'EOT' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns='http://www.w3.org/1999/xhtml'> <head id='header'> <title>新規作成</title> <link href='/.theme/base.css' rel='stylesheet' type='text/css' media='screen,tv'/> <link href='/.theme/qwiksystem/qwiksystem.css' rel='stylesheet' type='text/css' media='screen,tv'/> <meta name='ROBOTS' content='NOINDEX,NOFOLLOW'/> <meta content='0; url=FirstPage.edit' http-equiv='Refresh'/> </head> <body> <div class='container'> <div class='header'> <div> <div> <h1 id='view_title'>新規作成</h1> </div> </div> </div> <div class='update day'> <div class='form'> <div class='msg' id='msg'> <h2>新規作成</h2> <p>新規ページを作成しました</p> <p> <a href='FirstPage.edit'>新規ページを編集</a>してください。</p> <p> <a href='FirstPage.edit'>FirstPage.edit</a> </p> </div> </div> </div> <div class='update day'> <div class='comment'/> </div> </div> </body> </html> EOT #ok_eq(e, r.to_s(0)) end