Sha256: 7bc0707af17e3325a8527afefd7555245791a5182795cf3068ce3407303cc718

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

require 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

11 entries across 11 versions & 4 rubygems

Version Path
DanaDanger-css_parser-0.9.1 test/test_css_parser_basic.rb
css_parser-1.1.3 test/test_css_parser_basic.rb
css_parser-1.1.2 test/test_css_parser_basic.rb
css_parser-1.1.1 test/test_css_parser_basic.rb
css_parser_1.1.0-1.1.0 test/test_css_parser_basic.rb
css_parser-1.0.1 test/test_css_parser_basic.rb
deadweight-0.1.3 vendor/gems/css_parser-1.0.0/test/test_css_parser_basic.rb
css_parser-1.0.0 test/test_css_parser_basic.rb
deadweight-0.1.2 vendor/gems/css_parser-0.9.1/test/test_css_parser_basic.rb
css_parser-0.9.0 test/test_css_parser_basic.rb
css_parser-0.9.1 test/test_css_parser_basic.rb