test_cssbuilder.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env ruby
  2. #--
  3. # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
  4. # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
  5. # All rights reserved.
  6. # Permission is granted for use, copying, modification, distribution,
  7. # and distribution of modified versions of this work as long as the
  8. # above copyright notice is included.
  9. #++
  10. require 'test/unit'
  11. require 'test/preload'
  12. require 'builder'
  13. require 'builder/css'
  14. class TestCSS < Test::Unit::TestCase
  15. def setup
  16. @css = Builder::CSS.new
  17. end
  18. def test_create
  19. assert_not_nil @css
  20. end
  21. def test_no_block
  22. @css.body
  23. assert_equal 'body', @css.target!
  24. end
  25. def test_block
  26. @css.body {
  27. color 'green'
  28. }
  29. assert_equal "body {\n color: green;\n}\n\n", @css.target!
  30. end
  31. def test_id
  32. @css.id!('nav') { color 'green' }
  33. assert_equal "#nav {\n color: green;\n}\n\n", @css.target!
  34. end
  35. def test_class
  36. @css.class!('nav') { color 'green' }
  37. assert_equal ".nav {\n color: green;\n}\n\n", @css.target!
  38. end
  39. def test_elem_with_id
  40. @css.div(:id => 'nav') { color 'green' }
  41. assert_equal "div#nav {\n color: green;\n}\n\n", @css.target!
  42. end
  43. def test_elem_with_class
  44. @css.div(:class => 'nav') { color 'green' }
  45. assert_equal "div.nav {\n color: green;\n}\n\n", @css.target!
  46. end
  47. def test_comment
  48. @css.comment!('foo')
  49. assert_equal "/* foo */\n", @css.target!
  50. end
  51. def test_selector
  52. @css.a(:hover) { color 'green' }
  53. assert_equal "a:hover {\n color: green;\n}\n\n", @css.target!
  54. end
  55. def test_plus
  56. @css.h1 + @css.span
  57. assert_equal "h1 + span", @css.target!
  58. end
  59. def test_plus_with_block
  60. @css.h1 + @css.span { color 'green' }
  61. assert_equal "h1 + span {\n color: green;\n}\n\n", @css.target!
  62. end
  63. def test_contextual
  64. @css.h1 >> @css.span
  65. assert_equal "h1 span", @css.target!
  66. end
  67. def test_contextual_with_block
  68. @css.h1 >> @css.span { color 'green' }
  69. assert_equal "h1 span {\n color: green;\n}\n\n", @css.target!
  70. end
  71. def test_child
  72. @css.h1 > @css.span
  73. assert_equal "h1 > span", @css.target!
  74. end
  75. def test_child_with_block
  76. @css.h1 > @css.span { color 'green' }
  77. assert_equal "h1 > span {\n color: green;\n}\n\n", @css.target!
  78. end
  79. def test_multiple_op
  80. @css.h1 + @css.span + @css.span
  81. assert_equal "h1 + span + span", @css.target!
  82. end
  83. def test_all
  84. @css.h1 | @css.h2 { color 'green' }
  85. assert_equal "h1 , h2 {\n color: green;\n}\n\n", @css.target!
  86. end
  87. def test_all_with_atts
  88. @css.h1(:class => 'foo') | @css.h2(:class => 'bar') { color 'green' }
  89. assert_equal "h1.foo , h2.bar {\n color: green;\n}\n\n", @css.target!
  90. end
  91. def test_multiple_basic
  92. @css.body { color 'green' }
  93. @css.h1 { color 'green' }
  94. assert_equal "body {\n color: green;\n}\n\nh1 {\n color: green;\n}\n\n", @css.target!
  95. end
  96. def test_multiple_ops
  97. @css.body { color 'green' }
  98. @css.body > @css.h1 { color 'green' }
  99. assert_equal "body {\n color: green;\n}\n\nbody > h1 {\n color: green;\n}\n\n", @css.target!
  100. end
  101. end