class TestHTreeToWabisabi

Public Instance Methods

ok(e, htree) click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 98
def ok(e, htree)
  ok_eq(e, htree.to_wabisabi)
end
ok_ht(e, str) click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 94
def ok_ht(e, str)
  ok_eq(e, HTree(str).to_wabisabi)
end
test_bogustag() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 166
def test_bogustag
  ok([[:p, 't']], HTree('<p>t</p>'))
  ok([[:p, 't'], ''], HTree('<p>t</p></p>'))
end
test_comment() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 159
def test_comment
  ok_ht([[:'!--', 'c']], '<!--c-->')
  e = HTree::Comment.new('a')
  ok_eq('a', e.content)
  ok([:'!--', 'a'], e)
end
test_doc() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 102
def test_doc
  ok([[:'!DOCTYPE', 'html', 'PUBLIC',
         '-//W3C//DTD html 4.01 Transitional//EN',
         'http://www.w3.org/TR/html4/loose.dtd'],
       [:html, [:head, [:title, 't']], [:body, [:p, 'b']]]],
     HTree('<!DOCTYPE HTML PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>t</title></head><body><p>b</p></body></html>'))

  e = HTree::Elem.new('a')
  doc = HTree::Doc.new(e)
  ok_eq('#<HTree::Doc {emptyelem <a>}>', doc.inspect)
  ok([[:a]], doc)
end
test_doctype() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 124
    def test_doctype
      ok_ht([[:'!DOCTYPE', 'html', 'PUBLIC',
                 '-//W3C//DTD html 4.01 Transitional//EN',
                 'http://www.w3.org/TR/html4/loose.dtd']],
             '<!DOCTYPE HTML PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">')

      e = HTree::DocType.new('HTML', '-//W3C//DTD html 4.01 Transitional//EN',
                             'http://www.w3.org/TR/html4/loose.dtd')
#     ok_eq('{doctype <!DOCTYPE HTML PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">}', e.inspect)
      ok_eq("PUBLIC \"-//W3C//DTD html 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"", e.generate_content)
      ok([:'!DOCTYPE', 'HTML', 'PUBLIC',
           '-//W3C//DTD html 4.01 Transitional//EN',
           'http://www.w3.org/TR/html4/loose.dtd'], e)
    end
test_node() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 139
def test_node
  ok_ht([[:a]], '<a/>')
  ok_ht([[:a]], '<a></a>')
  ok_ht([[:a, [:b]]], '<a><b/></a>')
  ok_ht([[:a, {:href=>'foo.html'}]], "<a href='foo.html'></a>")

  e = HTree::Elem.new('a')
  ok([:a], e)       # test_elem
  e = HTree::Elem.new('b', e)       # test_elem_with_elem
  ok([:b, [:a]], e)
  e = HTree::Elem.new('a', {'href'=>'foo.html'})    # test_elem_with_attr
  ok([:a, {:href=>'foo.html'}], e)
end
test_text() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 153
def test_text
  ok_ht(['a'], 'a')
  e = HTree::Text.new('a')
  ok('a', e)
end
test_xmldecl() click to toggle source
# File vendor/qwik/lib/qwik/htree-to-wabisabi.rb, line 115
def test_xmldecl
  ok_ht([[:'?xml', '1.0', 'utf-8']],
        '<?xml version="1.0" encoding="utf-8"?>')

  e = HTree::XMLDecl.new('1.0', 'utf-8')
  ok_eq('{xmldecl }', e.inspect)
  ok([:'?xml', '1.0', 'utf-8'], e)
end