class TestHTreeGenerator

Public Instance Methods

ok(e, s) click to toggle source
# File vendor/qwik/lib/qwik/htree-generator.rb, line 82
def ok(e, s)
  ok_eq(e, s.format_xml)
end
test_all() click to toggle source
# File vendor/qwik/lib/qwik/htree-generator.rb, line 86
def test_all
  g = HTree::Generator.new

  # test_htree_generator
  ok("<p/>", g.p)
  doc = HTree::Doc.new(g.p)
  ok("<p/>", doc)
  str = ''
  doc.display_xml(str)
  ok_eq("<p\n/>", str)

  ok("<a/>", g.a)
  ok("<b/>", g.b{})
  ok("<b></b>", g.b{''})
  ok('<img src='u'/>', g.img(:src=>'u'))
  ok("<b>t</b>", g.b{'t'})
  ok("<p><b>b</b></p>", g.p{g.b{'b'}})
  ok("<p>t<p>b</p>t</p>", g.p{['t', g.p{'b'}, 't']})
  ok('<a href='u'>t</a>', g.a(:href=>'u'){'t'})
  ok('<font size='7'>t</font>', g.font(:size => 7){'t'})

  # test_namespace
  ok("<b>t</b>", g.make('b'){'t'})
  ok("<n:b>t</n:b>", g.make("n:b"){'t'})
  ok('<a href='u'>t</a>', g.make('a', :href=>'u'){'t'})

  html = g.html {[
      g.head {[
          g.title {"タイトル"},
        ]},
      g.body {[
          g.pre {[g.b {'world'},  'hello']},
          g.pre {['This is ', g.b{'bold'}, ' text.']},
          g.pre {['This is ', g.i{'italic'}, ' text.']},
          g.p {['This is ', g.a(:href=>'hoge'){'anchor'}, ' text.']},
        ]}
    ]}
  ok("<html><head><title>タイトル</title></head><body><pre><b>world</b>hello</pre><pre>This is <b>bold</b> text.</pre><pre>This is <i>italic</i> text.</pre><p>This is <a href=\"hoge\">anchor</a> text.</p></body></html>", html)

  # test_with_underbar
  ok("<ab/>", g.ab)
  ok("<a-b/>", g.a_b)
  ok("<a-b/>", g.make("a_b"))
  ok("<a-b/>", g.make("a-b"))

  # test_ordered_hash
  ok("<a b=\"c\"/>", g.a({'b'=>'c'}))
  ok("<a b=\"c\"/>", g.a([{'b'=>'c'}]))
  ok("<a b=\"c\" d=\"e\"/>", g.a([{'b'=>'c'}, {'d'=>'e'}]))
  ok("<a b=\"c\" d=\"e\"/>", g.a({'b'=>'c'}, {'d'=>'e'}))

  # test_multi_attr
  ok("<a href=\"h\" class=\"c\"/>",
     g.make('a', {:href=>'h'}, {:class=>'c'}))
  ok("<a class=\"c\" href=\"h\"/>",
     g.make('a', {:class=>'c'}, {:href=>'h'}))
end