#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/html2haml/erb_tests' require 'haml/html' class Html2HamlTest < Test::Unit::TestCase def test_empty_render_should_remain_empty assert_equal '', render('') end def test_id_and_class_should_be_removed_from_hash assert_equal '%span#foo.bar', render('
') end def test_no_tag_name_for_div_if_class_or_id_is_present assert_equal '#foo', render('
foo
")) end def test_inline_comment assert_equal("/ foo", render("")) end def test_non_inline_comment assert_equal(<foo
bar
baz
HTML
end
def test_code_without_pre
assert_equal(<- foo bar -
")) end def test_equals_in_tag assert_equal("%p = foo bar =", render("= foo bar =
")) end def test_hash_in_tag assert_equal("%p # foo bar #", render("# foo bar #
")) end begin require 'haml/html/erb' include ErbTests rescue LoadError => e puts "\n** Couldn't require #{e.message[/-- (.*)$/, 1]}, skipping some tests" end # Encodings unless Haml::Util.ruby1_8? def test_encoding_error render("foo\nbar\nb\xFEaz".force_encoding("utf-8")) assert(false, "Expected exception") rescue Haml::Error => e assert_equal(3, e.line) assert_equal('Invalid UTF-8 character "\xFE"', e.message) end def test_ascii_incompatible_encoding_error template = "foo\nbar\nb_z".encode("utf-16le") template[9] = "\xFE".force_encoding("utf-16le") render(template) assert(false, "Expected exception") rescue Haml::Error => e assert_equal(3, e.line) assert_equal('Invalid UTF-16LE character "\xFE"', e.message) end end protected def render(text, options = {}) Haml::HTML.new(text, options).render.rstrip end def render_erb(text) render(text, :erb => true) end end