PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/haml-2.0.3/test/haml/html2haml_test.rb

https://github.com/technicalpickles/flockup
Ruby | 59 lines | 46 code | 12 blank | 1 comment | 0 complexity | 1962169670e2036a034f9ff784e5a252 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env ruby
  2. require File.dirname(__FILE__) + '/../test_helper'
  3. require 'haml/html'
  4. class Html2HamlTest < Test::Unit::TestCase
  5. def test_empty_render_should_remain_empty
  6. assert_equal '', render('')
  7. end
  8. def test_id_and_class_should_be_removed_from_hash
  9. assert_equal '%span#foo.bar', render('<span id="foo" class="bar"> </span>')
  10. end
  11. def test_no_tag_name_for_div_if_class_or_id_is_present
  12. assert_equal '#foo', render('<div id="foo"> </div>')
  13. assert_equal '.foo', render('<div class="foo"> </div>')
  14. end
  15. def test_multiple_class_names
  16. assert_equal '.foo.bar.baz', render('<div class=" foo bar baz "> </div>')
  17. end
  18. def test_should_have_pretty_attributes
  19. assert_equal_attributes('%input{ :type => "text", :name => "login" }/',
  20. render('<input type="text" name="login" />'))
  21. assert_equal_attributes('%meta{ "http-equiv" => "Content-Type", :content => "text/html" }/',
  22. render('<meta http-equiv="Content-Type" content="text/html" />'))
  23. assert_equal_attributes('%div{ "xml:lang" => "hr" }/',
  24. render('<div xml:lang="hr" />'))
  25. end
  26. def test_sqml_comment
  27. assert_equal "/\n IE sucks", render('<!-- IE sucks -->')
  28. end
  29. def test_rhtml
  30. assert_equal '- foo = bar', render_rhtml('<% foo = bar %>')
  31. assert_equal '- foo = bar', render_rhtml('<% foo = bar -%>')
  32. assert_equal '= h @item.title', render_rhtml('<%=h @item.title %>')
  33. assert_equal '= h @item.title', render_rhtml('<%=h @item.title -%>')
  34. end
  35. protected
  36. def render(text, options = {})
  37. Haml::HTML.new(text, options).render.rstrip
  38. end
  39. def render_rhtml(text)
  40. render(text, :rhtml => true)
  41. end
  42. def assert_equal_attributes(expected, result)
  43. expected_attr, result_attr = [expected, result].map { |s| s.gsub!(/\{ (.+) \}/, ''); $1.split(', ').sort }
  44. assert_equal expected_attr, result_attr
  45. assert_equal expected, result
  46. end
  47. end