csscss 0.0.1 → 0.1.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 (53) hide show
  1. data/.gitignore +0 -1
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +39 -0
  5. data/README.md +47 -12
  6. data/bin/csscss +0 -1
  7. data/csscss.gemspec +2 -3
  8. data/lib/csscss/cli.rb +10 -1
  9. data/lib/csscss/json_reporter.rb +17 -0
  10. data/lib/csscss/parser/background.rb +72 -0
  11. data/lib/csscss/parser/base.rb +13 -0
  12. data/lib/csscss/parser/border.rb +45 -0
  13. data/lib/csscss/parser/border_color.rb +41 -0
  14. data/lib/csscss/parser/border_side.rb +91 -0
  15. data/lib/csscss/parser/border_style.rb +41 -0
  16. data/lib/csscss/parser/border_width.rb +37 -0
  17. data/lib/csscss/parser/color.rb +53 -0
  18. data/lib/csscss/parser/common.rb +86 -0
  19. data/lib/csscss/parser/css.rb +88 -0
  20. data/lib/csscss/parser/font.rb +96 -0
  21. data/lib/csscss/parser/list_style.rb +44 -0
  22. data/lib/csscss/parser/margin.rb +32 -0
  23. data/lib/csscss/parser/multi_side_transformer.rb +47 -0
  24. data/lib/csscss/parser/outline.rb +45 -0
  25. data/lib/csscss/parser/padding.rb +32 -0
  26. data/lib/csscss/parslet_optimizations.rb +77 -0
  27. data/lib/csscss/redundancy_analyzer.rb +75 -8
  28. data/lib/csscss/reporter.rb +2 -4
  29. data/lib/csscss/types.rb +77 -2
  30. data/lib/csscss/version.rb +1 -1
  31. data/lib/csscss.rb +22 -1
  32. data/test/csscss/json_reporter_test.rb +34 -0
  33. data/test/csscss/parser/background_test.rb +57 -0
  34. data/test/csscss/parser/border_color_test.rb +30 -0
  35. data/test/csscss/parser/border_side_test.rb +44 -0
  36. data/test/csscss/parser/border_style_test.rb +30 -0
  37. data/test/csscss/parser/border_test.rb +31 -0
  38. data/test/csscss/parser/border_width_test.rb +30 -0
  39. data/test/csscss/parser/color_test.rb +51 -0
  40. data/test/csscss/parser/common_test.rb +130 -0
  41. data/test/csscss/parser/css_test.rb +133 -0
  42. data/test/csscss/parser/font_test.rb +43 -0
  43. data/test/csscss/parser/list_style_test.rb +28 -0
  44. data/test/csscss/parser/margin_test.rb +50 -0
  45. data/test/csscss/parser/outline_test.rb +26 -0
  46. data/test/csscss/parser/padding_test.rb +50 -0
  47. data/test/csscss/redundancy_analyzer_test.rb +126 -4
  48. data/test/csscss/reporter_test.rb +4 -2
  49. data/test/csscss/types_test.rb +73 -0
  50. data/test/just_parse.rb +8 -0
  51. data/test/test_helper.rb +49 -6
  52. metadata +61 -23
  53. data/.rspec.default +0 -1
@@ -1,3 +1,3 @@
1
1
  module Csscss
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/csscss.rb CHANGED
@@ -1,11 +1,32 @@
1
1
  require "stringio"
2
2
  require "optparse"
3
+ require "json"
3
4
 
4
5
  require "parslet"
5
- require "csspool"
6
+ require "csscss/parslet_optimizations"
6
7
 
7
8
  require "csscss/version"
8
9
  require "csscss/cli"
9
10
  require "csscss/types"
10
11
  require "csscss/redundancy_analyzer"
11
12
  require "csscss/reporter"
13
+ require "csscss/json_reporter"
14
+
15
+ require "csscss/parser/common"
16
+ require "csscss/parser/color"
17
+ require "csscss/parser/base"
18
+ require "csscss/parser/multi_side_transformer"
19
+
20
+ require "csscss/parser/css"
21
+ require "csscss/parser/background"
22
+ require "csscss/parser/list_style"
23
+ require "csscss/parser/margin"
24
+ require "csscss/parser/padding"
25
+ require "csscss/parser/border_width"
26
+ require "csscss/parser/border_color"
27
+ require "csscss/parser/border_style"
28
+ require "csscss/parser/border_side"
29
+ require "csscss/parser/border"
30
+ require "csscss/parser/outline"
31
+ require "csscss/parser/font"
32
+
@@ -0,0 +1,34 @@
1
+ require "test_helper"
2
+
3
+ module Csscss
4
+ describe JSONReporter do
5
+ include TypeHelpers
6
+
7
+ it "formats json result" do
8
+ reporter = JSONReporter.new({
9
+ [sel(".foo"), sel(".bar")] => [dec("width", "1px"), dec("border", "black")],
10
+ [sel("h1, h2"), sel(".foo"), sel(".baz")] => [dec("display", "none")],
11
+ [sel("h1, h2"), sel(".bar")] => [dec("position", "relative")]
12
+ })
13
+
14
+ expected = [
15
+ {
16
+ "selectors" => %w(.foo .bar),
17
+ "count" => 2,
18
+ "declarations" => ["width: 1px", "border: black"]
19
+ },
20
+ {
21
+ "selectors" => ["h1, h2", ".foo", ".baz"],
22
+ "count" => 1,
23
+ "declarations" => ["display: none"]
24
+ },
25
+ {
26
+ "selectors" => ["h1, h2", ".bar"],
27
+ "count" => 1,
28
+ "declarations" => ["position: relative"]
29
+ },
30
+ ]
31
+ reporter.report.must_equal JSON.dump(expected)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,57 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module Background
5
+ describe Background do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "parses position" do
14
+ @parser.bg_position.must_parse("10.2%")
15
+ @parser.bg_position.must_parse("left")
16
+ @parser.bg_position.must_parse("44em")
17
+ @parser.bg_position.must_parse("left 11%")
18
+ @parser.bg_position.must_parse("left bottom")
19
+ @parser.bg_position.must_parse("inherit")
20
+ @parser.bg_position.must_parse("bottom")
21
+ @parser.bg_position.wont_parse("bottom left")
22
+ @parser.bg_position.wont_parse("inherit bottom")
23
+ end
24
+
25
+ it "converts shorthand rules to longhand" do
26
+ trans("rgb(111, 222, 333) none repeat-x scroll").must_equal([
27
+ dec("background-color", "rgb(111, 222, 333)"),
28
+ dec("background-image", "none"),
29
+ dec("background-repeat", "repeat-x"),
30
+ dec("background-attachment", "scroll")
31
+ ])
32
+
33
+ trans("inherit none inherit 10% bottom").must_equal([
34
+ dec("background-color", "inherit"),
35
+ dec("background-image", "none"),
36
+ dec("background-repeat", "inherit"),
37
+ dec("background-position", "10% bottom")
38
+ ])
39
+
40
+ trans("#fff url(http://foo.com/bar.jpg) bottom").must_equal([
41
+ dec("background-color", "#fff"),
42
+ dec("background-image", "url(http://foo.com/bar.jpg)"),
43
+ dec("background-position", "bottom")
44
+ ])
45
+
46
+ trans("#fff").must_equal([dec("background-color", "#fff")])
47
+ trans("BLACK").must_equal([dec("background-color", "black")])
48
+ end
49
+
50
+ it "tries the parse and returns false if it doesn't work" do
51
+ @parser.try_parse("foo").must_equal(false)
52
+ parsed = @parser.try_parse("black")
53
+ parsed[:background][:bg_color].must_equal(color:{keyword:"black"})
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module BorderColor
5
+ describe BorderColor do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "converts shorthand rules to longhand" do
14
+ trans("#fff transparent black rgb(1, 2, 3)").must_equal([
15
+ dec("border-top-color", "#fff"),
16
+ dec("border-right-color", "transparent"),
17
+ dec("border-bottom-color", "black"),
18
+ dec("border-left-color", "rgb(1, 2, 3)")
19
+ ])
20
+
21
+ trans("#fff black").must_equal([
22
+ dec("border-top-color", "#fff"),
23
+ dec("border-right-color", "black"),
24
+ dec("border-bottom-color", "#fff"),
25
+ dec("border-left-color", "black")
26
+ ])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module BorderSide
5
+ describe self do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new("top")
10
+ end
11
+
12
+ def trans_top(s)
13
+ Transformer.new.apply(@parser.parse(s))
14
+ end
15
+ alias_method :trans, :trans_top
16
+
17
+ def trans_bottom(s)
18
+ Transformer.new.apply(Parser.new("bottom").parse(s))
19
+ end
20
+
21
+ it "converts shorthand rules to longhand" do
22
+ trans_top("thin").must_equal([
23
+ dec("border-top-width", "thin")
24
+ ])
25
+
26
+ trans_bottom("rgb(1, 2, 3)").must_equal([
27
+ dec("border-bottom-color", "rgb(1, 2, 3)")
28
+ ])
29
+
30
+ trans_top("thin solid #fff").must_equal([
31
+ dec("border-top-width", "thin"),
32
+ dec("border-top-style", "solid"),
33
+ dec("border-top-color", "#fff")
34
+ ])
35
+
36
+ trans_bottom("thin solid #fff").must_equal([
37
+ dec("border-bottom-width", "thin"),
38
+ dec("border-bottom-style", "solid"),
39
+ dec("border-bottom-color", "#fff")
40
+ ])
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module BorderStyle
5
+ describe BorderStyle do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "converts shorthand rules to longhand" do
14
+ trans("none dashed solid ridge").must_equal([
15
+ dec("border-top-style", "none"),
16
+ dec("border-right-style", "dashed"),
17
+ dec("border-bottom-style", "solid"),
18
+ dec("border-left-style", "ridge")
19
+ ])
20
+
21
+ trans("none dashed").must_equal([
22
+ dec("border-top-style", "none"),
23
+ dec("border-right-style", "dashed"),
24
+ dec("border-bottom-style", "none"),
25
+ dec("border-left-style", "dashed")
26
+ ])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module Border
5
+ describe Border do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "converts shorthand rules to longhand" do
14
+ trans("1px solid #fff").must_equal([
15
+ dec("border-top-width", "1px"),
16
+ dec("border-top-style", "solid"),
17
+ dec("border-top-color", "#fff"),
18
+ dec("border-right-width", "1px"),
19
+ dec("border-right-style", "solid"),
20
+ dec("border-right-color", "#fff"),
21
+ dec("border-bottom-width", "1px"),
22
+ dec("border-bottom-style", "solid"),
23
+ dec("border-bottom-color", "#fff"),
24
+ dec("border-left-width", "1px"),
25
+ dec("border-left-style", "solid"),
26
+ dec("border-left-color", "#fff")
27
+ ])
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module BorderWidth
5
+ describe BorderWidth do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "converts shorthand rules to longhand" do
14
+ trans("thin thick inherit 10em").must_equal([
15
+ dec("border-top-width", "thin"),
16
+ dec("border-right-width", "thick"),
17
+ dec("border-bottom-width", "inherit"),
18
+ dec("border-left-width", "10em")
19
+ ])
20
+
21
+ trans("thin thick").must_equal([
22
+ dec("border-top-width", "thin"),
23
+ dec("border-right-width", "thick"),
24
+ dec("border-bottom-width", "thin"),
25
+ dec("border-left-width", "thick")
26
+ ])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,51 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ describe Color do
5
+ class ColorTest
6
+ include Color
7
+ end
8
+
9
+ before { @parser = ColorTest.new }
10
+
11
+ describe "color" do
12
+ it "parses color" do
13
+ @parser.color.must_parse "rgb(123, 222, 444)"
14
+ @parser.color.must_parse "rgb(123%, 222%, 444%)"
15
+ @parser.color.must_parse "#ffffff"
16
+ @parser.color.must_parse "inherit"
17
+ @parser.color.must_parse "black"
18
+ end
19
+ end
20
+
21
+ describe "individual rules" do
22
+ it "parses rgb number color" do
23
+ @parser.rgb.must_parse "rgb(123, 222, 444)"
24
+ @parser.rgb.must_parse "rgb ( 123 , 222 , 444 ) "
25
+ @parser.rgb.wont_parse "rgb(1aa, 222, 444)"
26
+ end
27
+
28
+ it "parses rgb percentage color" do
29
+ @parser.rgb.must_parse "rgb(123%, 222%, 444%)"
30
+ @parser.rgb.must_parse "rgb ( 123% , 222% , 444% ) "
31
+ @parser.rgb.wont_parse "rgb(1aa%, 222%, 444%)"
32
+ end
33
+
34
+ it "parses hex colors" do
35
+ @parser.hexcolor.must_parse "#ffffff"
36
+ @parser.hexcolor.must_parse "#ffffff "
37
+ @parser.hexcolor.must_parse "#fff "
38
+ @parser.hexcolor.must_parse "#fFF123"
39
+ @parser.hexcolor.wont_parse "fFF123"
40
+ end
41
+
42
+ it "parses keyword colors" do
43
+ @parser.color_keyword.must_parse "inherit"
44
+ @parser.color_keyword.must_parse "inherit "
45
+
46
+ @parser.color_keyword.must_parse "black"
47
+ @parser.color_keyword.must_parse "BLACK"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,130 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ describe Common do
5
+ class CommonTest
6
+ include Common
7
+ end
8
+
9
+ before { @parser = CommonTest.new }
10
+
11
+ describe "#stri" do
12
+ it "parses case insensitive strings" do
13
+ @parser.stri("a").must_parse "a"
14
+ @parser.stri("A").must_parse "a"
15
+ @parser.stri("A").wont_parse "b"
16
+
17
+ @parser.stri("This too shall pass").must_parse "this TOO shall PASS"
18
+ @parser.stri("[").must_parse "["
19
+ end
20
+ end
21
+
22
+ describe "#spaces" do
23
+ it "parses series of spaces" do
24
+ @parser.space.must_parse " "
25
+ @parser.space.must_parse " "
26
+ @parser.space.must_parse "\n"
27
+ @parser.space.wont_parse " a"
28
+
29
+ @parser.space.wont_parse ""
30
+ @parser.space?.must_parse ""
31
+ end
32
+ end
33
+
34
+ describe "#symbol" do
35
+ it "parses case insensitive characters followed by spaces" do
36
+ @parser.symbol("foo").must_parse "foo"
37
+ @parser.symbol("foo").must_parse "foo "
38
+ @parser.symbol("foo").must_parse "Foo "
39
+ @parser.symbol("foo").wont_parse " Foo "
40
+ end
41
+
42
+ it "optionally captures input" do
43
+ parsed = @parser.symbol("foo", :foo).parse("Foo ")
44
+ parsed[:foo].must_equal "Foo"
45
+ end
46
+ end
47
+
48
+ describe "between and helpers" do
49
+ it "parses characters surrounded" do
50
+ @parser.between("[", "]") { @parser.symbol("foo") }.must_parse "[foo]"
51
+ end
52
+
53
+ it "parses input surrounded by parens" do
54
+ @parser.parens { @parser.symbol("foo") }.must_parse "(foo)"
55
+ @parser.parens { @parser.symbol("foo") }.must_parse "(FOo) "
56
+ @parser.parens { @parser.symbol("foo") }.must_parse "(FOo ) "
57
+ @parser.parens { @parser.symbol("food") }.wont_parse "(FOo"
58
+ end
59
+
60
+ it "parses input surrounded by double quotes" do
61
+ @parser.double_quoted { @parser.symbol("foo") }.must_parse %("foo")
62
+ @parser.double_quoted { @parser.symbol("foo") }.must_parse %("FOo ")
63
+ @parser.double_quoted { @parser.symbol("foo") }.must_parse %("FOo " )
64
+ @parser.double_quoted { @parser.symbol("food") }.wont_parse %("FOo)
65
+ end
66
+
67
+ it "parses input surrounded by single quotes" do
68
+ @parser.single_quoted { @parser.symbol('foo') }.must_parse %('foo')
69
+ @parser.single_quoted { @parser.symbol('foo') }.must_parse %('FOo ')
70
+ @parser.single_quoted { @parser.symbol('foo') }.must_parse %('FOo ' )
71
+ @parser.single_quoted { @parser.symbol('food') }.wont_parse %('FOo)
72
+ end
73
+ end
74
+
75
+ describe "number and numbers" do
76
+ it "parses single numbers" do
77
+ @parser.number.must_parse "1"
78
+ @parser.number.wont_parse "12"
79
+ @parser.number.wont_parse "a"
80
+ @parser.number.wont_parse "1 "
81
+ end
82
+
83
+ it "parses multiple numbers" do
84
+ @parser.numbers.must_parse "1"
85
+ @parser.numbers.must_parse "12"
86
+ @parser.numbers.wont_parse "12 "
87
+ @parser.numbers.wont_parse "1223a"
88
+ end
89
+
90
+ it "parses decimals" do
91
+ @parser.decimal.must_parse "1"
92
+ @parser.decimal.must_parse "12"
93
+ @parser.decimal.must_parse "12."
94
+ @parser.decimal.must_parse "12.0123"
95
+ @parser.decimal.wont_parse "1223a"
96
+ end
97
+
98
+ it "parses percentages" do
99
+ @parser.percent.must_parse "100%"
100
+ @parser.percent.must_parse "100% "
101
+ @parser.percent.must_parse "100.344%"
102
+ @parser.percent.wont_parse "100 %"
103
+ end
104
+
105
+ it "parses lengths" do
106
+ @parser.length.must_parse "123px"
107
+ @parser.length.must_parse "123EM"
108
+ @parser.length.must_parse "1.23Pt"
109
+ end
110
+ end
111
+
112
+ describe "url" do
113
+ it "parses http" do
114
+ @parser.http.must_parse "foo.jpg"
115
+ @parser.http.must_parse 'foo\(bar\).jpg'
116
+ @parser.http.must_parse 'http://foo\(bar\).jpg'
117
+ @parser.http.must_parse 'http://foo.com/baz/\(bar\).jpg'
118
+ end
119
+
120
+ it "parses urls" do
121
+ @parser.url.must_parse "url(foo.jpg)"
122
+ @parser.url.must_parse "url( foo.jpg )"
123
+ @parser.url.must_parse 'url("foo.jpg")'
124
+ @parser.url.must_parse "url('foo.jpg')"
125
+ @parser.url.must_parse "url('foo.jpg' )"
126
+ @parser.url.must_parse 'url(foo\(bar\).jpg)'
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,133 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module Css
5
+ describe self do
6
+ include CommonParserTests::Helpers
7
+ include TypeHelpers
8
+
9
+ before do
10
+ @parser = Parser.new
11
+ @trans = Transformer.new
12
+ end
13
+
14
+ describe "parsing" do
15
+ it "parses css" do
16
+ @parser.must_parse "h1 { display: none }"
17
+ @parser.must_parse "\nh1 { display: none; }"
18
+ @parser.must_parse %$
19
+ .bar { border: 1px solid black }
20
+ $
21
+
22
+ @parser.wont_parse ""
23
+ end
24
+
25
+ it "parses comments" do
26
+ @parser.css_space?.must_parse "/* foo */"
27
+ @parser.css_space?.must_parse %$
28
+ /* foo
29
+ * bar
30
+ */
31
+ $
32
+
33
+ @parser.css_space?.must_parse %$
34
+ /* foo */
35
+ /* bar */
36
+ $
37
+ end
38
+ end
39
+
40
+ it "transforms css" do
41
+ css = %$
42
+ h1, h2 { display: none; position: relative; outline:none}
43
+ .foo { display: none; width: 1px }
44
+ .bar { border: 1px solid black }
45
+ .baz {
46
+ background-color: black;
47
+ background-style: solid
48
+ }
49
+ $
50
+
51
+ trans(css).must_equal([
52
+ rs(sel("h1, h2"), [dec("display", "none"), dec("position", "relative"), dec("outline", "none")]),
53
+ rs(sel(".foo"), [dec("display", "none"), dec("width", "1px")]),
54
+ rs(sel(".bar"), [dec("border", "1px solid black")]),
55
+ rs(sel(".baz"), [dec("background-color", "black"), dec("background-style", "solid")])
56
+ ])
57
+ end
58
+
59
+ it "skips comments" do
60
+ css = %$
61
+ /* some comment
62
+ * foo
63
+ */
64
+ .bar { border: 1px solid black /* sdflk */ }
65
+ .baz { background: white /* sdflk */ }
66
+ $
67
+
68
+ trans(css).must_equal([
69
+ rs(sel(".bar"), [dec("border", "1px solid black /* sdflk */")]),
70
+ rs(sel(".baz"), [dec("background", "white /* sdflk */")])
71
+ ])
72
+ end
73
+
74
+ it "skips rules that are commented out" do
75
+ css = %$
76
+ /*
77
+ bar { border: 1px solid black }
78
+ */
79
+
80
+ /* foo */
81
+ .baz {
82
+ background: white;
83
+ /* bar */
84
+ border: 1px;
85
+ }
86
+ $
87
+
88
+ trans(css).must_equal([
89
+ rs(sel(".baz"), [dec("background", "white"), dec("border", "1px")])
90
+ ])
91
+ end
92
+
93
+ it "parses commented attributes" do
94
+ css = %$
95
+ .foo {
96
+ /*
97
+ some comment
98
+ */
99
+ }
100
+ $
101
+
102
+ trans(css).must_equal([
103
+ rs(sel(".foo"), [])
104
+ ])
105
+ end
106
+
107
+ it "recognizes media queries" do
108
+ css = %$
109
+ @media only screen {
110
+ /* some comment */
111
+ #foo {
112
+ background-color: black;
113
+ }
114
+
115
+ #bar {
116
+ display: none;
117
+ }
118
+ }
119
+
120
+ h1 {
121
+ outline: 1px;
122
+ }
123
+ $
124
+
125
+ trans(css).must_equal([
126
+ rs(sel("#foo"), [dec("background-color", "black")]),
127
+ rs(sel("#bar"), [dec("display", "none")]),
128
+ rs(sel("h1"), [dec("outline", "1px")])
129
+ ])
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module Font
5
+ describe self do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "converts shorthand rules to longhand" do
14
+ trans("10% Gill, 'Lucida Sans'").must_equal([
15
+ dec("font-size", "10%"),
16
+ dec("font-family", "Gill, 'Lucida Sans'")
17
+ ])
18
+
19
+ trans("normal small-caps 100 10% / 33 Gill, Helvetica, \"Lucida Sans\", cursive").must_equal([
20
+ dec("font-style", "normal"),
21
+ dec("font-variant", "small-caps"),
22
+ dec("font-weight", "100"),
23
+ dec("font-size", "10%"),
24
+ dec("line-height", "33"),
25
+ dec("font-family", 'Gill, Helvetica, "Lucida Sans", cursive')
26
+ ])
27
+ end
28
+
29
+ it "parses font family" do
30
+ @parser.font_family.must_parse("\"Lucida\"")
31
+ @parser.font_family.must_parse("\"Lucida Sans\"")
32
+ @parser.font_family.must_parse("Gill")
33
+ @parser.font_family.must_parse('Gill, Helvetica, "Lucida Sans", cursive')
34
+ end
35
+
36
+ it "ignores literal fonts" do
37
+ trans("caption").must_equal([])
38
+ trans("icon").must_equal([])
39
+ trans("menu").must_equal([])
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ require "test_helper"
2
+
3
+ module Csscss::Parser
4
+ module ListStyle
5
+ describe ListStyle do
6
+ include CommonParserTests
7
+
8
+ before do
9
+ @parser = Parser.new
10
+ @trans = Transformer.new
11
+ end
12
+
13
+ it "converts shorthand rules to longhand" do
14
+ trans("circle outside url('foo.jpg')").must_equal([
15
+ dec("list-style-type", "circle"),
16
+ dec("list-style-position", "outside"),
17
+ dec("list-style-image", "url('foo.jpg')")
18
+ ])
19
+ end
20
+
21
+ it "tries the parse and returns false if it doesn't work" do
22
+ @parser.try_parse("foo").must_equal(false)
23
+ parsed = @parser.try_parse("circle")
24
+ parsed[:list_style][:list_style_type].must_equal(type:"circle")
25
+ end
26
+ end
27
+ end
28
+ end