haml 2.2.24 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (168) hide show
  1. data/.yardopts +0 -1
  2. data/README.md +91 -151
  3. data/REMEMBER +11 -1
  4. data/Rakefile +73 -55
  5. data/VERSION +1 -1
  6. data/VERSION_NAME +1 -1
  7. data/bin/css2sass +7 -1
  8. data/bin/sass-convert +7 -0
  9. data/extra/haml-mode.el +2 -1
  10. data/lib/haml/buffer.rb +22 -4
  11. data/lib/haml/engine.rb +5 -1
  12. data/lib/haml/exec.rb +231 -46
  13. data/lib/haml/filters.rb +19 -8
  14. data/lib/haml/helpers.rb +47 -20
  15. data/lib/haml/helpers/action_view_extensions.rb +2 -4
  16. data/lib/haml/helpers/action_view_mods.rb +11 -8
  17. data/lib/haml/helpers/xss_mods.rb +13 -2
  18. data/lib/haml/html.rb +179 -48
  19. data/lib/haml/html/erb.rb +141 -0
  20. data/lib/haml/precompiler.rb +40 -15
  21. data/lib/haml/railtie.rb +1 -5
  22. data/lib/haml/root.rb +3 -0
  23. data/lib/haml/template.rb +4 -14
  24. data/lib/haml/util.rb +120 -30
  25. data/lib/haml/version.rb +25 -2
  26. data/lib/sass.rb +5 -1
  27. data/lib/sass/callbacks.rb +50 -0
  28. data/lib/sass/css.rb +40 -191
  29. data/lib/sass/engine.rb +170 -74
  30. data/lib/sass/environment.rb +8 -2
  31. data/lib/sass/error.rb +163 -25
  32. data/lib/sass/files.rb +31 -28
  33. data/lib/sass/plugin.rb +268 -87
  34. data/lib/sass/plugin/rails.rb +9 -4
  35. data/lib/sass/repl.rb +1 -1
  36. data/lib/sass/script.rb +31 -29
  37. data/lib/sass/script/bool.rb +1 -0
  38. data/lib/sass/script/color.rb +290 -23
  39. data/lib/sass/script/css_lexer.rb +22 -0
  40. data/lib/sass/script/css_parser.rb +28 -0
  41. data/lib/sass/script/funcall.rb +22 -3
  42. data/lib/sass/script/functions.rb +523 -33
  43. data/lib/sass/script/interpolation.rb +42 -0
  44. data/lib/sass/script/lexer.rb +169 -52
  45. data/lib/sass/script/literal.rb +58 -9
  46. data/lib/sass/script/node.rb +79 -1
  47. data/lib/sass/script/number.rb +20 -5
  48. data/lib/sass/script/operation.rb +49 -3
  49. data/lib/sass/script/parser.rb +162 -28
  50. data/lib/sass/script/string.rb +50 -2
  51. data/lib/sass/script/unary_operation.rb +25 -2
  52. data/lib/sass/script/variable.rb +21 -4
  53. data/lib/sass/scss.rb +14 -0
  54. data/lib/sass/scss/css_parser.rb +39 -0
  55. data/lib/sass/scss/parser.rb +683 -0
  56. data/lib/sass/scss/rx.rb +112 -0
  57. data/lib/sass/scss/script_lexer.rb +13 -0
  58. data/lib/sass/scss/script_parser.rb +25 -0
  59. data/lib/sass/tree/comment_node.rb +69 -27
  60. data/lib/sass/tree/debug_node.rb +7 -2
  61. data/lib/sass/tree/directive_node.rb +41 -35
  62. data/lib/sass/tree/for_node.rb +6 -0
  63. data/lib/sass/tree/if_node.rb +13 -1
  64. data/lib/sass/tree/import_node.rb +52 -27
  65. data/lib/sass/tree/mixin_def_node.rb +18 -0
  66. data/lib/sass/tree/mixin_node.rb +41 -6
  67. data/lib/sass/tree/node.rb +197 -70
  68. data/lib/sass/tree/prop_node.rb +152 -57
  69. data/lib/sass/tree/root_node.rb +118 -0
  70. data/lib/sass/tree/rule_node.rb +193 -96
  71. data/lib/sass/tree/variable_node.rb +9 -5
  72. data/lib/sass/tree/while_node.rb +4 -0
  73. data/test/benchmark.rb +5 -5
  74. data/test/haml/engine_test.rb +147 -10
  75. data/test/haml/{rhtml/_av_partial_1.rhtml → erb/_av_partial_1.erb} +1 -1
  76. data/test/haml/{rhtml/_av_partial_2.rhtml → erb/_av_partial_2.erb} +1 -1
  77. data/test/haml/{rhtml/action_view.rhtml → erb/action_view.erb} +1 -1
  78. data/test/haml/{rhtml/standard.rhtml → erb/standard.erb} +0 -0
  79. data/test/haml/helper_test.rb +91 -24
  80. data/test/haml/html2haml/erb_tests.rb +410 -0
  81. data/test/haml/html2haml_test.rb +210 -66
  82. data/test/haml/results/filters.xhtml +1 -1
  83. data/test/haml/results/just_stuff.xhtml +2 -0
  84. data/test/haml/spec_test.rb +44 -0
  85. data/test/haml/template_test.rb +22 -2
  86. data/test/haml/templates/helpers.haml +0 -13
  87. data/test/haml/templates/just_stuff.haml +2 -0
  88. data/test/haml/util_test.rb +48 -0
  89. data/test/sass/callbacks_test.rb +61 -0
  90. data/test/sass/conversion_test.rb +884 -0
  91. data/test/sass/css2sass_test.rb +99 -18
  92. data/test/sass/data/hsl-rgb.txt +319 -0
  93. data/test/sass/engine_test.rb +1049 -131
  94. data/test/sass/functions_test.rb +398 -47
  95. data/test/sass/more_results/more_import.css +1 -1
  96. data/test/sass/more_templates/more_import.sass +3 -3
  97. data/test/sass/plugin_test.rb +184 -10
  98. data/test/sass/results/compact.css +1 -1
  99. data/test/sass/results/complex.css +5 -5
  100. data/test/sass/results/compressed.css +1 -1
  101. data/test/sass/results/expanded.css +1 -1
  102. data/test/sass/results/import.css +3 -1
  103. data/test/sass/results/mixins.css +12 -12
  104. data/test/sass/results/nested.css +1 -1
  105. data/test/sass/results/options.css +1 -0
  106. data/test/sass/results/parent_ref.css +4 -4
  107. data/test/sass/results/script.css +3 -3
  108. data/test/sass/results/scss_import.css +15 -0
  109. data/test/sass/results/scss_importee.css +2 -0
  110. data/test/sass/script_conversion_test.rb +153 -0
  111. data/test/sass/script_test.rb +137 -70
  112. data/test/sass/scss/css_test.rb +811 -0
  113. data/test/sass/scss/rx_test.rb +156 -0
  114. data/test/sass/scss/scss_test.rb +871 -0
  115. data/test/sass/scss/test_helper.rb +37 -0
  116. data/test/sass/templates/alt.sass +2 -2
  117. data/test/sass/templates/bork1.sass +2 -0
  118. data/test/sass/templates/bork3.sass +2 -0
  119. data/test/sass/templates/bork4.sass +2 -0
  120. data/test/sass/templates/import.sass +4 -4
  121. data/test/sass/templates/importee.sass +3 -3
  122. data/test/sass/templates/line_numbers.sass +1 -1
  123. data/test/sass/templates/mixin_bork.sass +5 -0
  124. data/test/sass/templates/mixins.sass +2 -2
  125. data/test/sass/templates/nested_bork1.sass +2 -0
  126. data/test/sass/templates/nested_bork2.sass +2 -0
  127. data/test/sass/templates/nested_bork3.sass +2 -0
  128. data/test/sass/templates/nested_bork4.sass +2 -0
  129. data/test/sass/templates/nested_mixin_bork.sass +6 -0
  130. data/test/sass/templates/options.sass +2 -0
  131. data/test/sass/templates/parent_ref.sass +2 -2
  132. data/test/sass/templates/script.sass +69 -69
  133. data/test/sass/templates/scss_import.scss +10 -0
  134. data/test/sass/templates/scss_importee.scss +1 -0
  135. data/test/sass/templates/units.sass +10 -10
  136. data/test/test_helper.rb +20 -8
  137. data/vendor/fssm/LICENSE +20 -0
  138. data/vendor/fssm/README.markdown +55 -0
  139. data/vendor/fssm/Rakefile +59 -0
  140. data/vendor/fssm/VERSION.yml +5 -0
  141. data/vendor/fssm/example.rb +9 -0
  142. data/vendor/fssm/fssm.gemspec +77 -0
  143. data/vendor/fssm/lib/fssm.rb +33 -0
  144. data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
  145. data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
  146. data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
  147. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
  148. data/vendor/fssm/lib/fssm/monitor.rb +26 -0
  149. data/vendor/fssm/lib/fssm/path.rb +91 -0
  150. data/vendor/fssm/lib/fssm/pathname.rb +502 -0
  151. data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
  152. data/vendor/fssm/lib/fssm/state/file.rb +24 -0
  153. data/vendor/fssm/lib/fssm/support.rb +63 -0
  154. data/vendor/fssm/lib/fssm/tree.rb +176 -0
  155. data/vendor/fssm/profile/prof-cache.rb +40 -0
  156. data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
  157. data/vendor/fssm/profile/prof-pathname.rb +68 -0
  158. data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
  159. data/vendor/fssm/profile/prof.html +2379 -0
  160. data/vendor/fssm/spec/path_spec.rb +75 -0
  161. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  162. data/vendor/fssm/spec/root/file.css +0 -0
  163. data/vendor/fssm/spec/root/file.rb +0 -0
  164. data/vendor/fssm/spec/root/file.yml +0 -0
  165. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  166. data/vendor/fssm/spec/spec_helper.rb +14 -0
  167. metadata +94 -14
  168. data/test/sass/templates/bork.sass +0 -2
@@ -1,57 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'test/unit'
3
- require File.dirname(__FILE__) + '/../../lib/sass'
3
+ require File.dirname(__FILE__) + '/../test_helper'
4
4
  require 'sass/script'
5
5
 
6
- module UserFunctions
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
+
7
13
  def user_defined
8
14
  Sass::Script::String.new("I'm a user-defined string!")
9
15
  end
10
- end
11
16
 
12
- module Sass::Script::Functions
13
- include UserFunctions
17
+ def _preceding_underscore
18
+ Sass::Script::String.new("I'm another user-defined string!")
19
+ end
14
20
  end
15
21
 
16
22
  class SassFunctionTest < Test::Unit::TestCase
17
- def test_hsl
18
- # These tests adapted from the w3c browser tests
19
- # http://www.w3.org/Style/CSS/Test/CSS3/Color/20070927/html4/t040204-hsl-h-rotating-b.htm
20
- red = [255, 0, 0]
21
- assert_rgb_hsl(red, ['0', '100%', '50%'])
22
- assert_rgb_hsl(red, ['-360', '100%', '50%'])
23
- assert_rgb_hsl(red, ['360', '100%', '50%'])
24
- assert_rgb_hsl(red, ['6120', '100%', '50%'])
25
-
26
- yellow = [255, 255, 0]
27
- assert_rgb_hsl(yellow, ['60', '100%', '50%'])
28
- assert_rgb_hsl(yellow, ['-300', '100%', '50%'])
29
- assert_rgb_hsl(yellow, ['420', '100%', '50%'])
30
- assert_rgb_hsl(yellow, ['-9660', '100%', '50%'])
31
-
32
- green = [0, 255, 0]
33
- assert_rgb_hsl(green, ['120', '100%', '50%'])
34
- assert_rgb_hsl(green, ['-240', '100%', '50%'])
35
- assert_rgb_hsl(green, ['480', '100%', '50%'])
36
- assert_rgb_hsl(green, ['99840', '100%', '50%'])
37
-
38
- cyan = [0, 255, 255]
39
- assert_rgb_hsl(cyan, ['180', '100%', '50%'])
40
- assert_rgb_hsl(cyan, ['-180', '100%', '50%'])
41
- assert_rgb_hsl(cyan, ['540', '100%', '50%'])
42
- assert_rgb_hsl(cyan, ['-900', '100%', '50%'])
43
-
44
- blue = [0, 0, 255]
45
- assert_rgb_hsl(blue, ['240', '100%', '50%'])
46
- assert_rgb_hsl(blue, ['-120', '100%', '50%'])
47
- assert_rgb_hsl(blue, ['600', '100%', '50%'])
48
- assert_rgb_hsl(blue, ['-104880', '100%', '50%'])
49
-
50
- purple = [255, 0, 255]
51
- assert_rgb_hsl(purple, ['300', '100%', '50%'])
52
- assert_rgb_hsl(purple, ['-60', '100%', '50%'])
53
- assert_rgb_hsl(purple, ['660', '100%', '50%'])
54
- assert_rgb_hsl(purple, ['2820', '100%', '50%'])
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
55
51
  end
56
52
 
57
53
  def test_hsl_checks_bounds
@@ -65,6 +61,26 @@ class SassFunctionTest < Test::Unit::TestCase
65
61
  assert_error_message("\"foo\" is not a number for `hsl'", "hsl(10, 10, \"foo\")");
66
62
  end
67
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
+
68
84
  def test_percentage
69
85
  assert_equal("50%", evaluate("percentage(.5)"))
70
86
  assert_equal("100%", evaluate("percentage(1)"))
@@ -149,21 +165,356 @@ class SassFunctionTest < Test::Unit::TestCase
149
165
  assert_error_message("\"foo\" is not a number for `rgb'", "rgb(10, 10, \"foo\")");
150
166
  end
151
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_unquote
473
+ assert_equal('foo', evaluate('unquote("foo")'))
474
+ assert_equal('foo', evaluate('unquote(foo)'))
475
+ end
476
+
477
+ def test_unquote_tests_type
478
+ assert_error_message("#ff0000 is not a string for `unquote'", "unquote(#f00)")
479
+ end
480
+
481
+ def test_quote
482
+ assert_equal('"foo"', evaluate('quote(foo)'))
483
+ assert_equal('"foo"', evaluate('quote("foo")'))
484
+ end
485
+
486
+ def test_quote_tests_type
487
+ assert_error_message("#ff0000 is not a string for `quote'", "quote(#f00)")
488
+ end
489
+
152
490
  def test_user_defined_function
153
491
  assert_equal("I'm a user-defined string!", evaluate("user_defined()"))
154
492
  end
155
493
 
156
- private
494
+ def test_user_defined_function_with_preceding_underscore
495
+ assert_equal("I'm another user-defined string!", evaluate("_preceding_underscore()"))
496
+ assert_equal("I'm another user-defined string!", evaluate("-preceding-underscore()"))
497
+ end
157
498
 
158
- def assert_rgb_hsl(rgb, hsl)
159
- hsl = hsl.map {|v| Sass::Script::Parser.parse v, 0, 0 }
160
- assert_equal(rgb, Sass::Script::Functions::EvaluationContext.new({}).hsl(*hsl).rgb)
499
+ def test_options_on_new_literals_fails
500
+ assert_error_message(<<MSG, "call-options-on-new-literal()")
501
+ The #options attribute is not set on this Sass::Script::String.
502
+ This error is probably occurring because #to_s was called
503
+ on this literal within a custom Sass function without first
504
+ setting the #option attribute.
505
+ MSG
161
506
  end
162
507
 
508
+ private
509
+
163
510
  def evaluate(value)
164
511
  Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new).to_s
165
512
  end
166
513
 
514
+ def perform(value)
515
+ Sass::Script::Parser.parse(value, 0, 0).perform(Sass::Environment.new)
516
+ end
517
+
167
518
  def assert_error_message(message, value)
168
519
  evaluate(value)
169
520
  flunk("Error message expected but not raised: #{message}")