require 'test/unit' require 'rubygems' require 'wunderbar' class HtmlMarkupTest < Test::Unit::TestCase def setup $x = nil # until this hack is removed html-methods.rb end def test_html x = HtmlMarkup.new x.html {} assert_equal %{\n\n}, x.target! end def test_void_element x = HtmlMarkup.new x.html {_br} assert_match %r{
}, x.target! end def test_normal_element x = HtmlMarkup.new x.html {_textarea} assert_match %r{}, x.target! end def test_script_lang x = HtmlMarkup.new x.html {_script} assert_match %r[], x.target! end def test_script_indent x = HtmlMarkup.new x.html {_script "if (i<1) {}"} assert_match %r[^ if], x.target! end def test_script_html $XHTML = false x = HtmlMarkup.new x.html {_script "if (i<1) {}"} assert_match %r[\s*if \(i<1\) \{\}\s*], x.target! end def test_script_xhtml $XHTML = true x = HtmlMarkup.new x.html {_script "if (i<1) {}"} assert_match %r[\s*if \(i<1\) \{\}\s*], x.target! end def test_disable_indent x = HtmlMarkup.new x.html {_div! {_ "one "; _strong "two"; _ " three"}} assert_match %r[
one two three
], x.target! end def test_traceback x = HtmlMarkup.new x.html {_body? {boom}} assert_match %r[#<NameError: .*boom], x.target! end def test_traceback_default_style x = HtmlMarkup.new x.html {_body? {boom}} assert_match %r[
], x.target!
  end

  def test_traceback_style_override
    x = HtmlMarkup.new
    x.html {_body?(:traceback_style => 'color:red') {boom}}
    assert_match %r[
 'traceback') {boom}}
    assert_match %r[
\s*\s*], x.target!
  end

  def test_indented_text
    x = HtmlMarkup.new
    x.html {_div {_ 'text'}}
    assert_match %r[^  
\n text\n
], x.target! end def test_unindented_text x = HtmlMarkup.new x.html {_div {_! "text\n"}} assert_match %r[^
\ntext\n
], x.target! end def test_declare x = HtmlMarkup.new x.declare! :DOCTYPE, 'html' assert_equal %{\n}, x.target! end end