csspool 0.2.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. data/.autotest +16 -0
  2. data/{CHANGELOG.txt → CHANGELOG.rdoc} +10 -0
  3. data/Manifest.txt +60 -72
  4. data/README.rdoc +78 -0
  5. data/Rakefile +9 -52
  6. data/lib/csspool/collection.rb +50 -0
  7. data/lib/csspool/css/charset.rb +7 -0
  8. data/lib/csspool/css/declaration.rb +8 -0
  9. data/lib/csspool/css/document.rb +34 -0
  10. data/lib/csspool/css/document_handler.rb +51 -0
  11. data/lib/csspool/css/import_rule.rb +15 -0
  12. data/lib/csspool/css/media.rb +7 -0
  13. data/lib/csspool/css/rule_set.rb +12 -0
  14. data/lib/csspool/css.rb +7 -0
  15. data/lib/csspool/lib_croco/cr_additional_sel.rb +46 -0
  16. data/lib/csspool/lib_croco/cr_attr_sel.rb +16 -0
  17. data/lib/csspool/lib_croco/cr_doc_handler.rb +24 -0
  18. data/lib/csspool/lib_croco/cr_num.rb +13 -0
  19. data/lib/csspool/lib_croco/cr_parser.rb +11 -0
  20. data/lib/csspool/lib_croco/cr_parsing_location.rb +17 -0
  21. data/lib/csspool/lib_croco/cr_pseudo.rb +14 -0
  22. data/lib/csspool/lib_croco/cr_rgb.rb +18 -0
  23. data/lib/csspool/lib_croco/cr_selector.rb +34 -0
  24. data/lib/csspool/lib_croco/cr_simple_sel.rb +54 -0
  25. data/lib/csspool/lib_croco/cr_term.rb +97 -0
  26. data/lib/csspool/lib_croco/glist.rb +21 -0
  27. data/lib/csspool/lib_croco.rb +78 -0
  28. data/lib/csspool/node.rb +5 -0
  29. data/lib/csspool/sac/document.rb +35 -0
  30. data/lib/csspool/sac/parser.rb +122 -0
  31. data/lib/csspool/sac.rb +2 -0
  32. data/lib/csspool/selector.rb +32 -0
  33. data/lib/csspool/selectors/additional.rb +6 -0
  34. data/lib/csspool/selectors/attribute.rb +21 -0
  35. data/lib/csspool/selectors/class.rb +11 -0
  36. data/lib/csspool/selectors/id.rb +11 -0
  37. data/lib/csspool/selectors/pseudo_class.rb +13 -0
  38. data/lib/csspool/selectors/simple.rb +22 -0
  39. data/lib/csspool/selectors/type.rb +6 -0
  40. data/lib/csspool/selectors/universal.rb +6 -0
  41. data/lib/csspool/selectors.rb +8 -0
  42. data/lib/csspool/terms/function.rb +17 -0
  43. data/lib/csspool/terms/hash.rb +6 -0
  44. data/lib/csspool/terms/ident.rb +15 -0
  45. data/lib/csspool/terms/number.rb +14 -0
  46. data/lib/csspool/terms/rgb.rb +23 -0
  47. data/lib/csspool/terms/string.rb +6 -0
  48. data/lib/csspool/terms/uri.rb +6 -0
  49. data/lib/csspool/terms.rb +7 -0
  50. data/lib/csspool/visitable.rb +18 -0
  51. data/lib/csspool/visitors/comparable.rb +78 -0
  52. data/lib/csspool/visitors/to_css.rb +201 -0
  53. data/lib/csspool/visitors/visitor.rb +17 -0
  54. data/lib/csspool/visitors.rb +3 -0
  55. data/lib/csspool.rb +18 -1
  56. data/test/css/test_document.rb +13 -0
  57. data/test/css/test_import_rule.rb +42 -0
  58. data/test/helper.rb +62 -6
  59. data/test/sac/test_parser.rb +115 -0
  60. data/test/sac/test_properties.rb +43 -0
  61. data/test/sac/test_terms.rb +134 -0
  62. data/test/test_collection.rb +81 -0
  63. data/test/test_parser.rb +75 -241
  64. data/test/test_selector.rb +45 -34
  65. data/test/visitors/test_comparable.rb +72 -0
  66. data/test/visitors/test_to_css.rb +141 -0
  67. metadata +98 -85
  68. data/README.txt +0 -79
  69. data/lib/css/sac/conditions/attribute_condition.rb +0 -56
  70. data/lib/css/sac/conditions/begin_hyphen_condition.rb +0 -22
  71. data/lib/css/sac/conditions/class_condition.rb +0 -22
  72. data/lib/css/sac/conditions/combinator_condition.rb +0 -40
  73. data/lib/css/sac/conditions/condition.rb +0 -35
  74. data/lib/css/sac/conditions/id_condition.rb +0 -27
  75. data/lib/css/sac/conditions/one_of_condition.rb +0 -22
  76. data/lib/css/sac/conditions/pseudo_class_condition.rb +0 -24
  77. data/lib/css/sac/conditions.rb +0 -5
  78. data/lib/css/sac/document_handler.rb +0 -67
  79. data/lib/css/sac/error_handler.rb +0 -14
  80. data/lib/css/sac/generated_parser.rb +0 -999
  81. data/lib/css/sac/generated_property_parser.rb +0 -9214
  82. data/lib/css/sac/lexeme.rb +0 -29
  83. data/lib/css/sac/lexical_unit.rb +0 -203
  84. data/lib/css/sac/parse_exception.rb +0 -6
  85. data/lib/css/sac/parser.rb +0 -115
  86. data/lib/css/sac/property_parser.rb +0 -47
  87. data/lib/css/sac/selectors/child_selector.rb +0 -40
  88. data/lib/css/sac/selectors/conditional_selector.rb +0 -49
  89. data/lib/css/sac/selectors/descendant_selector.rb +0 -40
  90. data/lib/css/sac/selectors/element_selector.rb +0 -39
  91. data/lib/css/sac/selectors/selector.rb +0 -31
  92. data/lib/css/sac/selectors/sibling_selector.rb +0 -39
  93. data/lib/css/sac/selectors/simple_selector.rb +0 -25
  94. data/lib/css/sac/selectors.rb +0 -5
  95. data/lib/css/sac/token.rb +0 -27
  96. data/lib/css/sac/tokenizer.rb +0 -187
  97. data/lib/css/sac/visitable.rb +0 -106
  98. data/lib/css/sac.rb +0 -14
  99. data/lib/css/stylesheet/rule.rb +0 -20
  100. data/lib/css/stylesheet/stylesheet.rb +0 -96
  101. data/lib/css/stylesheet.rb +0 -3
  102. data/lib/parser.y +0 -308
  103. data/lib/property_parser.y +0 -2346
  104. data/lib/property_parser.y.erb +0 -1321
  105. data/test/condition_test_case.rb +0 -6
  106. data/test/selector_test_case.rb +0 -20
  107. data/test/test_all.rb +0 -4
  108. data/test/test_attribute_condition.rb +0 -39
  109. data/test/test_begin_hyphen_condition.rb +0 -15
  110. data/test/test_child_selector.rb +0 -60
  111. data/test/test_class_condition.rb +0 -15
  112. data/test/test_combinator_condition.rb +0 -38
  113. data/test/test_condition.rb +0 -31
  114. data/test/test_conditional_selector.rb +0 -44
  115. data/test/test_descendant_selector.rb +0 -64
  116. data/test/test_element_selector.rb +0 -31
  117. data/test/test_error_recovery.rb +0 -28
  118. data/test/test_id_condition.rb +0 -16
  119. data/test/test_lexeme.rb +0 -39
  120. data/test/test_lexical_color.rb +0 -49
  121. data/test/test_lexical_function.rb +0 -31
  122. data/test/test_lexical_ident.rb +0 -30
  123. data/test/test_lexical_number.rb +0 -68
  124. data/test/test_lexical_string.rb +0 -23
  125. data/test/test_lexical_unit.rb +0 -106
  126. data/test/test_lexical_uri.rb +0 -28
  127. data/test/test_one_of_condition.rb +0 -15
  128. data/test/test_parse_error.rb +0 -199
  129. data/test/test_property_parser.rb +0 -593
  130. data/test/test_selector_as_string.rb +0 -94
  131. data/test/test_selector_parser.rb +0 -178
  132. data/test/test_sibling_selector.rb +0 -42
  133. data/test/test_simple_selector.rb +0 -9
  134. data/test/test_specificity.rb +0 -76
  135. data/test/test_stylesheet.rb +0 -95
  136. data/test/test_token.rb +0 -24
  137. data/test/test_tokenizer.rb +0 -127
  138. data/test/test_xpath.rb +0 -105
@@ -1,6 +0,0 @@
1
- class ConditionTestCase < Test::Unit::TestCase
2
- include CSS::SAC::Conditions
3
-
4
- Node = Struct.new(:name, :parent, :child, :next_sibling, :attributes)
5
- undef :default_test
6
- end
@@ -1,20 +0,0 @@
1
- class SelectorTestCase < Test::Unit::TestCase
2
- include CSS::SAC::Selectors
3
- Node = Struct.new(:name, :parent, :child, :next_sibling, :attributes)
4
- NoParentNode = Struct.new(:name)
5
-
6
- def parent_child_tree(*args)
7
- nodes = args.map { |name|
8
- n = Node.new
9
- n.name = name
10
- n
11
- }
12
- nodes.each_with_index do |n,i|
13
- n.child = nodes[i + 1] if i < nodes.length
14
- n.parent = nodes[i - 1] if i > 0
15
- end
16
- nodes.last
17
- end
18
-
19
- undef :default_test
20
- end
data/test/test_all.rb DELETED
@@ -1,4 +0,0 @@
1
- Dir[File.dirname(__FILE__) + "/test_*.rb"].
2
- reject { |f| f == __FILE__ }.
3
- collect { |f| File.basename(f, ".rb") }.
4
- each { |f| require f }
@@ -1,39 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class AttributeConditionTest < ConditionTestCase
4
- def test_hash
5
- first = AttributeCondition.new(1, 1, 1)
6
- second = AttributeCondition.new(1, 1, 1)
7
- assert_equal first.hash, second.hash
8
-
9
- third = AttributeCondition.new(2, 1, 1)
10
- assert_not_equal first.hash, third.hash
11
- end
12
-
13
- def test_equals2
14
- first = AttributeCondition.new(1, 1, 1)
15
- second = AttributeCondition.new(1, 1, 1)
16
- assert_equal first, second
17
-
18
- third = AttributeCondition.new(1,1,2)
19
- assert_not_equal first, third
20
-
21
- fourth = AttributeCondition.new(1,2,1)
22
- assert_not_equal first, fourth
23
-
24
- fifth = AttributeCondition.new(2,1,1)
25
- assert_not_equal first, fifth
26
- end
27
-
28
- def test_equals_tilde
29
- attribute = AttributeCondition.new('class', 'foo', true)
30
- node = Node.new('p')
31
- node.attributes = { 'class' => 'foo' }
32
-
33
- assert attribute =~ node
34
-
35
- node.attributes = { 'class' => 'bar' }
36
- assert(!(attribute =~ node))
37
- assert(!(attribute =~ 1))
38
- end
39
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class BeginHyphenConditionTest < ConditionTestCase
4
- def test_tilde_equals
5
- attribute = BeginHyphenCondition.new('class', 'foo')
6
- node = Node.new('p')
7
- node.attributes = { 'class' => 'foobar' }
8
-
9
- assert attribute =~ node
10
-
11
- node.attributes = { 'class' => 'barfoo' }
12
- assert(!(attribute =~ node))
13
- assert(!(attribute =~ 1))
14
- end
15
- end
@@ -1,60 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ChildSelectorTest < SelectorTestCase
4
- def test_hash
5
- first = ChildSelector.new(1,1)
6
- second = ChildSelector.new(1,1)
7
- assert_equal first.hash, second.hash
8
-
9
- third = ChildSelector.new(1,2)
10
- assert_not_equal first.hash, third.hash
11
-
12
- fourth = ChildSelector.new(2,1)
13
- assert_not_equal first.hash, fourth.hash
14
- end
15
-
16
- def test_equals2
17
- first = ChildSelector.new(1,1)
18
- second = ChildSelector.new(1,1)
19
- assert_equal first, second
20
-
21
- third = ChildSelector.new(1,2)
22
- assert_not_equal first, third
23
-
24
- fourth = ChildSelector.new(2,1)
25
- assert_not_equal first, fourth
26
- end
27
-
28
- def test_equals_tilde
29
- parent = ElementSelector.new('div')
30
- child = ElementSelector.new('p')
31
- sel = ChildSelector.new(parent, child)
32
-
33
- node = parent_child_tree('div', 'p')
34
- assert sel =~ node
35
-
36
- node2 = parent_child_tree('body', 'div', 'p')
37
- assert sel =~ node2
38
-
39
- failing = parent_child_tree('p', 'div')
40
- assert(! (sel =~ failing))
41
- assert(! (sel =~ NoParentNode.new('div')))
42
- assert(! (sel =~ Node.new('div', nil, nil)))
43
- end
44
-
45
- def test_many_child
46
- @sac = CSS::SAC::Parser.new()
47
- class << @sac.document_handler
48
- attr_accessor :selectors
49
- alias :start_selector :selectors=
50
- end
51
-
52
- @sac.parse('div > h1 > h2 { }')
53
- selectors = @sac.document_handler.selectors
54
- assert_equal(1, selectors.length)
55
-
56
- sel = selectors.first
57
- node = parent_child_tree('div', 'h1', 'h2')
58
- assert sel =~ node
59
- end
60
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ClassConditionTest < ConditionTestCase
4
- def test_tilde_equals
5
- attribute = ClassCondition.new('foo')
6
- node = Node.new('p')
7
- node.attributes = { 'class' => 'foo' }
8
-
9
- assert attribute =~ node
10
-
11
- node.attributes = { 'class' => 'barfoo' }
12
- assert(!(attribute =~ node))
13
- assert(!(attribute =~ 1))
14
- end
15
- end
@@ -1,38 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class CombinatorConditionTest < ConditionTestCase
4
- def test_equals2
5
- first = CombinatorCondition.new(1,1)
6
- second = CombinatorCondition.new(1,1)
7
- assert_equal first, second
8
-
9
- third = CombinatorCondition.new(1,2)
10
- assert_not_equal first, third
11
- end
12
-
13
- def test_hash
14
- first = CombinatorCondition.new(1,1)
15
- second = CombinatorCondition.new(1,1)
16
- assert_equal first.hash, second.hash
17
-
18
- third = CombinatorCondition.new(1,2)
19
- assert_not_equal first.hash, third.hash
20
- end
21
-
22
- def test_equals_tilde
23
- first = ClassCondition.new('foo')
24
- second = AttributeCondition.new('name', 'aaron', true)
25
- combinator_condition = CombinatorCondition.new(first, second)
26
-
27
- node = Node.new('p')
28
- node.attributes = { 'class' => 'foo', 'name' => 'aaron' }
29
-
30
- assert combinator_condition =~ node
31
-
32
- node.attributes = { 'class' => 'bar', 'name' => 'aaron' }
33
- assert(!(combinator_condition =~ node))
34
-
35
- node.attributes = { 'class' => 'foo', 'name' => 'bar' }
36
- assert(!(combinator_condition =~ node))
37
- end
38
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ConditionTest < ConditionTestCase
4
- def test_equals2
5
- first = Condition.new(1)
6
- second = Condition.new(1)
7
- assert_equal first, second
8
-
9
- third = Condition.new(2)
10
- assert_not_equal first, third
11
- assert_not_equal first, 1
12
- end
13
-
14
- def test_eql?
15
- first = Condition.new(1)
16
- second = Condition.new(1)
17
- assert first.eql?(second)
18
-
19
- third = Condition.new(2)
20
- assert !first.eql?(third)
21
- end
22
-
23
- def test_hash
24
- first = Condition.new(1)
25
- second = Condition.new(1)
26
- assert_equal first.hash, second.hash
27
-
28
- third = Condition.new(2)
29
- assert_not_equal first.hash, third.hash
30
- end
31
- end
@@ -1,44 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ConditionalSelectorTest < SelectorTestCase
4
- def test_hash
5
- first = ConditionalSelector.new(1,1)
6
- second = ConditionalSelector.new(1,1)
7
- assert_equal first.hash, second.hash
8
-
9
- third = ConditionalSelector.new(1,2)
10
- assert_not_equal first.hash, third.hash
11
-
12
- fourth = ConditionalSelector.new(2,1)
13
- assert_not_equal first.hash, fourth.hash
14
- end
15
-
16
- def test_equals2
17
- first = ConditionalSelector.new(1,1)
18
- second = ConditionalSelector.new(1,1)
19
- assert_equal first, second
20
-
21
- third = ConditionalSelector.new(1,2)
22
- assert_not_equal first, third
23
-
24
- fourth = ConditionalSelector.new(2,1)
25
- assert_not_equal first, fourth
26
- end
27
-
28
- def test_equals_tilde
29
- attribute = CSS::SAC::Conditions::AttributeCondition.new('class', 'foo', true)
30
- div = ElementSelector.new('div')
31
- sel = ConditionalSelector.new(div, attribute)
32
-
33
- node = Node.new('div')
34
- node.attributes = { 'class' => 'foo' }
35
-
36
- assert sel =~ node
37
-
38
- sel = ConditionalSelector.new(nil, attribute)
39
- assert(sel =~ node)
40
-
41
- node.attributes = { 'class' => 'bar' }
42
- assert(!(sel =~ node))
43
- end
44
- end
@@ -1,64 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class DescendantSelectorTest < SelectorTestCase
4
- def test_hash
5
- first = DescendantSelector.new(1,1)
6
- second = DescendantSelector.new(1,1)
7
- assert_equal first.hash, second.hash
8
-
9
- third = DescendantSelector.new(1,2)
10
- assert_not_equal first.hash, third.hash
11
-
12
- fourth = DescendantSelector.new(2,1)
13
- assert_not_equal first.hash, fourth.hash
14
- end
15
-
16
- def test_equals2
17
- first = DescendantSelector.new(1,1)
18
- second = DescendantSelector.new(1,1)
19
- assert_equal first, second
20
-
21
- third = DescendantSelector.new(1,2)
22
- assert_not_equal first, third
23
-
24
- fourth = DescendantSelector.new(2,1)
25
- assert_not_equal first, fourth
26
- end
27
-
28
- def test_equals_tilde
29
- parent = ElementSelector.new('div')
30
- child = ElementSelector.new('p')
31
- sel = DescendantSelector.new(parent, child)
32
-
33
- node = parent_child_tree('div', 'p')
34
- assert sel =~ node
35
-
36
- node2 = parent_child_tree('body', 'div', 'p')
37
- assert sel =~ node2
38
-
39
- node3 = parent_child_tree('body', 'div', 'table', 'tr', 'td', 'p')
40
- assert sel =~ node3
41
-
42
- failing = parent_child_tree('p', 'div')
43
- assert(! (sel =~ failing))
44
- assert(! (sel =~ NoParentNode.new('div')))
45
- assert(! (sel =~ Node.new('div', nil, nil)))
46
- end
47
-
48
- def test_many_descendants
49
- @sac = CSS::SAC::Parser.new()
50
- class << @sac.document_handler
51
- attr_accessor :selectors
52
- alias :start_selector :selectors=
53
- end
54
-
55
- @sac.parse('div h1 h2 { }')
56
- selectors = @sac.document_handler.selectors
57
- assert_equal(1, selectors.length)
58
-
59
- sel = selectors.first
60
- node = parent_child_tree('body', 'div', 'p', 'h1', 'p', 'h2')
61
- assert sel =~ node
62
- end
63
- end
64
-
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ElementSelectorTest < SelectorTestCase
4
- def test_hash
5
- first = ElementSelector.new(1)
6
- second = ElementSelector.new(1)
7
- assert_equal first.hash, second.hash
8
-
9
- third = ElementSelector.new(2)
10
- assert_not_equal first.hash, third.hash
11
- end
12
-
13
- def test_equals2
14
- first = ElementSelector.new(1)
15
- second = ElementSelector.new(1)
16
- assert_equal first, second
17
-
18
- third = ElementSelector.new(2)
19
- assert_not_equal first, third
20
- end
21
-
22
- def test_equals_tilde
23
- div = ElementSelector.new('div')
24
- node = Node.new
25
- node.name = 'div'
26
-
27
- assert div =~ node
28
- assert(!(div =~ nil))
29
- end
30
- end
31
-
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class ErrorRecoveryTest < Test::Unit::TestCase
4
- def setup
5
- @sac = CSS::SAC::Parser.new
6
- end
7
-
8
- def test_unexpected_color
9
- doc = @sac.parse('
10
- a { color: red; }
11
- body { border: solid 1px; #000; color: red; }
12
- p { color: blue; }
13
- ')
14
- assert_equal 3, doc.rules.length
15
-
16
- a_rule = doc['a']
17
- assert a_rule
18
- assert_equal 1, a_rule.properties.length
19
-
20
- body_rule = doc['body']
21
- assert body_rule
22
- assert_equal 2, body_rule.properties.length
23
-
24
- p_rule = doc['p']
25
- assert p_rule
26
- assert_equal 1, p_rule.properties.length
27
- end
28
- end
@@ -1,16 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class IdConditionTest < ConditionTestCase
4
- def test_equals_tilde
5
- attribute = IDCondition.new('some_id')
6
- node = Node.new('p')
7
- node.attributes = { 'id' => 'some_id' }
8
-
9
- assert attribute =~ node
10
-
11
- node.attributes = { 'id' => 'different' }
12
- assert(!(attribute =~ node))
13
- assert(!(attribute =~ 1))
14
- end
15
- end
16
-
data/test/test_lexeme.rb DELETED
@@ -1,39 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexemeTest < Test::Unit::TestCase
4
- include CSS
5
- #include CSS::SAC # grrr annoying: SAC should be a module
6
-
7
- def test_lexemes_have_a_required_name
8
- assert_equal(:foo, SAC::Lexeme.new(:foo, /foo/).name)
9
- assert_raise(ArgumentError) { SAC::Lexeme.new(nil, /foo/) }
10
- end
11
-
12
- def test_lexemes_require_at_least_one_pattern
13
- assert_raise(ArgumentError) { SAC::Lexeme.new(:foo) }
14
- end
15
-
16
- def test_simple_lexemes_can_specify_a_pattern_inline
17
- lexeme = SAC::Lexeme.new(:foo, /bar/)
18
- assert(lexeme.pattern.match("bar"))
19
- end
20
-
21
- def test_more_patterns_can_be_added_in_a_block
22
- lexeme = SAC::Lexeme.new(:foo) do |patterns|
23
- patterns << /foo/
24
- patterns << /bar/
25
- patterns << /baz/
26
- end
27
-
28
- # ...but the single exposed lexeme pattern is a union
29
- %w(foo bar baz).each do |candidate|
30
- assert_match(lexeme.pattern, candidate)
31
- end
32
- end
33
-
34
- def test_patterns_are_start_anchored_and_case_insensitive
35
- lexeme = SAC::Lexeme.new(:foo, /foo/)
36
- assert_match(lexeme.pattern, "FOO")
37
- assert_no_match(lexeme.pattern, " foo")
38
- end
39
- end
@@ -1,49 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalColorTest < Test::Unit::TestCase
4
- include CSS::SAC
5
-
6
- def test_to_s
7
- first = Color.new('#FFFFFF')
8
- assert_equal('#FFF', first.to_s)
9
-
10
- second = Color.new('#FEFEFE')
11
- assert_equal('#FEFEFE', second.to_s)
12
-
13
- third = Color.new('red')
14
- assert_equal('red', third.to_s)
15
-
16
- fourth = Color.new('#0066FF')
17
- assert_equal('#06F', fourth.to_s)
18
- end
19
-
20
- def test_hash
21
- first = Color.new('#FFFFFF')
22
- second = Color.new('#FFFFFF')
23
- assert_equal first.hash, second.hash
24
-
25
- third = Color.new('red')
26
- assert_not_equal first.hash, third.hash
27
- end
28
-
29
- def test_equals2
30
- first = Color.new('#FFFFFF')
31
- second = Color.new('#FFFFFF')
32
- assert_equal(first, second)
33
-
34
- third = Color.new('#FFF')
35
- assert_equal(first, third)
36
-
37
- fourth = Color.new('#FFA')
38
- assert_not_equal(first, fourth)
39
- end
40
-
41
- def test_equals2_string
42
- first = Color.new('red')
43
- second = Color.new('red')
44
- assert_equal(first, second)
45
-
46
- third = Color.new('#FFF')
47
- assert_not_equal(first, third)
48
- end
49
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalFunctionTest < Test::Unit::TestCase
4
- include CSS::SAC
5
-
6
- def test_to_s
7
- first = Function.new('counter(', %w{ 1 2 3 4 })
8
- assert_equal('counter(1, 2, 3, 4)', first.to_s)
9
- end
10
-
11
- def test_equals2
12
- first = Function.new('counter(', %w{ 1 2 3 4 })
13
- second = Function.new('counter(', %w{ 1 2 3 4 })
14
- assert_equal(first, second)
15
-
16
- third = Function.new('rect(', %w{ 1 2 3 4 })
17
- assert_not_equal(first, third)
18
-
19
- fourth = Function.new('counter(', %w{ 1 2 3 5 })
20
- assert_not_equal(first, fourth)
21
- end
22
-
23
- def test_hash
24
- first = Function.new('counter(', %w{ 1 2 3 4 })
25
- second = Function.new('counter(', %w{ 1 2 3 4 })
26
- assert_equal first.hash, second.hash
27
-
28
- third = Function.new('counter(', %w{ 1 2 4 4 })
29
- assert_not_equal first.hash, third.hash
30
- end
31
- end
@@ -1,30 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalIdentTest < Test::Unit::TestCase
4
- include CSS::SAC
5
-
6
- def test_equals2
7
- first = LexicalIdent.new('one')
8
- second = LexicalIdent.new('one')
9
- assert_equal first, second
10
-
11
- third = LexicalIdent.new('two')
12
- assert_not_equal first, third
13
- end
14
-
15
- def test_eql?
16
- first = LexicalIdent.new('one')
17
- second = LexicalIdent.new('one')
18
-
19
- assert first.eql?(second)
20
- end
21
-
22
- def test_hash
23
- first = LexicalIdent.new('one')
24
- second = LexicalIdent.new('one')
25
- assert_equal first.hash, second.hash
26
-
27
- third = LexicalIdent.new('two')
28
- assert_not_equal first.hash, third.hash
29
- end
30
- end
@@ -1,68 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalNumberTest < Test::Unit::TestCase
4
- def test_to_s
5
- first = CSS::SAC::Number.new('10', 'px')
6
- assert_equal('10px', first.to_s)
7
-
8
- second = CSS::SAC::Number.new('0', 'em')
9
- assert_equal('0', second.to_s)
10
- end
11
-
12
- def test_hash
13
- first = CSS::SAC::Number.new('10', 'px')
14
- second = CSS::SAC::Number.new('10', 'px')
15
- assert_equal first.hash, second.hash
16
-
17
- third = CSS::SAC::Number.new('11', 'px')
18
- assert_not_equal first.hash, third.hash
19
-
20
- fourth = CSS::SAC::Number.new('10', 'em')
21
- assert_not_equal first.hash, fourth.hash
22
- end
23
-
24
- def test_hash_0_unit
25
- first = CSS::SAC::Number.new('0', 'px')
26
- second = CSS::SAC::Number.new('0', 'px')
27
- assert_equal first.hash, second.hash
28
-
29
- third = CSS::SAC::Number.new('0', 'em')
30
- assert_equal first.hash, third.hash
31
- end
32
-
33
- def test_equals2
34
- first = CSS::SAC::Number.new('10', 'px')
35
- second = CSS::SAC::Number.new('10', 'px')
36
- assert_equal first, second
37
-
38
- third = CSS::SAC::Number.new('10', 'ex')
39
- assert_not_equal first, third
40
-
41
- fourth = CSS::SAC::Number.new('11', 'px')
42
- assert_equal(11, fourth.integer_value)
43
- assert_not_equal first, fourth
44
- end
45
-
46
- def test_equals2_zero
47
- first = CSS::SAC::Number.new('0', 'px')
48
- second = CSS::SAC::Number.new('0', 'em')
49
- assert_equal first, second
50
-
51
- first_float = CSS::SAC::Number.new('0.0', 'px')
52
- second_float = CSS::SAC::Number.new('0.0', 'em')
53
- assert_equal first_float, second_float
54
-
55
- third_float = CSS::SAC::Number.new('0.1', 'em')
56
- assert_equal 0.1, third_float.float_value
57
- assert_not_equal first_float, third_float
58
- end
59
-
60
- def test_equals2_type
61
- first = CSS::SAC::Number.new(10, '', :SAC_INTEGER)
62
- second = CSS::SAC::Number.new(10, '', :SAC_INTEGER)
63
- assert_equal first, second
64
-
65
- third = CSS::SAC::Number.new(11, '', :SAC_INTEGER)
66
- assert_not_equal first, third
67
- end
68
- end
@@ -1,23 +0,0 @@
1
- require File.dirname(__FILE__) + "/helper"
2
-
3
- class LexicalStringTest < Test::Unit::TestCase
4
- include CSS::SAC
5
-
6
- def test_equals2
7
- first = LexicalString.new('hey bro')
8
- second = LexicalString.new('hey bro')
9
- assert_equal(first, second)
10
-
11
- third = LexicalString.new('hey bro again')
12
- assert_not_equal(first, third)
13
- end
14
-
15
- def test_hash
16
- first = LexicalString.new('hey bro')
17
- second = LexicalString.new('hey bro')
18
- assert_equal(first.hash, second.hash)
19
-
20
- third = LexicalString.new('hey bro!')
21
- assert_not_equal(first.hash, third.hash)
22
- end
23
- end