sass 3.1.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +11 -0
- data/CONTRIBUTING +3 -0
- data/EDGE_GEM_VERSION +1 -0
- data/MIT-LICENSE +20 -0
- data/README.md +201 -0
- data/REVISION +1 -0
- data/Rakefile +353 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/css2sass +13 -0
- data/bin/sass +8 -0
- data/bin/sass-convert +7 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass.rb +71 -0
- data/lib/sass/cache_store.rb +208 -0
- data/lib/sass/callbacks.rb +66 -0
- data/lib/sass/css.rb +294 -0
- data/lib/sass/engine.rb +792 -0
- data/lib/sass/environment.rb +143 -0
- data/lib/sass/error.rb +201 -0
- data/lib/sass/exec.rb +619 -0
- data/lib/sass/importers.rb +22 -0
- data/lib/sass/importers/base.rb +138 -0
- data/lib/sass/importers/filesystem.rb +121 -0
- data/lib/sass/less.rb +363 -0
- data/lib/sass/plugin.rb +126 -0
- data/lib/sass/plugin/compiler.rb +346 -0
- data/lib/sass/plugin/configuration.rb +123 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +47 -0
- data/lib/sass/plugin/rails.rb +41 -0
- data/lib/sass/plugin/staleness_checker.rb +145 -0
- data/lib/sass/railtie.rb +8 -0
- data/lib/sass/repl.rb +58 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script.rb +63 -0
- data/lib/sass/script/bool.rb +18 -0
- data/lib/sass/script/color.rb +490 -0
- data/lib/sass/script/css_lexer.rb +29 -0
- data/lib/sass/script/css_parser.rb +31 -0
- data/lib/sass/script/funcall.rb +78 -0
- data/lib/sass/script/functions.rb +852 -0
- data/lib/sass/script/interpolation.rb +70 -0
- data/lib/sass/script/lexer.rb +337 -0
- data/lib/sass/script/literal.rb +236 -0
- data/lib/sass/script/node.rb +101 -0
- data/lib/sass/script/number.rb +420 -0
- data/lib/sass/script/operation.rb +92 -0
- data/lib/sass/script/parser.rb +392 -0
- data/lib/sass/script/string.rb +67 -0
- data/lib/sass/script/string_interpolation.rb +93 -0
- data/lib/sass/script/unary_operation.rb +57 -0
- data/lib/sass/script/variable.rb +48 -0
- data/lib/sass/scss.rb +17 -0
- data/lib/sass/scss/css_parser.rb +51 -0
- data/lib/sass/scss/parser.rb +838 -0
- data/lib/sass/scss/rx.rb +126 -0
- data/lib/sass/scss/sass_parser.rb +11 -0
- data/lib/sass/scss/script_lexer.rb +15 -0
- data/lib/sass/scss/script_parser.rb +25 -0
- data/lib/sass/scss/static_parser.rb +40 -0
- data/lib/sass/selector.rb +361 -0
- data/lib/sass/selector/abstract_sequence.rb +62 -0
- data/lib/sass/selector/comma_sequence.rb +82 -0
- data/lib/sass/selector/sequence.rb +236 -0
- data/lib/sass/selector/simple.rb +113 -0
- data/lib/sass/selector/simple_sequence.rb +135 -0
- data/lib/sass/shared.rb +78 -0
- data/lib/sass/tree/comment_node.rb +128 -0
- data/lib/sass/tree/debug_node.rb +36 -0
- data/lib/sass/tree/directive_node.rb +75 -0
- data/lib/sass/tree/extend_node.rb +65 -0
- data/lib/sass/tree/for_node.rb +67 -0
- data/lib/sass/tree/if_node.rb +81 -0
- data/lib/sass/tree/import_node.rb +124 -0
- data/lib/sass/tree/mixin_def_node.rb +60 -0
- data/lib/sass/tree/mixin_node.rb +123 -0
- data/lib/sass/tree/node.rb +490 -0
- data/lib/sass/tree/prop_node.rb +220 -0
- data/lib/sass/tree/root_node.rb +125 -0
- data/lib/sass/tree/rule_node.rb +273 -0
- data/lib/sass/tree/variable_node.rb +39 -0
- data/lib/sass/tree/warn_node.rb +42 -0
- data/lib/sass/tree/while_node.rb +48 -0
- data/lib/sass/util.rb +687 -0
- data/lib/sass/util/subset_map.rb +101 -0
- data/lib/sass/version.rb +109 -0
- data/rails/init.rb +1 -0
- data/test/sass/cache_test.rb +74 -0
- data/test/sass/callbacks_test.rb +61 -0
- data/test/sass/conversion_test.rb +1210 -0
- data/test/sass/css2sass_test.rb +364 -0
- data/test/sass/data/hsl-rgb.txt +319 -0
- data/test/sass/engine_test.rb +2273 -0
- data/test/sass/extend_test.rb +1348 -0
- data/test/sass/functions_test.rb +565 -0
- data/test/sass/importer_test.rb +104 -0
- data/test/sass/less_conversion_test.rb +632 -0
- data/test/sass/mock_importer.rb +49 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +430 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +86 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/import.css +31 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/options.css +1 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/scss_import.css +31 -0
- data/test/sass/results/scss_importee.css +2 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +254 -0
- data/test/sass/script_test.rb +459 -0
- data/test/sass/scss/css_test.rb +897 -0
- data/test/sass/scss/rx_test.rb +156 -0
- data/test/sass/scss/scss_test.rb +1088 -0
- data/test/sass/scss/test_helper.rb +37 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +305 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/import.sass +12 -0
- data/test/sass/templates/importee.less +2 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/sass/templates/options.sass +2 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/scss_import.scss +11 -0
- data/test/sass/templates/scss_importee.scss +1 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/sass/templates/warn.sass +3 -0
- data/test/sass/templates/warn_imported.sass +4 -0
- data/test/sass/test_helper.rb +8 -0
- data/test/sass/util/subset_map_test.rb +91 -0
- data/test/sass/util_test.rb +275 -0
- data/test/test_helper.rb +64 -0
- data/vendor/fssm/LICENSE +20 -0
- data/vendor/fssm/README.markdown +55 -0
- data/vendor/fssm/Rakefile +59 -0
- data/vendor/fssm/VERSION.yml +5 -0
- data/vendor/fssm/example.rb +9 -0
- data/vendor/fssm/fssm.gemspec +77 -0
- data/vendor/fssm/lib/fssm.rb +33 -0
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
- data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
- data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
- data/vendor/fssm/lib/fssm/monitor.rb +26 -0
- data/vendor/fssm/lib/fssm/path.rb +91 -0
- data/vendor/fssm/lib/fssm/pathname.rb +502 -0
- data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
- data/vendor/fssm/lib/fssm/state/file.rb +24 -0
- data/vendor/fssm/lib/fssm/support.rb +63 -0
- data/vendor/fssm/lib/fssm/tree.rb +176 -0
- data/vendor/fssm/profile/prof-cache.rb +40 -0
- data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
- data/vendor/fssm/profile/prof-pathname.rb +68 -0
- data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
- data/vendor/fssm/profile/prof.html +2379 -0
- data/vendor/fssm/spec/path_spec.rb +75 -0
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +14 -0
- metadata +297 -0
@@ -0,0 +1,565 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
4
|
+
require 'sass/script'
|
5
|
+
|
6
|
+
module Sass::Script::Functions::UserFunctions
|
7
|
+
def call_options_on_new_literal
|
8
|
+
str = Sass::Script::String.new("foo")
|
9
|
+
str.options[:foo]
|
10
|
+
str
|
11
|
+
end
|
12
|
+
|
13
|
+
def user_defined
|
14
|
+
Sass::Script::String.new("I'm a user-defined string!")
|
15
|
+
end
|
16
|
+
|
17
|
+
def _preceding_underscore
|
18
|
+
Sass::Script::String.new("I'm another user-defined string!")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class SassFunctionTest < Test::Unit::TestCase
|
23
|
+
# Tests taken from:
|
24
|
+
# http://www.w3.org/Style/CSS/Test/CSS3/Color/20070927/html4/t040204-hsl-h-rotating-b.htm
|
25
|
+
# http://www.w3.org/Style/CSS/Test/CSS3/Color/20070927/html4/t040204-hsl-values-b.htm
|
26
|
+
File.read(File.dirname(__FILE__) + "/data/hsl-rgb.txt").split("\n\n").each do |chunk|
|
27
|
+
hsls, rgbs = chunk.strip.split("====")
|
28
|
+
hsls.strip.split("\n").zip(rgbs.strip.split("\n")) do |hsl, rgb|
|
29
|
+
hsl_method = "test_hsl: #{hsl} = #{rgb}"
|
30
|
+
define_method(hsl_method) do
|
31
|
+
assert_equal(evaluate(rgb), evaluate(hsl))
|
32
|
+
end
|
33
|
+
|
34
|
+
rgb_to_hsl_method = "test_rgb_to_hsl: #{rgb} = #{hsl}"
|
35
|
+
define_method(rgb_to_hsl_method) do
|
36
|
+
rgb_color = perform(rgb)
|
37
|
+
hsl_color = perform(hsl)
|
38
|
+
|
39
|
+
white = hsl_color.lightness == 100
|
40
|
+
black = hsl_color.lightness == 0
|
41
|
+
grayscale = white || black || hsl_color.saturation == 0
|
42
|
+
|
43
|
+
assert_in_delta(hsl_color.hue, rgb_color.hue, 0.0001,
|
44
|
+
"Hues should be equal") unless grayscale
|
45
|
+
assert_in_delta(hsl_color.saturation, rgb_color.saturation, 0.0001,
|
46
|
+
"Saturations should be equal") unless white || black
|
47
|
+
assert_in_delta(hsl_color.lightness, rgb_color.lightness, 0.0001,
|
48
|
+
"Lightnesses should be equal")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_hsl_checks_bounds
|
54
|
+
assert_error_message("Saturation -114 must be between 0% and 100% for `hsl'", "hsl(10, -114, 12)");
|
55
|
+
assert_error_message("Lightness 256 must be between 0% and 100% for `hsl'", "hsl(10, 10, 256%)");
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_hsl_checks_types
|
59
|
+
assert_error_message("\"foo\" is not a number for `hsl'", "hsl(\"foo\", 10, 12)");
|
60
|
+
assert_error_message("\"foo\" is not a number for `hsl'", "hsl(10, \"foo\", 12)");
|
61
|
+
assert_error_message("\"foo\" is not a number for `hsl'", "hsl(10, 10, \"foo\")");
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_hsla
|
65
|
+
assert_equal "rgba(51, 204, 204, 0.4)", evaluate("hsla(180, 60%, 50%, 0.4)")
|
66
|
+
assert_equal "#33cccc", evaluate("hsla(180, 60%, 50%, 1)")
|
67
|
+
assert_equal "rgba(51, 204, 204, 0)", evaluate("hsla(180, 60%, 50%, 0)")
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_hsla_checks_bounds
|
71
|
+
assert_error_message("Saturation -114 must be between 0% and 100% for `hsla'", "hsla(10, -114, 12, 1)");
|
72
|
+
assert_error_message("Lightness 256 must be between 0% and 100% for `hsla'", "hsla(10, 10, 256%, 0)");
|
73
|
+
assert_error_message("Alpha channel -0.1 must be between 0 and 1 for `hsla'", "hsla(10, 10, 10, -0.1)");
|
74
|
+
assert_error_message("Alpha channel 1.1 must be between 0 and 1 for `hsla'", "hsla(10, 10, 10, 1.1)");
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_hsla_checks_types
|
78
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(\"foo\", 10, 12, 0.3)");
|
79
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(10, \"foo\", 12, 0)");
|
80
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(10, 10, \"foo\", 1)");
|
81
|
+
assert_error_message("\"foo\" is not a number for `hsla'", "hsla(10, 10, 10, \"foo\")");
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_percentage
|
85
|
+
assert_equal("50%", evaluate("percentage(.5)"))
|
86
|
+
assert_equal("100%", evaluate("percentage(1)"))
|
87
|
+
assert_equal("25%", evaluate("percentage(25px / 100px)"))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_percentage_checks_types
|
91
|
+
assert_error_message("25px is not a unitless number for `percentage'", "percentage(25px)")
|
92
|
+
assert_error_message("#cccccc is not a unitless number for `percentage'", "percentage(#ccc)")
|
93
|
+
assert_error_message("\"string\" is not a unitless number for `percentage'", %Q{percentage("string")})
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_round
|
97
|
+
assert_equal("5", evaluate("round(4.8)"))
|
98
|
+
assert_equal("5px", evaluate("round(4.8px)"))
|
99
|
+
assert_equal("5px", evaluate("round(5.49px)"))
|
100
|
+
|
101
|
+
assert_error_message("#cccccc is not a number for `round'", "round(#ccc)")
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_floor
|
105
|
+
assert_equal("4", evaluate("floor(4.8)"))
|
106
|
+
assert_equal("4px", evaluate("floor(4.8px)"))
|
107
|
+
|
108
|
+
assert_error_message("\"foo\" is not a number for `floor'", "floor(\"foo\")")
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_ceil
|
112
|
+
assert_equal("5", evaluate("ceil(4.1)"))
|
113
|
+
assert_equal("5px", evaluate("ceil(4.8px)"))
|
114
|
+
|
115
|
+
assert_error_message("\"a\" is not a number for `ceil'", "ceil(\"a\")")
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_abs
|
119
|
+
assert_equal("5", evaluate("abs(-5)"))
|
120
|
+
assert_equal("5px", evaluate("abs(-5px)"))
|
121
|
+
assert_equal("5", evaluate("abs(5)"))
|
122
|
+
assert_equal("5px", evaluate("abs(5px)"))
|
123
|
+
|
124
|
+
assert_error_message("#aaaaaa is not a number for `abs'", "abs(#aaa)")
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_rgb
|
128
|
+
assert_equal("#123456", evaluate("rgb(18, 52, 86)"))
|
129
|
+
assert_equal("#beaded", evaluate("rgb(190, 173, 237)"))
|
130
|
+
assert_equal("#00ff7f", evaluate("rgb(0, 255, 127)"))
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_rgb_percent
|
134
|
+
assert_equal("#123456", evaluate("rgb(7.1%, 20.4%, 34%)"))
|
135
|
+
assert_equal("#beaded", evaluate("rgb(74.7%, 173, 93%)"))
|
136
|
+
assert_equal("#beaded", evaluate("rgb(190, 68%, 237)"))
|
137
|
+
assert_equal("#00ff7f", evaluate("rgb(0%, 100%, 50%)"))
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_rgb_tests_bounds
|
141
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgb'",
|
142
|
+
"rgb(256, 1, 1)")
|
143
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgb'",
|
144
|
+
"rgb(1, 256, 1)")
|
145
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgb'",
|
146
|
+
"rgb(1, 1, 256)")
|
147
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgb'",
|
148
|
+
"rgb(1, 256, 257)")
|
149
|
+
assert_error_message("Color value -1 must be between 0 and 255 inclusive for `rgb'",
|
150
|
+
"rgb(-1, 1, 1)")
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_rgb_test_percent_bounds
|
154
|
+
assert_error_message("Color value 100.1% must be between 0% and 100% inclusive for `rgb'",
|
155
|
+
"rgb(100.1%, 0, 0)")
|
156
|
+
assert_error_message("Color value -0.1% must be between 0% and 100% inclusive for `rgb'",
|
157
|
+
"rgb(0, -0.1%, 0)")
|
158
|
+
assert_error_message("Color value 101% must be between 0% and 100% inclusive for `rgb'",
|
159
|
+
"rgb(0, 0, 101%)")
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_rgb_tests_types
|
163
|
+
assert_error_message("\"foo\" is not a number for `rgb'", "rgb(\"foo\", 10, 12)");
|
164
|
+
assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, \"foo\", 12)");
|
165
|
+
assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, 10, \"foo\")");
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_rgba
|
169
|
+
assert_equal("rgba(18, 52, 86, 0.5)", evaluate("rgba(18, 52, 86, 0.5)"))
|
170
|
+
assert_equal("#beaded", evaluate("rgba(190, 173, 237, 1)"))
|
171
|
+
assert_equal("rgba(0, 255, 127, 0)", evaluate("rgba(0, 255, 127, 0)"))
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_rgb_tests_bounds
|
175
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
176
|
+
"rgba(256, 1, 1, 0.3)")
|
177
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
178
|
+
"rgba(1, 256, 1, 0.3)")
|
179
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
180
|
+
"rgba(1, 1, 256, 0.3)")
|
181
|
+
assert_error_message("Color value 256 must be between 0 and 255 inclusive for `rgba'",
|
182
|
+
"rgba(1, 256, 257, 0.3)")
|
183
|
+
assert_error_message("Color value -1 must be between 0 and 255 inclusive for `rgba'",
|
184
|
+
"rgba(-1, 1, 1, 0.3)")
|
185
|
+
assert_error_message("Alpha channel -0.2 must be between 0 and 1 inclusive for `rgba'",
|
186
|
+
"rgba(1, 1, 1, -0.2)")
|
187
|
+
assert_error_message("Alpha channel 1.2 must be between 0 and 1 inclusive for `rgba'",
|
188
|
+
"rgba(1, 1, 1, 1.2)")
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_rgba_tests_types
|
192
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(\"foo\", 10, 12, 0.2)");
|
193
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(10, \"foo\", 12, 0.1)");
|
194
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(10, 10, \"foo\", 0)");
|
195
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(10, 10, 10, \"foo\")");
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_rgba_with_color
|
199
|
+
assert_equal "rgba(16, 32, 48, 0.5)", evaluate("rgba(#102030, 0.5)")
|
200
|
+
assert_equal "rgba(0, 0, 255, 0.5)", evaluate("rgba(blue, 0.5)")
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_rgba_with_color_tests_types
|
204
|
+
assert_error_message("\"foo\" is not a color for `rgba'", "rgba(\"foo\", 0.2)");
|
205
|
+
assert_error_message("\"foo\" is not a number for `rgba'", "rgba(blue, \"foo\")");
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_rgba_tests_num_args
|
209
|
+
assert_error_message("wrong number of arguments (0 for 4) for `rgba'", "rgba()");
|
210
|
+
assert_error_message("wrong number of arguments (1 for 4) for `rgba'", "rgba(blue)");
|
211
|
+
assert_error_message("wrong number of arguments (3 for 4) for `rgba'", "rgba(1, 2, 3)");
|
212
|
+
assert_error_message("wrong number of arguments (5 for 4) for `rgba'", "rgba(1, 2, 3, 0.4, 5)");
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_red
|
216
|
+
assert_equal("18", evaluate("red(#123456)"))
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_red_exception
|
220
|
+
assert_error_message("12 is not a color for `red'", "red(12)")
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_green
|
224
|
+
assert_equal("52", evaluate("green(#123456)"))
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_green_exception
|
228
|
+
assert_error_message("12 is not a color for `green'", "green(12)")
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_blue
|
232
|
+
assert_equal("86", evaluate("blue(#123456)"))
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_blue_exception
|
236
|
+
assert_error_message("12 is not a color for `blue'", "blue(12)")
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_hue
|
240
|
+
assert_equal("18deg", evaluate("hue(hsl(18, 50%, 20%))"))
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_hue_exception
|
244
|
+
assert_error_message("12 is not a color for `hue'", "hue(12)")
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_saturation
|
248
|
+
assert_equal("52%", evaluate("saturation(hsl(20, 52%, 20%))"))
|
249
|
+
assert_equal("52%", evaluate("saturation(hsl(20, 52, 20%))"))
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_saturation_exception
|
253
|
+
assert_error_message("12 is not a color for `saturation'", "saturation(12)")
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_lightness
|
257
|
+
assert_equal("86%", evaluate("lightness(hsl(120, 50%, 86%))"))
|
258
|
+
assert_equal("86%", evaluate("lightness(hsl(120, 50%, 86))"))
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_lightness_exception
|
262
|
+
assert_error_message("12 is not a color for `lightness'", "lightness(12)")
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_alpha
|
266
|
+
assert_equal("1", evaluate("alpha(#123456)"))
|
267
|
+
assert_equal("0.34", evaluate("alpha(rgba(0, 1, 2, 0.34))"))
|
268
|
+
assert_equal("0", evaluate("alpha(hsla(0, 1, 2, 0))"))
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_alpha_exception
|
272
|
+
assert_error_message("12 is not a color for `alpha'", "alpha(12)")
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_opacify
|
276
|
+
assert_equal("rgba(0, 0, 0, 0.75)", evaluate("opacify(rgba(0, 0, 0, 0.5), 0.25)"))
|
277
|
+
assert_equal("rgba(0, 0, 0, 0.3)", evaluate("opacify(rgba(0, 0, 0, 0.2), 0.1)"))
|
278
|
+
assert_equal("rgba(0, 0, 0, 0.7)", evaluate("fade-in(rgba(0, 0, 0, 0.2), 0.5px)"))
|
279
|
+
assert_equal("black", evaluate("fade_in(rgba(0, 0, 0, 0.2), 0.8)"))
|
280
|
+
assert_equal("black", evaluate("opacify(rgba(0, 0, 0, 0.2), 1)"))
|
281
|
+
assert_equal("rgba(0, 0, 0, 0.2)", evaluate("opacify(rgba(0, 0, 0, 0.2), 0%)"))
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_opacify_tests_bounds
|
285
|
+
assert_error_message("Amount -0.001 must be between 0 and 1 for `opacify'",
|
286
|
+
"opacify(rgba(0, 0, 0, 0.2), -0.001)")
|
287
|
+
assert_error_message("Amount 1.001 must be between 0 and 1 for `opacify'",
|
288
|
+
"opacify(rgba(0, 0, 0, 0.2), 1.001)")
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_opacify_tests_types
|
292
|
+
assert_error_message("\"foo\" is not a color for `opacify'", "opacify(\"foo\", 10%)")
|
293
|
+
assert_error_message("\"foo\" is not a number for `opacify'", "opacify(#fff, \"foo\")")
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_transparentize
|
297
|
+
assert_equal("rgba(0, 0, 0, 0.3)", evaluate("transparentize(rgba(0, 0, 0, 0.5), 0.2)"))
|
298
|
+
assert_equal("rgba(0, 0, 0, 0.1)", evaluate("transparentize(rgba(0, 0, 0, 0.2), 0.1)"))
|
299
|
+
assert_equal("rgba(0, 0, 0, 0.2)", evaluate("fade-out(rgba(0, 0, 0, 0.5), 0.3px)"))
|
300
|
+
assert_equal("rgba(0, 0, 0, 0)", evaluate("fade_out(rgba(0, 0, 0, 0.2), 0.2)"))
|
301
|
+
assert_equal("rgba(0, 0, 0, 0)", evaluate("transparentize(rgba(0, 0, 0, 0.2), 1)"))
|
302
|
+
assert_equal("rgba(0, 0, 0, 0.2)", evaluate("transparentize(rgba(0, 0, 0, 0.2), 0)"))
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_transparentize_tests_bounds
|
306
|
+
assert_error_message("Amount -0.001 must be between 0 and 1 for `transparentize'",
|
307
|
+
"transparentize(rgba(0, 0, 0, 0.2), -0.001)")
|
308
|
+
assert_error_message("Amount 1.001 must be between 0 and 1 for `transparentize'",
|
309
|
+
"transparentize(rgba(0, 0, 0, 0.2), 1.001)")
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_transparentize_tests_types
|
313
|
+
assert_error_message("\"foo\" is not a color for `transparentize'", "transparentize(\"foo\", 10%)")
|
314
|
+
assert_error_message("\"foo\" is not a number for `transparentize'", "transparentize(#fff, \"foo\")")
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_lighten
|
318
|
+
assert_equal("#4d4d4d", evaluate("lighten(hsl(0, 0, 0), 30%)"))
|
319
|
+
assert_equal("#ee0000", evaluate("lighten(#800, 20%)"))
|
320
|
+
assert_equal("white", evaluate("lighten(#fff, 20%)"))
|
321
|
+
assert_equal("white", evaluate("lighten(#800, 100%)"))
|
322
|
+
assert_equal("#880000", evaluate("lighten(#800, 0%)"))
|
323
|
+
assert_equal("rgba(238, 0, 0, 0.5)", evaluate("lighten(rgba(136, 0, 0, 0.5), 20%)"))
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_lighten_tests_bounds
|
327
|
+
assert_error_message("Amount -0.001 must be between 0% and 100% for `lighten'",
|
328
|
+
"lighten(#123, -0.001)")
|
329
|
+
assert_error_message("Amount 100.001 must be between 0% and 100% for `lighten'",
|
330
|
+
"lighten(#123, 100.001)")
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_lighten_tests_types
|
334
|
+
assert_error_message("\"foo\" is not a color for `lighten'", "lighten(\"foo\", 10%)")
|
335
|
+
assert_error_message("\"foo\" is not a number for `lighten'", "lighten(#fff, \"foo\")")
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_darken
|
339
|
+
assert_equal("#ff6a00", evaluate("darken(hsl(25, 100, 80), 30%)"))
|
340
|
+
assert_equal("#220000", evaluate("darken(#800, 20%)"))
|
341
|
+
assert_equal("black", evaluate("darken(#000, 20%)"))
|
342
|
+
assert_equal("black", evaluate("darken(#800, 100%)"))
|
343
|
+
assert_equal("#880000", evaluate("darken(#800, 0%)"))
|
344
|
+
assert_equal("rgba(34, 0, 0, 0.5)", evaluate("darken(rgba(136, 0, 0, 0.5), 20%)"))
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_darken_tests_bounds
|
348
|
+
assert_error_message("Amount -0.001 must be between 0% and 100% for `darken'",
|
349
|
+
"darken(#123, -0.001)")
|
350
|
+
assert_error_message("Amount 100.001 must be between 0% and 100% for `darken'",
|
351
|
+
"darken(#123, 100.001)")
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_darken_tests_types
|
355
|
+
assert_error_message("\"foo\" is not a color for `darken'", "darken(\"foo\", 10%)")
|
356
|
+
assert_error_message("\"foo\" is not a number for `darken'", "darken(#fff, \"foo\")")
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_saturate
|
360
|
+
assert_equal("#d9f2d9", evaluate("saturate(hsl(120, 30, 90), 20%)"))
|
361
|
+
assert_equal("#9e3f3f", evaluate("saturate(#855, 20%)"))
|
362
|
+
assert_equal("black", evaluate("saturate(#000, 20%)"))
|
363
|
+
assert_equal("white", evaluate("saturate(#fff, 20%)"))
|
364
|
+
assert_equal("#33ff33", evaluate("saturate(#8a8, 100%)"))
|
365
|
+
assert_equal("#88aa88", evaluate("saturate(#8a8, 0%)"))
|
366
|
+
assert_equal("rgba(158, 63, 63, 0.5)", evaluate("saturate(rgba(136, 85, 85, 0.5), 20%)"))
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_saturate_tests_bounds
|
370
|
+
assert_error_message("Amount -0.001 must be between 0% and 100% for `saturate'",
|
371
|
+
"saturate(#123, -0.001)")
|
372
|
+
assert_error_message("Amount 100.001 must be between 0% and 100% for `saturate'",
|
373
|
+
"saturate(#123, 100.001)")
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_saturate_tests_types
|
377
|
+
assert_error_message("\"foo\" is not a color for `saturate'", "saturate(\"foo\", 10%)")
|
378
|
+
assert_error_message("\"foo\" is not a number for `saturate'", "saturate(#fff, \"foo\")")
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_desaturate
|
382
|
+
assert_equal("#e3e8e3", evaluate("desaturate(hsl(120, 30, 90), 20%)"))
|
383
|
+
assert_equal("#726b6b", evaluate("desaturate(#855, 20%)"))
|
384
|
+
assert_equal("black", evaluate("desaturate(#000, 20%)"))
|
385
|
+
assert_equal("white", evaluate("desaturate(#fff, 20%)"))
|
386
|
+
assert_equal("#999999", evaluate("desaturate(#8a8, 100%)"))
|
387
|
+
assert_equal("#88aa88", evaluate("desaturate(#8a8, 0%)"))
|
388
|
+
assert_equal("rgba(114, 107, 107, 0.5)", evaluate("desaturate(rgba(136, 85, 85, 0.5), 20%)"))
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_desaturate_tests_bounds
|
392
|
+
assert_error_message("Amount -0.001 must be between 0% and 100% for `desaturate'",
|
393
|
+
"desaturate(#123, -0.001)")
|
394
|
+
assert_error_message("Amount 100.001 must be between 0% and 100% for `desaturate'",
|
395
|
+
"desaturate(#123, 100.001)")
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_desaturate_tests_types
|
399
|
+
assert_error_message("\"foo\" is not a color for `desaturate'", "desaturate(\"foo\", 10%)")
|
400
|
+
assert_error_message("\"foo\" is not a number for `desaturate'", "desaturate(#fff, \"foo\")")
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_adjust_hue
|
404
|
+
assert_equal("#deeded", evaluate("adjust-hue(hsl(120, 30, 90), 60deg)"))
|
405
|
+
assert_equal("#ededde", evaluate("adjust-hue(hsl(120, 30, 90), -60deg)"))
|
406
|
+
assert_equal("#886a11", evaluate("adjust-hue(#811, 45deg)"))
|
407
|
+
assert_equal("black", evaluate("adjust-hue(#000, 45deg)"))
|
408
|
+
assert_equal("white", evaluate("adjust-hue(#fff, 45deg)"))
|
409
|
+
assert_equal("#88aa88", evaluate("adjust-hue(#8a8, 360deg)"))
|
410
|
+
assert_equal("#88aa88", evaluate("adjust-hue(#8a8, 0deg)"))
|
411
|
+
assert_equal("rgba(136, 106, 17, 0.5)", evaluate("adjust-hue(rgba(136, 17, 17, 0.5), 45deg)"))
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_adjust_hue_tests_types
|
415
|
+
assert_error_message("\"foo\" is not a color for `adjust-hue'", "adjust-hue(\"foo\", 10%)")
|
416
|
+
assert_error_message("\"foo\" is not a number for `adjust-hue'", "adjust-hue(#fff, \"foo\")")
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_mix
|
420
|
+
assert_equal("#7f007f", evaluate("mix(#f00, #00f)"))
|
421
|
+
assert_equal("#7f7f7f", evaluate("mix(#f00, #0ff)"))
|
422
|
+
assert_equal("#7f9055", evaluate("mix(#f70, #0aa)"))
|
423
|
+
assert_equal("#3f00bf", evaluate("mix(#f00, #00f, 25%)"))
|
424
|
+
assert_equal("rgba(63, 0, 191, 0.75)", evaluate("mix(rgba(255, 0, 0, 0.5), #00f)"))
|
425
|
+
assert_equal("red", evaluate("mix(#f00, #00f, 100%)"))
|
426
|
+
assert_equal("blue", evaluate("mix(#f00, #00f, 0%)"))
|
427
|
+
assert_equal("rgba(255, 0, 0, 0.5)", evaluate("mix(#f00, transparentize(#00f, 1))"))
|
428
|
+
assert_equal("rgba(0, 0, 255, 0.5)", evaluate("mix(transparentize(#f00, 1), #00f)"))
|
429
|
+
assert_equal("red", evaluate("mix(#f00, transparentize(#00f, 1), 100%)"))
|
430
|
+
assert_equal("blue", evaluate("mix(transparentize(#f00, 1), #00f, 0%)"))
|
431
|
+
assert_equal("rgba(0, 0, 255, 0)", evaluate("mix(#f00, transparentize(#00f, 1), 0%)"))
|
432
|
+
assert_equal("rgba(255, 0, 0, 0)", evaluate("mix(transparentize(#f00, 1), #00f, 100%)"))
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_mix_tests_types
|
436
|
+
assert_error_message("\"foo\" is not a color for `mix'", "mix(\"foo\", #f00, 10%)")
|
437
|
+
assert_error_message("\"foo\" is not a color for `mix'", "mix(#f00, \"foo\", 10%)")
|
438
|
+
assert_error_message("\"foo\" is not a number for `mix'", "mix(#f00, #baf, \"foo\")")
|
439
|
+
end
|
440
|
+
|
441
|
+
def test_mix_tests_bounds
|
442
|
+
assert_error_message("Weight -0.001 must be between 0% and 100% for `mix'",
|
443
|
+
"mix(#123, #456, -0.001)")
|
444
|
+
assert_error_message("Weight 100.001 must be between 0% and 100% for `mix'",
|
445
|
+
"mix(#123, #456, 100.001)")
|
446
|
+
end
|
447
|
+
|
448
|
+
def test_grayscale
|
449
|
+
assert_equal("#bbbbbb", evaluate("grayscale(#abc)"))
|
450
|
+
assert_equal("gray", evaluate("grayscale(#f00)"))
|
451
|
+
assert_equal("gray", evaluate("grayscale(#00f)"))
|
452
|
+
assert_equal("white", evaluate("grayscale(white)"))
|
453
|
+
assert_equal("black", evaluate("grayscale(black)"))
|
454
|
+
end
|
455
|
+
|
456
|
+
def tets_grayscale_tests_types
|
457
|
+
assert_error_message("\"foo\" is not a color for `grayscale'", "grayscale(\"foo\")")
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_complement
|
461
|
+
assert_equal("#ccbbaa", evaluate("complement(#abc)"))
|
462
|
+
assert_equal("aqua", evaluate("complement(red)"))
|
463
|
+
assert_equal("red", evaluate("complement(aqua)"))
|
464
|
+
assert_equal("white", evaluate("complement(white)"))
|
465
|
+
assert_equal("black", evaluate("complement(black)"))
|
466
|
+
end
|
467
|
+
|
468
|
+
def tets_complement_tests_types
|
469
|
+
assert_error_message("\"foo\" is not a color for `complement'", "complement(\"foo\")")
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_invert
|
473
|
+
assert_equal("#112233", evaluate("invert(#edc)"))
|
474
|
+
assert_equal("rgba(245, 235, 225, 0.5)", evaluate("invert(rgba(10, 20, 30, 0.5))"))
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_invert_tests_types
|
478
|
+
assert_error_message("\"foo\" is not a color for `invert'", "invert(\"foo\")")
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_unquote
|
482
|
+
assert_equal('foo', evaluate('unquote("foo")'))
|
483
|
+
assert_equal('foo', evaluate('unquote(foo)'))
|
484
|
+
end
|
485
|
+
|
486
|
+
def test_unquote_tests_type
|
487
|
+
assert_error_message("#ff0000 is not a string for `unquote'", "unquote(#f00)")
|
488
|
+
end
|
489
|
+
|
490
|
+
def test_quote
|
491
|
+
assert_equal('"foo"', evaluate('quote(foo)'))
|
492
|
+
assert_equal('"foo"', evaluate('quote("foo")'))
|
493
|
+
end
|
494
|
+
|
495
|
+
def test_quote_tests_type
|
496
|
+
assert_error_message("#ff0000 is not a string for `quote'", "quote(#f00)")
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_user_defined_function
|
500
|
+
assert_equal("I'm a user-defined string!", evaluate("user_defined()"))
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_user_defined_function_with_preceding_underscore
|
504
|
+
assert_equal("I'm another user-defined string!", evaluate("_preceding_underscore()"))
|
505
|
+
assert_equal("I'm another user-defined string!", evaluate("-preceding-underscore()"))
|
506
|
+
end
|
507
|
+
|
508
|
+
def test_options_on_new_literals_fails
|
509
|
+
assert_error_message(<<MSG, "call-options-on-new-literal()")
|
510
|
+
The #options attribute is not set on this Sass::Script::String.
|
511
|
+
This error is probably occurring because #to_s was called
|
512
|
+
on this literal within a custom Sass function without first
|
513
|
+
setting the #option attribute.
|
514
|
+
MSG
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_type_of
|
518
|
+
assert_equal("string", evaluate("type-of(\"asdf\")"))
|
519
|
+
assert_equal("string", evaluate("type-of(asdf)"))
|
520
|
+
assert_equal("number", evaluate("type-of(1px)"))
|
521
|
+
assert_equal("bool", evaluate("type-of(true)"))
|
522
|
+
assert_equal("color", evaluate("type-of(#fff)"))
|
523
|
+
end
|
524
|
+
|
525
|
+
def test_unit
|
526
|
+
assert_equal(%Q{""}, evaluate("unit(100)"))
|
527
|
+
assert_equal(%Q{"px"}, evaluate("unit(100px)"))
|
528
|
+
assert_equal(%Q{"em*px"}, evaluate("unit(10px * 5em)"))
|
529
|
+
assert_equal(%Q{"em*px"}, evaluate("unit(5em * 10px)"))
|
530
|
+
assert_equal(%Q{"em*px/cm*rem"}, evaluate("unit(10px * 5em / 30cm / 1rem)"))
|
531
|
+
assert_error_message("#ff0000 is not a number for `unit'", "unit(#f00)")
|
532
|
+
end
|
533
|
+
|
534
|
+
def test_unitless
|
535
|
+
assert_equal(%Q{true}, evaluate("unitless(100)"))
|
536
|
+
assert_equal(%Q{false}, evaluate("unitless(100px)"))
|
537
|
+
assert_error_message("#ff0000 is not a number for `unitless'", "unitless(#f00)")
|
538
|
+
end
|
539
|
+
|
540
|
+
def test_comparable
|
541
|
+
assert_equal(%Q{true}, evaluate("comparable(2px, 1px)"))
|
542
|
+
assert_equal(%Q{true}, evaluate("comparable(10cm, 3mm)"))
|
543
|
+
assert_equal(%Q{false}, evaluate("comparable(100px, 3em)"))
|
544
|
+
assert_error_message("#ff0000 is not a number for `comparable'", "comparable(#f00, 1px)")
|
545
|
+
assert_error_message("#ff0000 is not a number for `comparable'", "comparable(1px, #f00)")
|
546
|
+
end
|
547
|
+
|
548
|
+
private
|
549
|
+
|
550
|
+
def evaluate(value)
|
551
|
+
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
|
552
|
+
end
|
553
|
+
|
554
|
+
def perform(value)
|
555
|
+
Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new)
|
556
|
+
end
|
557
|
+
|
558
|
+
def assert_error_message(message, value)
|
559
|
+
evaluate(value)
|
560
|
+
flunk("Error message expected but not raised: #{message}")
|
561
|
+
rescue Sass::SyntaxError => e
|
562
|
+
assert_equal(message, e.message)
|
563
|
+
end
|
564
|
+
|
565
|
+
end
|