require 'test/unit' require 'rubygems' require 'wunderbar' class HtmlMarkupTest < Test::Unit::TestCase def setup @original_log_level = Wunderbar.logger.level Wunderbar.log_level = :fatal end def teardown Wunderbar.logger.level = @original_log_level 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_spaced_embedded x = HtmlMarkup.new x.html {_div {_p 'one'; _hr_; _p 'two'}} assert_match %r[
\n +

one

\n\n +
\n\n +

two

\n +
], x.target! end def test_spaced_collapsed x = HtmlMarkup.new x.html {_div {_p_ 'one'; _hr_; _p_ 'two'}} assert_match %r[
\n +

one

\n\n +
\n\n +

two

\n +
], 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_nil_attribute
    x = HtmlMarkup.new
    x.html {_div :class => nil}
    assert_match %r[^  
], x.target! end def test_class_attribute x = HtmlMarkup.new x.html {_div.header {_span.text 'foo'}} assert_match %r[
.*
]m, x.target! end def test_id_attribute x = HtmlMarkup.new x.html {_h1.content! 'Content'} assert_match %r[^

Content

], x.target! end def test_boolean_attribute_false x = HtmlMarkup.new x.html {_option :selected => false} assert_match %r[^ ], x.target! end def test_boolean_attribute_true x = HtmlMarkup.new x.html {_option :selected => true} assert_match %r[^ ], 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 def test_comment x = HtmlMarkup.new x._.comment 'foo' assert_equal %{\n}, x.target! end def test_svg x = HtmlMarkup.new x.html {_svg} assert_match %r[^ ], x.target! end def test_math x = HtmlMarkup.new x.html {_math} assert_match %r[^ ], x.target! end begin require 'coffee-script' def test_coffeescript x = HtmlMarkup.new x.html {_coffeescript 'alert "foo"'} assert_match %r[\s+\(function\(\)\s \{\s+alert\("foo"\);\s+\}\).call\(this\);\s+]x, x.target! end rescue LoadError end end