#!/usr/bin/env ruby require 'test/unit' # require 'test/preload' require 'rubygems' require 'builder' require File.dirname(__FILE__) + '/../lib/builder/css' class TestCSS < Test::Unit::TestCase def setup @css = Builder::CSS.new end def test_create assert_not_nil @css end def test_no_block @css.body assert_equal 'body', @css.target! end def test_block @css.body { color 'green' } assert_equal "body {\n color: green;\n}\n\n", @css.target! end def test_id @css.id!('nav') { color 'green' } assert_equal "#nav {\n color: green;\n}\n\n", @css.target! end def test_should_generate_id_in_markaby_style @css.nav! { color 'green' } assert_equal "#nav {\n color: green;\n}\n\n", @css.target! end def test_should_generate_class_in_markaby_style @css.nav { color 'green' } assert_equal ".nav {\n color: green;\n}\n\n", @css.target! end def test_class @css.class!('nav') { color 'green' } assert_equal ".nav {\n color: green;\n}\n\n", @css.target! end def test_elem_with_id @css.div(:id => 'nav') { color 'green' } assert_equal "div#nav {\n color: green;\n}\n\n", @css.target! end def test_elem_with_class @css.div(:class => 'nav') { color 'green' } assert_equal "div.nav {\n color: green;\n}\n\n", @css.target! end def test_comment @css.comment!('foo') assert_equal "/* foo */\n", @css.target! end def test_selector @css.a(:hover) { color 'green' } assert_equal "a:hover {\n color: green;\n}\n\n", @css.target! end def test_plus @css.h1 + @css.span assert_equal "h1 + span", @css.target! end def test_plus_with_block @css.h1 + @css.span { color 'green' } assert_equal "h1 + span {\n color: green;\n}\n\n", @css.target! end def test_contextual @css.h1 >> @css.span assert_equal "h1 span", @css.target! end def test_contextual_with_block @css.h1 >> @css.span { color 'green' } assert_equal "h1 span {\n color: green;\n}\n\n", @css.target! end def test_child @css.h1 > @css.span assert_equal "h1 > span", @css.target! end def test_child_with_block @css.h1 > @css.span { color 'green' } assert_equal "h1 > span {\n color: green;\n}\n\n", @css.target! end def test_multiple_op @css.h1 + @css.span + @css.span assert_equal "h1 + span + span", @css.target! end def test_all @css.h1 | @css.h2 { color 'green' } assert_equal "h1 , h2 {\n color: green;\n}\n\n", @css.target! end # FAILS # def test_should_handle_markaby_id_in_middle_of_pipes # @css.h1(:id => "logo") | @css.products! | @css.product! { color 'green' } # assert_equal "h1#logo , #products, #product {\n color: green;\n}\n\n", @css.target! # end def test_should_take_symbol_as_value @css.h1 { color :green } assert_equal "h1 {\n color: green;\n}\n\n", @css.target! end def test_should_convert_underscores_to_dashes_in_symbol_args @css.h1 { color :green_grass } assert_equal "h1 {\n color: green-grass;\n}\n\n", @css.target! end def test_all_with_atts @css.h1(:class => 'foo') | @css.h2(:class => 'bar') { color 'green' } assert_equal "h1.foo , h2.bar {\n color: green;\n}\n\n", @css.target! end def test_multiple_basic @css.body { color 'green' } @css.h1 { color 'green' } assert_equal "body {\n color: green;\n}\n\nh1 {\n color: green;\n}\n\n", @css.target! end def test_multiple_ops @css.body { color 'green' } @css.body > @css.h1 { color 'green' } assert_equal "body {\n color: green;\n}\n\nbody > h1 {\n color: green;\n}\n\n", @css.target! end def test_should_print_straight_css hack_text = <<-CSS some_plain_css { maybe_an_ie_hack: foo } CSS @css.text hack_text @css.foo! assert_equal hack_text + "foo!", @css.target! end def test_should_print_straight_css_without_needing_extra_tag_hack # TODO @css.text doesn't work unless there is another dynamic tag following it. # Should work either way. end end