Sha256: e25695e4958988cd040c2662d93f5005b5834772fe698c70f42b9d2bdc0b570d

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/test_helper')

# Test cases for reading and generating CSS shorthand properties
class CssParserBasicTests < Test::Unit::TestCase
  include CssParser

  def setup
    @cp = CssParser::Parser.new
    @css = <<-EOT
      html, body, p { margin: 0px; }
      p { padding: 0px; }
      #content { font: 12px/normal sans-serif; }
    EOT
  end

  def test_finding_by_selector
    @cp.add_block!(@css)
    assert_equal 'margin: 0px;', @cp.find_by_selector('body').join(' ')
    assert_equal 'margin: 0px; padding: 0px;', @cp.find_by_selector('p').join(' ')
  end

  def test_adding_block
    @cp.add_block!(@css)
    assert_equal 'margin: 0px;', @cp.find_by_selector('body').join
  end

  def test_adding_a_rule
    @cp.add_rule!('div', 'color: blue;')
    assert_equal 'color: blue;', @cp.find_by_selector('div').join(' ')
  end

  def test_adding_a_rule_set
    rs = CssParser::RuleSet.new('div', 'color: blue;')
    @cp.add_rule_set!(rs)
    assert_equal 'color: blue;', @cp.find_by_selector('div').join(' ')
  end

  def test_toggling_uri_conversion
    # with conversion
    cp_with_conversion = Parser.new(:absolute_paths => true)
    cp_with_conversion.add_block!("body { background: url('../style/yellow.png?abc=123') };",
                                  :base_uri => 'http://example.org/style/basic.css')

    assert_equal "background: url('http://example.org/style/yellow.png?abc=123');",
                 cp_with_conversion['body'].join(' ')
    
    # without conversion
    cp_without_conversion = Parser.new(:absolute_paths => false)
    cp_without_conversion.add_block!("body { background: url('../style/yellow.png?abc=123') };",
                                     :base_uri => 'http://example.org/style/basic.css')

    assert_equal "background: url('../style/yellow.png?abc=123');",
                 cp_without_conversion['body'].join(' ')
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
css_parser-1.1.4 test/test_css_parser_basic.rb