csspool 0.2.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +16 -0
- data/{CHANGELOG.txt → CHANGELOG.rdoc} +10 -0
- data/Manifest.txt +60 -72
- data/README.rdoc +78 -0
- data/Rakefile +9 -52
- data/lib/csspool/collection.rb +50 -0
- data/lib/csspool/css/charset.rb +7 -0
- data/lib/csspool/css/declaration.rb +8 -0
- data/lib/csspool/css/document.rb +34 -0
- data/lib/csspool/css/document_handler.rb +51 -0
- data/lib/csspool/css/import_rule.rb +15 -0
- data/lib/csspool/css/media.rb +7 -0
- data/lib/csspool/css/rule_set.rb +12 -0
- data/lib/csspool/css.rb +7 -0
- data/lib/csspool/lib_croco/cr_additional_sel.rb +46 -0
- data/lib/csspool/lib_croco/cr_attr_sel.rb +16 -0
- data/lib/csspool/lib_croco/cr_doc_handler.rb +24 -0
- data/lib/csspool/lib_croco/cr_num.rb +13 -0
- data/lib/csspool/lib_croco/cr_parser.rb +11 -0
- data/lib/csspool/lib_croco/cr_parsing_location.rb +17 -0
- data/lib/csspool/lib_croco/cr_pseudo.rb +14 -0
- data/lib/csspool/lib_croco/cr_rgb.rb +18 -0
- data/lib/csspool/lib_croco/cr_selector.rb +34 -0
- data/lib/csspool/lib_croco/cr_simple_sel.rb +54 -0
- data/lib/csspool/lib_croco/cr_term.rb +97 -0
- data/lib/csspool/lib_croco/glist.rb +21 -0
- data/lib/csspool/lib_croco.rb +78 -0
- data/lib/csspool/node.rb +5 -0
- data/lib/csspool/sac/document.rb +35 -0
- data/lib/csspool/sac/parser.rb +122 -0
- data/lib/csspool/sac.rb +2 -0
- data/lib/csspool/selector.rb +32 -0
- data/lib/csspool/selectors/additional.rb +6 -0
- data/lib/csspool/selectors/attribute.rb +21 -0
- data/lib/csspool/selectors/class.rb +11 -0
- data/lib/csspool/selectors/id.rb +11 -0
- data/lib/csspool/selectors/pseudo_class.rb +13 -0
- data/lib/csspool/selectors/simple.rb +22 -0
- data/lib/csspool/selectors/type.rb +6 -0
- data/lib/csspool/selectors/universal.rb +6 -0
- data/lib/csspool/selectors.rb +8 -0
- data/lib/csspool/terms/function.rb +17 -0
- data/lib/csspool/terms/hash.rb +6 -0
- data/lib/csspool/terms/ident.rb +15 -0
- data/lib/csspool/terms/number.rb +14 -0
- data/lib/csspool/terms/rgb.rb +23 -0
- data/lib/csspool/terms/string.rb +6 -0
- data/lib/csspool/terms/uri.rb +6 -0
- data/lib/csspool/terms.rb +7 -0
- data/lib/csspool/visitable.rb +18 -0
- data/lib/csspool/visitors/comparable.rb +78 -0
- data/lib/csspool/visitors/to_css.rb +201 -0
- data/lib/csspool/visitors/visitor.rb +17 -0
- data/lib/csspool/visitors.rb +3 -0
- data/lib/csspool.rb +18 -1
- data/test/css/test_document.rb +13 -0
- data/test/css/test_import_rule.rb +42 -0
- data/test/helper.rb +62 -6
- data/test/sac/test_parser.rb +115 -0
- data/test/sac/test_properties.rb +43 -0
- data/test/sac/test_terms.rb +134 -0
- data/test/test_collection.rb +81 -0
- data/test/test_parser.rb +75 -241
- data/test/test_selector.rb +45 -34
- data/test/visitors/test_comparable.rb +72 -0
- data/test/visitors/test_to_css.rb +141 -0
- metadata +98 -85
- data/README.txt +0 -79
- data/lib/css/sac/conditions/attribute_condition.rb +0 -56
- data/lib/css/sac/conditions/begin_hyphen_condition.rb +0 -22
- data/lib/css/sac/conditions/class_condition.rb +0 -22
- data/lib/css/sac/conditions/combinator_condition.rb +0 -40
- data/lib/css/sac/conditions/condition.rb +0 -35
- data/lib/css/sac/conditions/id_condition.rb +0 -27
- data/lib/css/sac/conditions/one_of_condition.rb +0 -22
- data/lib/css/sac/conditions/pseudo_class_condition.rb +0 -24
- data/lib/css/sac/conditions.rb +0 -5
- data/lib/css/sac/document_handler.rb +0 -67
- data/lib/css/sac/error_handler.rb +0 -14
- data/lib/css/sac/generated_parser.rb +0 -999
- data/lib/css/sac/generated_property_parser.rb +0 -9214
- data/lib/css/sac/lexeme.rb +0 -29
- data/lib/css/sac/lexical_unit.rb +0 -203
- data/lib/css/sac/parse_exception.rb +0 -6
- data/lib/css/sac/parser.rb +0 -115
- data/lib/css/sac/property_parser.rb +0 -47
- data/lib/css/sac/selectors/child_selector.rb +0 -40
- data/lib/css/sac/selectors/conditional_selector.rb +0 -49
- data/lib/css/sac/selectors/descendant_selector.rb +0 -40
- data/lib/css/sac/selectors/element_selector.rb +0 -39
- data/lib/css/sac/selectors/selector.rb +0 -31
- data/lib/css/sac/selectors/sibling_selector.rb +0 -39
- data/lib/css/sac/selectors/simple_selector.rb +0 -25
- data/lib/css/sac/selectors.rb +0 -5
- data/lib/css/sac/token.rb +0 -27
- data/lib/css/sac/tokenizer.rb +0 -187
- data/lib/css/sac/visitable.rb +0 -106
- data/lib/css/sac.rb +0 -14
- data/lib/css/stylesheet/rule.rb +0 -20
- data/lib/css/stylesheet/stylesheet.rb +0 -96
- data/lib/css/stylesheet.rb +0 -3
- data/lib/parser.y +0 -308
- data/lib/property_parser.y +0 -2346
- data/lib/property_parser.y.erb +0 -1321
- data/test/condition_test_case.rb +0 -6
- data/test/selector_test_case.rb +0 -20
- data/test/test_all.rb +0 -4
- data/test/test_attribute_condition.rb +0 -39
- data/test/test_begin_hyphen_condition.rb +0 -15
- data/test/test_child_selector.rb +0 -60
- data/test/test_class_condition.rb +0 -15
- data/test/test_combinator_condition.rb +0 -38
- data/test/test_condition.rb +0 -31
- data/test/test_conditional_selector.rb +0 -44
- data/test/test_descendant_selector.rb +0 -64
- data/test/test_element_selector.rb +0 -31
- data/test/test_error_recovery.rb +0 -28
- data/test/test_id_condition.rb +0 -16
- data/test/test_lexeme.rb +0 -39
- data/test/test_lexical_color.rb +0 -49
- data/test/test_lexical_function.rb +0 -31
- data/test/test_lexical_ident.rb +0 -30
- data/test/test_lexical_number.rb +0 -68
- data/test/test_lexical_string.rb +0 -23
- data/test/test_lexical_unit.rb +0 -106
- data/test/test_lexical_uri.rb +0 -28
- data/test/test_one_of_condition.rb +0 -15
- data/test/test_parse_error.rb +0 -199
- data/test/test_property_parser.rb +0 -593
- data/test/test_selector_as_string.rb +0 -94
- data/test/test_selector_parser.rb +0 -178
- data/test/test_sibling_selector.rb +0 -42
- data/test/test_simple_selector.rb +0 -9
- data/test/test_specificity.rb +0 -76
- data/test/test_stylesheet.rb +0 -95
- data/test/test_token.rb +0 -24
- data/test/test_tokenizer.rb +0 -127
- data/test/test_xpath.rb +0 -105
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CSSPool
|
4
|
+
module SAC
|
5
|
+
class TestTerms < CSSPool::TestCase
|
6
|
+
def setup
|
7
|
+
@doc = MyDoc.new
|
8
|
+
@parser = CSSPool::SAC::Parser.new(@doc)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_hash_range
|
12
|
+
@parser.parse <<-eocss
|
13
|
+
div { border: #123; }
|
14
|
+
eocss
|
15
|
+
hash = @doc.properties.first[1].first
|
16
|
+
assert_equal '123', hash.value
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_rgb
|
20
|
+
@parser.parse <<-eocss
|
21
|
+
div { border: rgb(1,2,3); }
|
22
|
+
eocss
|
23
|
+
color = @doc.properties.first[1].first
|
24
|
+
assert_equal 1, color.red
|
25
|
+
assert_equal 2, color.green
|
26
|
+
assert_equal 3, color.blue
|
27
|
+
assert !color.percentage?
|
28
|
+
assert_match('rgb(1,2,3)', color.to_css)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_rgb_with_percentage
|
32
|
+
@parser.parse <<-eocss
|
33
|
+
div { border: rgb(100%,2%,3%); }
|
34
|
+
eocss
|
35
|
+
color = @doc.properties.first[1].first
|
36
|
+
assert_equal 100, color.red
|
37
|
+
assert_equal 2, color.green
|
38
|
+
assert_equal 3, color.blue
|
39
|
+
assert color.percentage?
|
40
|
+
assert_match('rgb(100%,2%,3%)', color.to_css)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_negative_number
|
44
|
+
@parser.parse <<-eocss
|
45
|
+
div { border: -1px; }
|
46
|
+
eocss
|
47
|
+
assert_equal 1, @doc.properties.length
|
48
|
+
size = @doc.properties.first[1].first
|
49
|
+
assert_equal :minus, size.unary_operator
|
50
|
+
assert_equal 1, size.value
|
51
|
+
assert_equal '-1.0px', size.to_s
|
52
|
+
assert_equal '-1.0px', size.to_css
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_positive_number
|
56
|
+
@parser.parse <<-eocss
|
57
|
+
div { border: 1px; }
|
58
|
+
eocss
|
59
|
+
assert_equal 1, @doc.properties.length
|
60
|
+
size = @doc.properties.first[1].first
|
61
|
+
assert_equal 1, size.value
|
62
|
+
assert_equal '1.0px', size.to_s
|
63
|
+
end
|
64
|
+
|
65
|
+
%w{
|
66
|
+
1 1em 1ex 1px 1in 1cm 1mm 1pt 1pc 1% 1deg 1rad 1ms 1s 1Hz 1kHz
|
67
|
+
}.each do |num|
|
68
|
+
expected = num.sub(/1/, '1.0')
|
69
|
+
define_method(:"test_num_#{num}") do
|
70
|
+
@parser.parse <<-eocss
|
71
|
+
div { border: #{num}; }
|
72
|
+
eocss
|
73
|
+
assert_equal 1, @doc.properties.length
|
74
|
+
size = @doc.properties.first[1].first
|
75
|
+
assert_equal 1, size.value
|
76
|
+
assert_equal expected, size.to_s
|
77
|
+
assert_equal expected, size.to_css
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_string_term
|
82
|
+
@parser.parse <<-eocss
|
83
|
+
div { border: "hello"; }
|
84
|
+
eocss
|
85
|
+
assert_equal 1, @doc.properties.length
|
86
|
+
string = @doc.properties.first[1].first
|
87
|
+
assert_equal 'hello', string.value
|
88
|
+
assert_equal '"hello"', string.to_css
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_inherit
|
92
|
+
@parser.parse <<-eocss
|
93
|
+
div { color: inherit; }
|
94
|
+
eocss
|
95
|
+
assert_equal 1, @doc.properties.length
|
96
|
+
string = @doc.properties.first[1].first
|
97
|
+
assert_equal 'inherit', string.value
|
98
|
+
assert_equal 'inherit', string.to_css
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_important
|
102
|
+
@parser.parse <<-eocss
|
103
|
+
div { color: inherit !important; }
|
104
|
+
eocss
|
105
|
+
assert_equal 1, @doc.properties.length
|
106
|
+
string = @doc.properties.first[1].first
|
107
|
+
assert_equal 'inherit', string.value
|
108
|
+
assert_equal 'inherit', string.to_css
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_function
|
112
|
+
@parser.parse <<-eocss
|
113
|
+
div { border: foo("hello"); }
|
114
|
+
eocss
|
115
|
+
assert_equal 1, @doc.properties.length
|
116
|
+
func = @doc.properties.first[1].first
|
117
|
+
assert_equal 'foo', func.name
|
118
|
+
assert_equal 1, func.params.length
|
119
|
+
assert_equal 'hello', func.params.first.value
|
120
|
+
assert_match 'foo("hello")', func.to_css
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_uri
|
124
|
+
@parser.parse <<-eocss
|
125
|
+
div { border: url(http://tenderlovemaking.com/); }
|
126
|
+
eocss
|
127
|
+
assert_equal 1, @doc.properties.length
|
128
|
+
url = @doc.properties.first[1].first
|
129
|
+
assert_equal 'http://tenderlovemaking.com/', url.value
|
130
|
+
assert_match 'url(http://tenderlovemaking.com/)', url.to_css
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CSSPool
|
4
|
+
class TestCollection < CSSPool::TestCase
|
5
|
+
def test_new
|
6
|
+
assert CSSPool::Collection.new
|
7
|
+
assert CSSPool::Collection.new { |url| }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_append
|
11
|
+
collection = CSSPool::Collection.new
|
12
|
+
collection << "div { background: green; }"
|
13
|
+
assert_equal 1, collection.length
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_collection_imports_stuff
|
17
|
+
called = false
|
18
|
+
collection = CSSPool::Collection.new do |url|
|
19
|
+
called = true
|
20
|
+
assert_equal 'hello.css', url
|
21
|
+
"div { background: red; }"
|
22
|
+
end
|
23
|
+
|
24
|
+
collection << '@import url(hello.css);'
|
25
|
+
assert called, "block was not called"
|
26
|
+
assert_equal 2, collection.length
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_collection_imports_imports_imports
|
30
|
+
css = {
|
31
|
+
'foo.css' => '@import url("bar.css");',
|
32
|
+
'bar.css' => '@import url("baz.css");',
|
33
|
+
'baz.css' => 'div { background: red; }',
|
34
|
+
}
|
35
|
+
|
36
|
+
collection = CSSPool::Collection.new do |url|
|
37
|
+
css[url] || raise
|
38
|
+
end
|
39
|
+
|
40
|
+
collection << '@import url(foo.css);'
|
41
|
+
assert_equal 4, collection.length
|
42
|
+
assert_nil collection.last.parent
|
43
|
+
assert_equal collection[-2].parent, collection.last
|
44
|
+
assert_equal collection[-3].parent, collection[-2]
|
45
|
+
assert_equal collection[-4].parent, collection[-3]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_load_only_once
|
49
|
+
css = {
|
50
|
+
'foo.css' => '@import url("foo.css");',
|
51
|
+
}
|
52
|
+
|
53
|
+
collection = CSSPool::Collection.new do |url|
|
54
|
+
css[url] || raise
|
55
|
+
end
|
56
|
+
|
57
|
+
collection << '@import url(foo.css);'
|
58
|
+
|
59
|
+
assert_equal 2, collection.length
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_each
|
63
|
+
css = {
|
64
|
+
'foo.css' => '@import url("foo.css");',
|
65
|
+
}
|
66
|
+
|
67
|
+
collection = CSSPool::Collection.new do |url|
|
68
|
+
css[url] || raise
|
69
|
+
end
|
70
|
+
|
71
|
+
collection << '@import url(foo.css);'
|
72
|
+
|
73
|
+
list = []
|
74
|
+
collection.each do |thing|
|
75
|
+
list << thing
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_equal 2, list.length
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/test/test_parser.rb
CHANGED
@@ -1,257 +1,91 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def teardown
|
9
|
-
flexmock_verify
|
10
|
-
flexmock_close
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_parse_rule
|
14
|
-
class << @sac.document_handler
|
15
|
-
attr_accessor :selector
|
16
|
-
alias :start_selector :selector=
|
3
|
+
module CSSPool
|
4
|
+
class TestParser < CSSPool::TestCase
|
5
|
+
def test_empty_doc_on_blank
|
6
|
+
assert CSSPool.CSS(nil)
|
7
|
+
assert CSSPool.CSS('')
|
17
8
|
end
|
18
|
-
@sac.parse('h1 > div { }')
|
19
|
-
|
20
|
-
expected_rule = @sac.document_handler.selector
|
21
|
-
assert expected_rule
|
22
|
-
|
23
|
-
rule = @sac.parse_rule('h1 > div')
|
24
|
-
assert rule
|
25
|
-
assert_equal 1, rule.length
|
26
|
-
assert_equal expected_rule, rule
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_page
|
30
|
-
flexmock(@sac.document_handler).
|
31
|
-
should_receive(:start_page).ordered.
|
32
|
-
with('foo', 'print').once
|
33
|
-
flexmock(@sac.document_handler).
|
34
|
-
should_receive(:property).ordered.with('color', on { |list|
|
35
|
-
list.length == 1 && list.first.dimension_unit_text.nil? &&
|
36
|
-
list.first.lexical_unit_type == :SAC_IDENT &&
|
37
|
-
list.first.string_value == "black" &&
|
38
|
-
list.first.integer_value.nil?
|
39
|
-
}, false).once
|
40
|
-
flexmock(@sac.document_handler).
|
41
|
-
should_receive(:end_page).ordered.
|
42
|
-
with('foo', 'print').once
|
43
|
-
@sac.parse('@page foo:print { color: black }')
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_empty
|
47
|
-
assert_nothing_raised {
|
48
|
-
@sac.parse('')
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_at_import
|
53
|
-
flexmock(@sac.document_handler).
|
54
|
-
should_receive(:import_style).ordered.
|
55
|
-
with('"subs.css"', []).once
|
56
|
-
@sac.parse('@import "subs.css";')
|
57
|
-
flexmock_verify
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_at_import_many_media
|
61
|
-
flexmock(@sac.document_handler).
|
62
|
-
should_receive(:import_style).ordered.
|
63
|
-
with('"subs.css"', ['paper', 'boobs']).once
|
64
|
-
@sac.parse('@import "subs.css" paper, boobs;')
|
65
|
-
flexmock_verify
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_multi_import
|
69
|
-
flexmock(@sac.document_handler).
|
70
|
-
should_receive(:import_style).ordered.
|
71
|
-
with('"subs.css"', []).once
|
72
|
-
flexmock(@sac.document_handler).
|
73
|
-
should_receive(:import_style).ordered.
|
74
|
-
with('"subs1.css"', []).once
|
75
|
-
@sac.parse('@import "subs.css"; @import "subs1.css";')
|
76
|
-
flexmock_verify
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_media
|
80
|
-
flexmock(@sac.document_handler).
|
81
|
-
should_receive(:start_media).ordered.
|
82
|
-
with(['print', 'tv']).once
|
83
|
-
flexmock(@sac.document_handler).
|
84
|
-
should_receive(:start_selector).ordered.once
|
85
|
-
flexmock(@sac.document_handler).
|
86
|
-
should_receive(:property).ordered.with('color', on { |list|
|
87
|
-
list.length == 1 && list.first.dimension_unit_text.nil? &&
|
88
|
-
list.first.lexical_unit_type == :SAC_IDENT &&
|
89
|
-
list.first.string_value == "black" &&
|
90
|
-
list.first.integer_value.nil?
|
91
|
-
}, false).once
|
92
|
-
flexmock(@sac.document_handler).
|
93
|
-
should_receive(:end_selector).ordered.once
|
94
|
-
flexmock(@sac.document_handler).
|
95
|
-
should_receive(:end_media).ordered.
|
96
|
-
with(['print', 'tv']).once
|
97
|
-
@sac.parse('@media print, tv { h1 { color: black } }')
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_media_single
|
101
|
-
flexmock(@sac.document_handler).
|
102
|
-
should_receive(:start_media).ordered.
|
103
|
-
with(['print']).once
|
104
|
-
flexmock(@sac.document_handler).
|
105
|
-
should_receive(:end_media).ordered.
|
106
|
-
with(['print']).once
|
107
|
-
@sac.parse('@media print { h1 { color: black } }')
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_comment
|
111
|
-
flexmock(@sac.document_handler).
|
112
|
-
should_receive(:comment).ordered.
|
113
|
-
with("/* sup bro */").once
|
114
|
-
@sac.parse('/* sup bro */')
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_weird
|
118
|
-
@sac.parse('#topnav legend { display: none; }')
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_ignorable_at_rule
|
122
|
-
flexmock(@sac.document_handler).
|
123
|
-
should_receive(:start_document).ordered.once
|
124
|
-
flexmock(@sac.document_handler).
|
125
|
-
should_receive(:ignorable_at_rule).ordered.
|
126
|
-
with("blah").once
|
127
|
-
flexmock(@sac.document_handler).
|
128
|
-
should_receive(:end_document).ordered.once
|
129
|
-
@sac.parse('@blah "style.css";')
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_selector
|
133
|
-
flexmock(@sac.document_handler).
|
134
|
-
should_receive(:start_document).ordered.once
|
135
|
-
flexmock(@sac.document_handler).
|
136
|
-
should_receive(:start_selector).ordered.once
|
137
|
-
flexmock(@sac.document_handler).
|
138
|
-
should_receive(:property).ordered.with('color', on { |list|
|
139
|
-
list.length == 1 && list.first.dimension_unit_text.nil? &&
|
140
|
-
list.first.lexical_unit_type == :SAC_IDENT &&
|
141
|
-
list.first.string_value == "black" &&
|
142
|
-
list.first.integer_value.nil?
|
143
|
-
}, false).once
|
144
|
-
flexmock(@sac.document_handler).
|
145
|
-
should_receive(:end_selector).ordered.once
|
146
|
-
flexmock(@sac.document_handler).
|
147
|
-
should_receive(:end_document).ordered.once
|
148
9
|
|
149
|
-
|
150
|
-
|
151
|
-
|
10
|
+
def test_doc_charset
|
11
|
+
doc = CSSPool.CSS <<-eocss
|
12
|
+
@charset "UTF-8";
|
13
|
+
@import url("foo.css") screen;
|
14
|
+
div#a, a.foo, a:hover, a[href][int="10"]{ background: red; }
|
15
|
+
eocss
|
16
|
+
assert_equal 'UTF-8', doc.charsets.first.name
|
17
|
+
end
|
152
18
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
19
|
+
def test_doc_parser
|
20
|
+
doc = CSSPool.CSS <<-eocss
|
21
|
+
@charset "UTF-8";
|
22
|
+
div#a, a.foo, a:hover, a[href][int="10"]{ background: red; }
|
23
|
+
eocss
|
24
|
+
|
25
|
+
assert_equal 1, doc.rule_sets.length
|
26
|
+
rule_set = doc.rule_sets.first
|
27
|
+
assert_equal 4, rule_set.selectors.length
|
28
|
+
assert_equal 1, rule_set.declarations.length
|
29
|
+
assert_equal 'background', rule_set.declarations.first.property
|
30
|
+
end
|
163
31
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
32
|
+
def test_media
|
33
|
+
doc = CSSPool.CSS <<-eocss
|
34
|
+
@media print {
|
35
|
+
div { background: red, blue; }
|
36
|
+
}
|
37
|
+
eocss
|
38
|
+
assert_equal 1, doc.rule_sets.first.media.length
|
39
|
+
end
|
169
40
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
}, false).once
|
177
|
-
@sac.parse('div h1 { border-spacing: -10em; }')
|
178
|
-
@sac.parse('div h1 { border: dashed black dotted; }')
|
179
|
-
flexmock_verify
|
180
|
-
end
|
41
|
+
def test_universal_to_css
|
42
|
+
doc = CSSPool.CSS <<-eocss
|
43
|
+
* { background: red, blue; }
|
44
|
+
eocss
|
45
|
+
assert_match '*', doc.to_css
|
46
|
+
end
|
181
47
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
list.first.parameters.map { |x| x.to_s } == %w{ 1in 1in 1in 2in } &&
|
190
|
-
list.first.integer_value.nil?
|
191
|
-
}, false).once
|
192
|
-
@sac.parse('div h1 { clip: rect(1in, 1in, 1in, 2in); }')
|
193
|
-
flexmock_verify
|
194
|
-
end
|
48
|
+
def test_doc_to_css
|
49
|
+
doc = CSSPool.CSS <<-eocss
|
50
|
+
div#a, a.foo, a:hover, a[href][int="10"]{ background: red, blue; }
|
51
|
+
eocss
|
52
|
+
assert_match 'div#a, a.foo, a:hover, a[href][int="10"]', doc.to_css
|
53
|
+
assert_match 'background: red, blue;', doc.to_css
|
54
|
+
end
|
195
55
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
list.first.integer_value.nil?
|
203
|
-
}, true).once
|
204
|
-
@sac.parse('h1 { color: black !important; }')
|
205
|
-
flexmock_verify
|
206
|
-
end
|
56
|
+
def test_doc_desc_to_css
|
57
|
+
doc = CSSPool.CSS <<-eocss
|
58
|
+
div > a { background: #123; }
|
59
|
+
eocss
|
60
|
+
assert_match 'div > a', doc.to_css
|
61
|
+
end
|
207
62
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
list.first.lexical_unit_type == :SAC_IDENT &&
|
215
|
-
list.first.string_value == "black" &&
|
216
|
-
list.first.integer_value.nil?
|
217
|
-
}, true).ordered.once
|
218
|
-
flexmock(@sac.document_handler).
|
219
|
-
should_receive(:end_selector).ordered.once
|
220
|
-
@sac.parse('h1:nth(1) { color: black !important; }')
|
221
|
-
flexmock_verify
|
222
|
-
end
|
63
|
+
def test_doc_pseudo_to_css
|
64
|
+
doc = CSSPool.CSS <<-eocss
|
65
|
+
:hover { background: #123; }
|
66
|
+
eocss
|
67
|
+
assert_match ':hover', doc.to_css
|
68
|
+
end
|
223
69
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
list.first.lexical_unit_type == :SAC_IDENT &&
|
231
|
-
list.first.string_value == "black" &&
|
232
|
-
list.first.integer_value.nil?
|
233
|
-
}, true).ordered.once
|
234
|
-
flexmock(@sac.document_handler).
|
235
|
-
should_receive(:end_selector).ordered.once
|
236
|
-
@sac.parse('a:hover { color: black !important; }')
|
237
|
-
flexmock_verify
|
238
|
-
end
|
70
|
+
def test_doc_id_to_css
|
71
|
+
doc = CSSPool.CSS <<-eocss
|
72
|
+
#hover { background: #123; }
|
73
|
+
eocss
|
74
|
+
assert_match '#hover', doc.to_css
|
75
|
+
end
|
239
76
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
77
|
+
def test_important
|
78
|
+
doc = CSSPool.CSS <<-eocss
|
79
|
+
div > a { background: #123 !important; }
|
80
|
+
eocss
|
81
|
+
assert_match '!important', doc.to_css
|
244
82
|
end
|
245
|
-
@sac.parse('a:hover { color: black !important; }')
|
246
|
-
assert_equal 'a:hover', @sac.document_handler.selectors.first.to_css
|
247
|
-
end
|
248
83
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
84
|
+
def test_doc_func_to_css
|
85
|
+
doc = CSSPool.CSS <<-eocss
|
86
|
+
div { border: foo(1, 2); }
|
87
|
+
eocss
|
88
|
+
assert_match('foo(1.0, 2.0)', doc.to_css)
|
253
89
|
end
|
254
|
-
@sac.parse('a:nth(3) { color: black !important; }')
|
255
|
-
assert_equal 'a:nth(3)', @sac.document_handler.selectors.first.to_css
|
256
90
|
end
|
257
91
|
end
|
data/test/test_selector.rb
CHANGED
@@ -1,36 +1,47 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module CSSPool
|
4
|
+
class TestSelector < CSSPool::TestCase
|
5
|
+
def test_specificity
|
6
|
+
doc = CSSPool.CSS <<-eocss
|
7
|
+
*, foo > bar, #hover, :hover, div#a, a.foo, a:hover, a[href][int="10"]{ background: red; }
|
8
|
+
eocss
|
9
|
+
selectors = doc.rule_sets.first.selectors
|
10
|
+
specs = selectors.map do |sel|
|
11
|
+
sel.specificity
|
12
|
+
end
|
13
|
+
assert_equal [[0, 0, 1],
|
14
|
+
[0, 0, 2],
|
15
|
+
[1, 0, 1],
|
16
|
+
[0, 1, 1],
|
17
|
+
[1, 0, 1],
|
18
|
+
[0, 1, 1],
|
19
|
+
[0, 1, 1],
|
20
|
+
[0, 2, 1]], specs
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_selector_knows_its_ruleset
|
24
|
+
doc = CSSPool.CSS <<-eocss
|
25
|
+
a[href][int="10"]{ background: red; }
|
26
|
+
eocss
|
27
|
+
rs = doc.rule_sets.first
|
28
|
+
assert_equal rs, rs.selectors.first.rule_set
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_selector_gets_declarations
|
32
|
+
doc = CSSPool.CSS <<-eocss
|
33
|
+
a[href][int="10"]{ background: red; }
|
34
|
+
eocss
|
35
|
+
rs = doc.rule_sets.first
|
36
|
+
assert_equal rs.declarations, rs.selectors.first.declarations
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_declaration_should_know_ruleset
|
40
|
+
doc = CSSPool.CSS <<-eocss
|
41
|
+
a[href][int="10"]{ background: red; }
|
42
|
+
eocss
|
43
|
+
rs = doc.rule_sets.first
|
44
|
+
rs.declarations.each { |del| assert_equal rs, del.rule_set }
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|