aliddle-sass 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. data/.yardopts +11 -0
  2. data/CONTRIBUTING +3 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +201 -0
  5. data/Rakefile +347 -0
  6. data/VERSION +1 -0
  7. data/VERSION_NAME +1 -0
  8. data/bin/sass +9 -0
  9. data/bin/sass-convert +8 -0
  10. data/bin/scss +9 -0
  11. data/extra/update_watch.rb +13 -0
  12. data/init.rb +18 -0
  13. data/lib/sass.rb +95 -0
  14. data/lib/sass/cache_stores.rb +15 -0
  15. data/lib/sass/cache_stores/base.rb +88 -0
  16. data/lib/sass/cache_stores/chain.rb +33 -0
  17. data/lib/sass/cache_stores/filesystem.rb +60 -0
  18. data/lib/sass/cache_stores/memory.rb +47 -0
  19. data/lib/sass/cache_stores/null.rb +25 -0
  20. data/lib/sass/callbacks.rb +66 -0
  21. data/lib/sass/css.rb +409 -0
  22. data/lib/sass/engine.rb +928 -0
  23. data/lib/sass/environment.rb +101 -0
  24. data/lib/sass/error.rb +201 -0
  25. data/lib/sass/exec.rb +707 -0
  26. data/lib/sass/importers.rb +22 -0
  27. data/lib/sass/importers/base.rb +139 -0
  28. data/lib/sass/importers/filesystem.rb +190 -0
  29. data/lib/sass/logger.rb +15 -0
  30. data/lib/sass/logger/base.rb +32 -0
  31. data/lib/sass/logger/log_level.rb +49 -0
  32. data/lib/sass/media.rb +213 -0
  33. data/lib/sass/plugin.rb +132 -0
  34. data/lib/sass/plugin/compiler.rb +406 -0
  35. data/lib/sass/plugin/configuration.rb +123 -0
  36. data/lib/sass/plugin/generic.rb +15 -0
  37. data/lib/sass/plugin/merb.rb +48 -0
  38. data/lib/sass/plugin/rack.rb +60 -0
  39. data/lib/sass/plugin/rails.rb +47 -0
  40. data/lib/sass/plugin/staleness_checker.rb +183 -0
  41. data/lib/sass/railtie.rb +9 -0
  42. data/lib/sass/repl.rb +57 -0
  43. data/lib/sass/root.rb +7 -0
  44. data/lib/sass/script.rb +39 -0
  45. data/lib/sass/script/arg_list.rb +52 -0
  46. data/lib/sass/script/bool.rb +18 -0
  47. data/lib/sass/script/color.rb +606 -0
  48. data/lib/sass/script/css_lexer.rb +29 -0
  49. data/lib/sass/script/css_parser.rb +31 -0
  50. data/lib/sass/script/funcall.rb +237 -0
  51. data/lib/sass/script/functions.rb +1543 -0
  52. data/lib/sass/script/interpolation.rb +79 -0
  53. data/lib/sass/script/lexer.rb +348 -0
  54. data/lib/sass/script/list.rb +85 -0
  55. data/lib/sass/script/literal.rb +221 -0
  56. data/lib/sass/script/node.rb +99 -0
  57. data/lib/sass/script/null.rb +37 -0
  58. data/lib/sass/script/number.rb +453 -0
  59. data/lib/sass/script/operation.rb +110 -0
  60. data/lib/sass/script/parser.rb +495 -0
  61. data/lib/sass/script/string.rb +51 -0
  62. data/lib/sass/script/string_interpolation.rb +103 -0
  63. data/lib/sass/script/unary_operation.rb +69 -0
  64. data/lib/sass/script/variable.rb +58 -0
  65. data/lib/sass/scss.rb +16 -0
  66. data/lib/sass/scss/css_parser.rb +36 -0
  67. data/lib/sass/scss/parser.rb +1179 -0
  68. data/lib/sass/scss/rx.rb +133 -0
  69. data/lib/sass/scss/script_lexer.rb +15 -0
  70. data/lib/sass/scss/script_parser.rb +25 -0
  71. data/lib/sass/scss/static_parser.rb +54 -0
  72. data/lib/sass/selector.rb +452 -0
  73. data/lib/sass/selector/abstract_sequence.rb +94 -0
  74. data/lib/sass/selector/comma_sequence.rb +92 -0
  75. data/lib/sass/selector/sequence.rb +507 -0
  76. data/lib/sass/selector/simple.rb +119 -0
  77. data/lib/sass/selector/simple_sequence.rb +212 -0
  78. data/lib/sass/shared.rb +76 -0
  79. data/lib/sass/supports.rb +229 -0
  80. data/lib/sass/tree/charset_node.rb +22 -0
  81. data/lib/sass/tree/comment_node.rb +82 -0
  82. data/lib/sass/tree/content_node.rb +9 -0
  83. data/lib/sass/tree/css_import_node.rb +60 -0
  84. data/lib/sass/tree/debug_node.rb +18 -0
  85. data/lib/sass/tree/directive_node.rb +42 -0
  86. data/lib/sass/tree/each_node.rb +24 -0
  87. data/lib/sass/tree/extend_node.rb +36 -0
  88. data/lib/sass/tree/for_node.rb +36 -0
  89. data/lib/sass/tree/function_node.rb +34 -0
  90. data/lib/sass/tree/if_node.rb +52 -0
  91. data/lib/sass/tree/import_node.rb +75 -0
  92. data/lib/sass/tree/media_node.rb +58 -0
  93. data/lib/sass/tree/mixin_def_node.rb +38 -0
  94. data/lib/sass/tree/mixin_node.rb +39 -0
  95. data/lib/sass/tree/node.rb +196 -0
  96. data/lib/sass/tree/prop_node.rb +152 -0
  97. data/lib/sass/tree/return_node.rb +18 -0
  98. data/lib/sass/tree/root_node.rb +28 -0
  99. data/lib/sass/tree/rule_node.rb +132 -0
  100. data/lib/sass/tree/supports_node.rb +51 -0
  101. data/lib/sass/tree/trace_node.rb +32 -0
  102. data/lib/sass/tree/variable_node.rb +30 -0
  103. data/lib/sass/tree/visitors/base.rb +75 -0
  104. data/lib/sass/tree/visitors/check_nesting.rb +147 -0
  105. data/lib/sass/tree/visitors/convert.rb +316 -0
  106. data/lib/sass/tree/visitors/cssize.rb +229 -0
  107. data/lib/sass/tree/visitors/deep_copy.rb +102 -0
  108. data/lib/sass/tree/visitors/extend.rb +68 -0
  109. data/lib/sass/tree/visitors/perform.rb +446 -0
  110. data/lib/sass/tree/visitors/set_options.rb +125 -0
  111. data/lib/sass/tree/visitors/to_css.rb +230 -0
  112. data/lib/sass/tree/warn_node.rb +18 -0
  113. data/lib/sass/tree/while_node.rb +18 -0
  114. data/lib/sass/util.rb +906 -0
  115. data/lib/sass/util/multibyte_string_scanner.rb +155 -0
  116. data/lib/sass/util/subset_map.rb +109 -0
  117. data/lib/sass/util/test.rb +10 -0
  118. data/lib/sass/version.rb +126 -0
  119. data/rails/init.rb +1 -0
  120. data/test/Gemfile +3 -0
  121. data/test/Gemfile.lock +10 -0
  122. data/test/sass/cache_test.rb +89 -0
  123. data/test/sass/callbacks_test.rb +61 -0
  124. data/test/sass/conversion_test.rb +1760 -0
  125. data/test/sass/css2sass_test.rb +439 -0
  126. data/test/sass/data/hsl-rgb.txt +319 -0
  127. data/test/sass/engine_test.rb +3243 -0
  128. data/test/sass/exec_test.rb +86 -0
  129. data/test/sass/extend_test.rb +1461 -0
  130. data/test/sass/fixtures/test_staleness_check_across_importers.css +1 -0
  131. data/test/sass/fixtures/test_staleness_check_across_importers.scss +1 -0
  132. data/test/sass/functions_test.rb +1139 -0
  133. data/test/sass/importer_test.rb +192 -0
  134. data/test/sass/logger_test.rb +58 -0
  135. data/test/sass/mock_importer.rb +49 -0
  136. data/test/sass/more_results/more1.css +9 -0
  137. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  138. data/test/sass/more_results/more_import.css +29 -0
  139. data/test/sass/more_templates/_more_partial.sass +2 -0
  140. data/test/sass/more_templates/more1.sass +23 -0
  141. data/test/sass/more_templates/more_import.sass +11 -0
  142. data/test/sass/plugin_test.rb +550 -0
  143. data/test/sass/results/alt.css +4 -0
  144. data/test/sass/results/basic.css +9 -0
  145. data/test/sass/results/cached_import_option.css +3 -0
  146. data/test/sass/results/compact.css +5 -0
  147. data/test/sass/results/complex.css +86 -0
  148. data/test/sass/results/compressed.css +1 -0
  149. data/test/sass/results/expanded.css +19 -0
  150. data/test/sass/results/filename_fn.css +3 -0
  151. data/test/sass/results/if.css +3 -0
  152. data/test/sass/results/import.css +31 -0
  153. data/test/sass/results/import_charset.css +5 -0
  154. data/test/sass/results/import_charset_1_8.css +5 -0
  155. data/test/sass/results/import_charset_ibm866.css +5 -0
  156. data/test/sass/results/import_content.css +1 -0
  157. data/test/sass/results/line_numbers.css +49 -0
  158. data/test/sass/results/mixins.css +95 -0
  159. data/test/sass/results/multiline.css +24 -0
  160. data/test/sass/results/nested.css +22 -0
  161. data/test/sass/results/options.css +1 -0
  162. data/test/sass/results/parent_ref.css +13 -0
  163. data/test/sass/results/script.css +16 -0
  164. data/test/sass/results/scss_import.css +31 -0
  165. data/test/sass/results/scss_importee.css +2 -0
  166. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  167. data/test/sass/results/subdir/subdir.css +3 -0
  168. data/test/sass/results/units.css +11 -0
  169. data/test/sass/results/warn.css +0 -0
  170. data/test/sass/results/warn_imported.css +0 -0
  171. data/test/sass/script_conversion_test.rb +299 -0
  172. data/test/sass/script_test.rb +591 -0
  173. data/test/sass/scss/css_test.rb +1093 -0
  174. data/test/sass/scss/rx_test.rb +156 -0
  175. data/test/sass/scss/scss_test.rb +2043 -0
  176. data/test/sass/scss/test_helper.rb +37 -0
  177. data/test/sass/templates/_cached_import_option_partial.scss +1 -0
  178. data/test/sass/templates/_double_import_loop2.sass +1 -0
  179. data/test/sass/templates/_filename_fn_import.scss +11 -0
  180. data/test/sass/templates/_imported_charset_ibm866.sass +4 -0
  181. data/test/sass/templates/_imported_charset_utf8.sass +4 -0
  182. data/test/sass/templates/_imported_content.sass +3 -0
  183. data/test/sass/templates/_partial.sass +2 -0
  184. data/test/sass/templates/_same_name_different_partiality.scss +1 -0
  185. data/test/sass/templates/alt.sass +16 -0
  186. data/test/sass/templates/basic.sass +23 -0
  187. data/test/sass/templates/bork1.sass +2 -0
  188. data/test/sass/templates/bork2.sass +2 -0
  189. data/test/sass/templates/bork3.sass +2 -0
  190. data/test/sass/templates/bork4.sass +2 -0
  191. data/test/sass/templates/bork5.sass +3 -0
  192. data/test/sass/templates/cached_import_option.scss +3 -0
  193. data/test/sass/templates/compact.sass +17 -0
  194. data/test/sass/templates/complex.sass +305 -0
  195. data/test/sass/templates/compressed.sass +15 -0
  196. data/test/sass/templates/double_import_loop1.sass +1 -0
  197. data/test/sass/templates/expanded.sass +17 -0
  198. data/test/sass/templates/filename_fn.scss +18 -0
  199. data/test/sass/templates/if.sass +11 -0
  200. data/test/sass/templates/import.sass +12 -0
  201. data/test/sass/templates/import_charset.sass +9 -0
  202. data/test/sass/templates/import_charset_1_8.sass +6 -0
  203. data/test/sass/templates/import_charset_ibm866.sass +11 -0
  204. data/test/sass/templates/import_content.sass +4 -0
  205. data/test/sass/templates/importee.less +2 -0
  206. data/test/sass/templates/importee.sass +19 -0
  207. data/test/sass/templates/line_numbers.sass +13 -0
  208. data/test/sass/templates/mixin_bork.sass +5 -0
  209. data/test/sass/templates/mixins.sass +76 -0
  210. data/test/sass/templates/multiline.sass +20 -0
  211. data/test/sass/templates/nested.sass +25 -0
  212. data/test/sass/templates/nested_bork1.sass +2 -0
  213. data/test/sass/templates/nested_bork2.sass +2 -0
  214. data/test/sass/templates/nested_bork3.sass +2 -0
  215. data/test/sass/templates/nested_bork4.sass +2 -0
  216. data/test/sass/templates/nested_import.sass +2 -0
  217. data/test/sass/templates/nested_mixin_bork.sass +6 -0
  218. data/test/sass/templates/options.sass +2 -0
  219. data/test/sass/templates/parent_ref.sass +25 -0
  220. data/test/sass/templates/same_name_different_ext.sass +2 -0
  221. data/test/sass/templates/same_name_different_ext.scss +1 -0
  222. data/test/sass/templates/same_name_different_partiality.scss +1 -0
  223. data/test/sass/templates/script.sass +101 -0
  224. data/test/sass/templates/scss_import.scss +11 -0
  225. data/test/sass/templates/scss_importee.scss +1 -0
  226. data/test/sass/templates/single_import_loop.sass +1 -0
  227. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  228. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  229. data/test/sass/templates/subdir/subdir.sass +6 -0
  230. data/test/sass/templates/units.sass +11 -0
  231. data/test/sass/templates/warn.sass +3 -0
  232. data/test/sass/templates/warn_imported.sass +4 -0
  233. data/test/sass/test_helper.rb +8 -0
  234. data/test/sass/util/multibyte_string_scanner_test.rb +147 -0
  235. data/test/sass/util/subset_map_test.rb +91 -0
  236. data/test/sass/util_test.rb +313 -0
  237. data/test/test_helper.rb +80 -0
  238. metadata +348 -0
@@ -0,0 +1,11 @@
1
+ $preconst: hello;
2
+
3
+ @mixin premixin {pre-mixin: here}
4
+
5
+ @import "importee.sass", "scss_importee", "basic.sass", "basic.css", "../results/complex.css";
6
+ @import "partial.sass";
7
+
8
+ nonimported {
9
+ myconst: $preconst;
10
+ otherconst: $postconst;
11
+ @include postmixin; }
@@ -0,0 +1 @@
1
+ scss {imported: yes}
@@ -0,0 +1 @@
1
+ @import "single_import_loop"
@@ -0,0 +1,2 @@
1
+ #nested
2
+ :relative true
@@ -0,0 +1,3 @@
1
+ #pi
2
+ :width 314px
3
+
@@ -0,0 +1,6 @@
1
+ @import nested_subdir/nested_partial.sass
2
+
3
+ #subdir
4
+ :font
5
+ :size 20px
6
+ :weight bold
@@ -0,0 +1,11 @@
1
+ b
2
+ :foo 0.5 * 10px
3
+ :bar 10zzz * 12px / 5zzz
4
+ :baz percentage(12.0px / 18px)
5
+ :many-units 10.0zzz / 3yyy * 12px / 5zzz * 3yyy / 3px * 4em
6
+ :mm 5mm + 1cm
7
+ :pc 1pc + 12pt
8
+ :pt 72pt - 2in
9
+ :inches 1in + 2.54cm
10
+ :more-inches 1in + ((72pt * 2in) + (36pt * 1in)) / 2.54cm
11
+ :mixed (1 + (1em * 6px / 3in)) * 4in / 2em
@@ -0,0 +1,3 @@
1
+ @warn "In the main file"
2
+ @import warn_imported.sass
3
+ +emits-a-warning
@@ -0,0 +1,4 @@
1
+ @warn "Imported"
2
+
3
+ =emits-a-warning
4
+ @warn "In an imported mixin"
@@ -0,0 +1,8 @@
1
+ test_dir = File.dirname(__FILE__)
2
+ $:.unshift test_dir unless $:.include?(test_dir)
3
+
4
+ class Test::Unit::TestCase
5
+ def absolutize(file)
6
+ File.expand_path("#{File.dirname(__FILE__)}/#{file}")
7
+ end
8
+ end
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require File.dirname(__FILE__) + '/../../test_helper'
4
+
5
+ unless Sass::Util.ruby1_8?
6
+ class MultibyteStringScannerTest < Test::Unit::TestCase
7
+ def setup
8
+ @scanner = Sass::Util::MultibyteStringScanner.new("cölorfül")
9
+ end
10
+
11
+ def test_initial
12
+ assert_scanner_state 0, 0, nil, nil
13
+ end
14
+
15
+ def test_check
16
+ assert_equal 'cö', @scanner.check(/../)
17
+ assert_scanner_state 0, 0, 2, 3
18
+ assert_equal 0, @scanner.pos
19
+ assert_equal 0, @scanner.pos
20
+ assert_equal 2, @scanner.matched_size
21
+ assert_equal 3, @scanner.byte_matched_size
22
+ end
23
+
24
+ def test_check_until
25
+ assert_equal 'cölorfü', @scanner.check_until(/f./)
26
+ assert_scanner_state 0, 0, 2, 3
27
+ end
28
+
29
+ def test_getch
30
+ assert_equal 'c', @scanner.getch
31
+ assert_equal 'ö', @scanner.getch
32
+ assert_scanner_state 2, 3, 1, 2
33
+ end
34
+
35
+ def test_match?
36
+ assert_equal 2, @scanner.match?(/../)
37
+ assert_scanner_state 0, 0, 2, 3
38
+ end
39
+
40
+ def test_peek
41
+ assert_equal 'cö', @scanner.peek(2)
42
+ assert_scanner_state 0, 0, nil, nil
43
+ end
44
+
45
+ def test_rest_size
46
+ assert_equal 'cö', @scanner.scan(/../)
47
+ assert_equal 6, @scanner.rest_size
48
+ end
49
+
50
+ def test_scan
51
+ assert_equal 'cö', @scanner.scan(/../)
52
+ assert_scanner_state 2, 3, 2, 3
53
+ end
54
+
55
+ def test_scan_until
56
+ assert_equal 'cölorfü', @scanner.scan_until(/f./)
57
+ assert_scanner_state 7, 9, 2, 3
58
+ end
59
+
60
+ def test_skip
61
+ assert_equal 2, @scanner.skip(/../)
62
+ assert_scanner_state 2, 3, 2, 3
63
+ end
64
+
65
+ def test_skip_until
66
+ assert_equal 7, @scanner.skip_until(/f./)
67
+ assert_scanner_state 7, 9, 2, 3
68
+ end
69
+
70
+ def test_set_pos
71
+ @scanner.pos = 7
72
+ assert_scanner_state 7, 9, nil, nil
73
+ @scanner.pos = 6
74
+ assert_scanner_state 6, 7, nil, nil
75
+ @scanner.pos = 1
76
+ assert_scanner_state 1, 1, nil, nil
77
+ end
78
+
79
+ def test_reset
80
+ @scanner.scan(/../)
81
+ @scanner.reset
82
+ assert_scanner_state 0, 0, nil, nil
83
+ end
84
+
85
+ def test_scan_full
86
+ assert_equal 'cö', @scanner.scan_full(/../, true, true)
87
+ assert_scanner_state 2, 3, 2, 3
88
+
89
+ @scanner.reset
90
+ assert_equal 'cö', @scanner.scan_full(/../, false, true)
91
+ assert_scanner_state 0, 0, 2, 3
92
+
93
+ @scanner.reset
94
+ assert_nil @scanner.scan_full(/../, true, false)
95
+ assert_scanner_state 2, 3, 2, 3
96
+
97
+ @scanner.reset
98
+ assert_nil @scanner.scan_full(/../, false, false)
99
+ assert_scanner_state 0, 0, 2, 3
100
+ end
101
+
102
+ def test_search_full
103
+ assert_equal 'cölorfü', @scanner.search_full(/f./, true, true)
104
+ assert_scanner_state 7, 9, 2, 3
105
+
106
+ @scanner.reset
107
+ assert_equal 'cölorfü', @scanner.search_full(/f./, false, true)
108
+ assert_scanner_state 0, 0, 2, 3
109
+
110
+ @scanner.reset
111
+ assert_nil @scanner.search_full(/f./, true, false)
112
+ assert_scanner_state 7, 9, 2, 3
113
+
114
+ @scanner.reset
115
+ assert_nil @scanner.search_full(/f./, false, false)
116
+ assert_scanner_state 0, 0, 2, 3
117
+ end
118
+
119
+ def test_set_string
120
+ @scanner.scan(/../)
121
+ @scanner.string = 'föóbâr'
122
+ assert_scanner_state 0, 0, nil, nil
123
+ end
124
+
125
+ def test_terminate
126
+ @scanner.scan(/../)
127
+ @scanner.terminate
128
+ assert_scanner_state 8, 10, nil, nil
129
+ end
130
+
131
+ def test_unscan
132
+ @scanner.scan(/../)
133
+ @scanner.scan_until(/f./)
134
+ @scanner.unscan
135
+ assert_scanner_state 2, 3, nil, nil
136
+ end
137
+
138
+ private
139
+
140
+ def assert_scanner_state(pos, byte_pos, matched_size, byte_matched_size)
141
+ assert_equal pos, @scanner.pos, 'pos'
142
+ assert_equal byte_pos, @scanner.byte_pos, 'byte_pos'
143
+ assert_equal matched_size, @scanner.matched_size, 'matched_size'
144
+ assert_equal byte_matched_size, @scanner.byte_matched_size, 'byte_matched_size'
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../test_helper'
3
+
4
+ class SubsetMapTest < Test::Unit::TestCase
5
+ def setup
6
+ @ssm = Sass::Util::SubsetMap.new
7
+ @ssm[Set[1, 2]] = "Foo"
8
+ @ssm[Set["fizz", "fazz"]] = "Bar"
9
+
10
+ @ssm[Set[:foo, :bar]] = "Baz"
11
+ @ssm[Set[:foo, :bar, :baz]] = "Bang"
12
+
13
+ @ssm[Set[:bip, :bop, :blip]] = "Qux"
14
+ @ssm[Set[:bip, :bop]] = "Thram"
15
+ end
16
+
17
+ def test_equal_keys
18
+ assert_equal [["Foo", Set[1, 2]]], @ssm.get(Set[1, 2])
19
+ assert_equal [["Bar", Set["fizz", "fazz"]]], @ssm.get(Set["fizz", "fazz"])
20
+ end
21
+
22
+ def test_subset_keys
23
+ assert_equal [["Foo", Set[1, 2]]], @ssm.get(Set[1, 2, "fuzz"])
24
+ assert_equal [["Bar", Set["fizz", "fazz"]]], @ssm.get(Set["fizz", "fazz", 3])
25
+ end
26
+
27
+ def test_superset_keys
28
+ assert_equal [], @ssm.get(Set[1])
29
+ assert_equal [], @ssm.get(Set[2])
30
+ assert_equal [], @ssm.get(Set["fizz"])
31
+ assert_equal [], @ssm.get(Set["fazz"])
32
+ end
33
+
34
+ def test_disjoint_keys
35
+ assert_equal [], @ssm.get(Set[3, 4])
36
+ assert_equal [], @ssm.get(Set["fuzz", "frizz"])
37
+ assert_equal [], @ssm.get(Set["gran", 15])
38
+ end
39
+
40
+ def test_semi_disjoint_keys
41
+ assert_equal [], @ssm.get(Set[2, 3])
42
+ assert_equal [], @ssm.get(Set["fizz", "fuzz"])
43
+ assert_equal [], @ssm.get(Set[1, "fazz"])
44
+ end
45
+
46
+ def test_empty_key_set
47
+ assert_raise(ArgumentError) {@ssm[Set[]] = "Fail"}
48
+ end
49
+
50
+ def test_empty_key_get
51
+ assert_equal [], @ssm.get(Set[])
52
+ end
53
+
54
+ def test_multiple_subsets
55
+ assert_equal [["Foo", Set[1, 2]], ["Bar", Set["fizz", "fazz"]]], @ssm.get(Set[1, 2, "fizz", "fazz"])
56
+ assert_equal [["Foo", Set[1, 2]], ["Bar", Set["fizz", "fazz"]]], @ssm.get(Set[1, 2, 3, "fizz", "fazz", "fuzz"])
57
+
58
+ assert_equal [["Baz", Set[:foo, :bar]]], @ssm.get(Set[:foo, :bar])
59
+ assert_equal [["Baz", Set[:foo, :bar]], ["Bang", Set[:foo, :bar, :baz]]], @ssm.get(Set[:foo, :bar, :baz])
60
+ end
61
+
62
+ def test_bracket_bracket
63
+ assert_equal ["Foo"], @ssm[Set[1, 2, "fuzz"]]
64
+ assert_equal ["Baz", "Bang"], @ssm[Set[:foo, :bar, :baz]]
65
+ end
66
+
67
+ def test_order_preserved
68
+ @ssm[Set[10, 11, 12]] = 1
69
+ @ssm[Set[10, 11]] = 2
70
+ @ssm[Set[11]] = 3
71
+ @ssm[Set[11, 12]] = 4
72
+ @ssm[Set[9, 10, 11, 12, 13]] = 5
73
+ @ssm[Set[10, 13]] = 6
74
+
75
+ assert_equal(
76
+ [[1, Set[10, 11, 12]], [2, Set[10, 11]], [3, Set[11]], [4, Set[11, 12]],
77
+ [5, Set[9, 10, 11, 12, 13]], [6, Set[10, 13]]],
78
+ @ssm.get(Set[9, 10, 11, 12, 13]))
79
+ end
80
+
81
+ def test_multiple_equal_values
82
+ @ssm[Set[11, 12]] = 1
83
+ @ssm[Set[12, 13]] = 2
84
+ @ssm[Set[13, 14]] = 1
85
+ @ssm[Set[14, 15]] = 1
86
+
87
+ assert_equal(
88
+ [[1, Set[11, 12]], [2, Set[12, 13]], [1, Set[13, 14]], [1, Set[14, 15]]],
89
+ @ssm.get(Set[11, 12, 13, 14, 15]))
90
+ end
91
+ end
@@ -0,0 +1,313 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../test_helper'
3
+ require 'pathname'
4
+
5
+ class UtilTest < Test::Unit::TestCase
6
+ include Sass::Util
7
+
8
+ def test_scope
9
+ assert(File.exist?(scope("Rakefile")))
10
+ end
11
+
12
+ def test_to_hash
13
+ assert_equal({
14
+ :foo => 1,
15
+ :bar => 2,
16
+ :baz => 3
17
+ }, to_hash([[:foo, 1], [:bar, 2], [:baz, 3]]))
18
+ end
19
+
20
+ def test_map_keys
21
+ assert_equal({
22
+ "foo" => 1,
23
+ "bar" => 2,
24
+ "baz" => 3
25
+ }, map_keys({:foo => 1, :bar => 2, :baz => 3}) {|k| k.to_s})
26
+ end
27
+
28
+ def test_map_vals
29
+ assert_equal({
30
+ :foo => "1",
31
+ :bar => "2",
32
+ :baz => "3"
33
+ }, map_vals({:foo => 1, :bar => 2, :baz => 3}) {|k| k.to_s})
34
+ end
35
+
36
+ def test_map_hash
37
+ assert_equal({
38
+ "foo" => "1",
39
+ "bar" => "2",
40
+ "baz" => "3"
41
+ }, map_hash({:foo => 1, :bar => 2, :baz => 3}) {|k, v| [k.to_s, v.to_s]})
42
+ end
43
+
44
+ def test_powerset
45
+ return unless Set[Set[]] == Set[Set[]] # There's a bug in Ruby 1.8.6 that breaks nested set equality
46
+ assert_equal([[].to_set].to_set,
47
+ powerset([]))
48
+ assert_equal([[].to_set, [1].to_set].to_set,
49
+ powerset([1]))
50
+ assert_equal([[].to_set, [1].to_set, [2].to_set, [1, 2].to_set].to_set,
51
+ powerset([1, 2]))
52
+ assert_equal([[].to_set, [1].to_set, [2].to_set, [3].to_set,
53
+ [1, 2].to_set, [2, 3].to_set, [1, 3].to_set, [1, 2, 3].to_set].to_set,
54
+ powerset([1, 2, 3]))
55
+ end
56
+
57
+ def test_restrict
58
+ assert_equal(0.5, restrict(0.5, 0..1))
59
+ assert_equal(1, restrict(2, 0..1))
60
+ assert_equal(1.3, restrict(2, 0..1.3))
61
+ assert_equal(0, restrict(-1, 0..1))
62
+ end
63
+
64
+ def test_merge_adjacent_strings
65
+ assert_equal(["foo bar baz", :bang, "biz bop", 12],
66
+ merge_adjacent_strings(["foo ", "bar ", "baz", :bang, "biz", " bop", 12]))
67
+ str = "foo"
68
+ assert_equal(["foo foo foo", :bang, "foo foo", 12],
69
+ merge_adjacent_strings([str, " ", str, " ", str, :bang, str, " ", str, 12]))
70
+ end
71
+
72
+ def test_intersperse
73
+ assert_equal(["foo", " ", "bar", " ", "baz"],
74
+ intersperse(%w[foo bar baz], " "))
75
+ assert_equal([], intersperse([], " "))
76
+ end
77
+
78
+ def test_substitute
79
+ assert_equal(["foo", "bar", "baz", 3, 4],
80
+ substitute([1, 2, 3, 4], [1, 2], ["foo", "bar", "baz"]))
81
+ assert_equal([1, "foo", "bar", "baz", 4],
82
+ substitute([1, 2, 3, 4], [2, 3], ["foo", "bar", "baz"]))
83
+ assert_equal([1, 2, "foo", "bar", "baz"],
84
+ substitute([1, 2, 3, 4], [3, 4], ["foo", "bar", "baz"]))
85
+
86
+ assert_equal([1, "foo", "bar", "baz", 2, 3, 4],
87
+ substitute([1, 2, 2, 2, 3, 4], [2, 2], ["foo", "bar", "baz"]))
88
+ end
89
+
90
+ def test_strip_string_array
91
+ assert_equal(["foo ", " bar ", " baz"],
92
+ strip_string_array([" foo ", " bar ", " baz "]))
93
+ assert_equal([:foo, " bar ", " baz"],
94
+ strip_string_array([:foo, " bar ", " baz "]))
95
+ assert_equal(["foo ", " bar ", :baz],
96
+ strip_string_array([" foo ", " bar ", :baz]))
97
+ end
98
+
99
+ def test_paths
100
+ assert_equal([[1, 3, 5], [2, 3, 5], [1, 4, 5], [2, 4, 5]],
101
+ paths([[1, 2], [3, 4], [5]]))
102
+ assert_equal([[]], paths([]))
103
+ assert_equal([[1, 2, 3]], paths([[1], [2], [3]]))
104
+ end
105
+
106
+ def test_lcs
107
+ assert_equal([1, 2, 3], lcs([1, 2, 3], [1, 2, 3]))
108
+ assert_equal([], lcs([], [1, 2, 3]))
109
+ assert_equal([], lcs([1, 2, 3], []))
110
+ assert_equal([1, 2, 3], lcs([5, 1, 4, 2, 3, 17], [0, 0, 1, 2, 6, 3]))
111
+
112
+ assert_equal([1], lcs([1, 2, 3, 4], [4, 3, 2, 1]))
113
+ assert_equal([1, 2], lcs([1, 2, 3, 4], [3, 4, 1, 2]))
114
+ end
115
+
116
+ def test_lcs_with_block
117
+ assert_equal(["1", "2", "3"],
118
+ lcs([1, 4, 2, 5, 3], [1, 2, 3]) {|a, b| a == b && a.to_s})
119
+ assert_equal([-4, 2, 8],
120
+ lcs([-5, 3, 2, 8], [-4, 1, 8]) {|a, b| (a - b).abs <= 1 && [a, b].max})
121
+ end
122
+
123
+ def test_group_by_to_a
124
+ assert_equal([[1, [1, 3, 5, 7]], [0, [2, 4, 6, 8]]],
125
+ group_by_to_a(1..8) {|i| i % 2})
126
+ assert_equal([[1, [1, 4, 7, 10]], [2, [2, 5, 8, 11]], [0, [3, 6, 9, 12]]],
127
+ group_by_to_a(1..12) {|i| i % 3})
128
+ end
129
+
130
+ def test_subsequence
131
+ assert(subsequence?([1, 2, 3], [1, 2, 3]))
132
+ assert(subsequence?([1, 2, 3], [1, :a, 2, :b, 3]))
133
+ assert(subsequence?([1, 2, 3], [:a, 1, :b, :c, 2, :d, 3, :e, :f]))
134
+
135
+ assert(!subsequence?([1, 2, 3], [1, 2]))
136
+ assert(!subsequence?([1, 2, 3], [1, 3, 2]))
137
+ assert(!subsequence?([1, 2, 3], [3, 2, 1]))
138
+ end
139
+
140
+ def test_silence_warnings
141
+ old_stderr, $stderr = $stderr, StringIO.new
142
+ warn "Out"
143
+ assert_equal("Out\n", $stderr.string)
144
+ silence_warnings {warn "In"}
145
+ assert_equal("Out\n", $stderr.string)
146
+ ensure
147
+ $stderr = old_stderr
148
+ end
149
+
150
+ def test_sass_warn
151
+ assert_warning("Foo!") {sass_warn "Foo!"}
152
+ end
153
+
154
+ def test_silence_sass_warnings
155
+ old_stderr, $stderr = $stderr, StringIO.new
156
+ silence_sass_warnings {warn "Out"}
157
+ assert_equal("Out\n", $stderr.string)
158
+ silence_sass_warnings {sass_warn "In"}
159
+ assert_equal("Out\n", $stderr.string)
160
+ ensure
161
+ $stderr = old_stderr
162
+ end
163
+
164
+ def test_has
165
+ assert(has?(:instance_method, String, :chomp!))
166
+ assert(has?(:private_instance_method, Sass::Engine, :parse_interp))
167
+ end
168
+
169
+ def test_enum_with_index
170
+ assert_equal(%w[foo0 bar1 baz2],
171
+ enum_with_index(%w[foo bar baz]).map {|s, i| "#{s}#{i}"})
172
+ end
173
+
174
+ def test_enum_cons
175
+ assert_equal(%w[foobar barbaz],
176
+ enum_cons(%w[foo bar baz], 2).map {|s1, s2| "#{s1}#{s2}"})
177
+ end
178
+
179
+ def test_extract
180
+ arr = [1, 2, 3, 4, 5]
181
+ assert_equal([1, 3, 5], extract!(arr) {|e| e % 2 == 1})
182
+ assert_equal([2, 4], arr)
183
+ end
184
+
185
+ def test_ord
186
+ assert_equal(102, ord("f"))
187
+ assert_equal(98, ord("bar"))
188
+ end
189
+
190
+ def test_flatten
191
+ assert_equal([1, 2, 3], flatten([1, 2, 3], 0))
192
+ assert_equal([1, 2, 3], flatten([1, 2, 3], 1))
193
+ assert_equal([1, 2, 3], flatten([1, 2, 3], 2))
194
+
195
+ assert_equal([[1, 2], 3], flatten([[1, 2], 3], 0))
196
+ assert_equal([1, 2, 3], flatten([[1, 2], 3], 1))
197
+ assert_equal([1, 2, 3], flatten([[1, 2], 3], 2))
198
+
199
+ assert_equal([[[1], 2], [3], 4], flatten([[[1], 2], [3], 4], 0))
200
+ assert_equal([[1], 2, 3, 4], flatten([[[1], 2], [3], 4], 1))
201
+ assert_equal([1, 2, 3, 4], flatten([[[1], 2], [3], 4], 2))
202
+ end
203
+
204
+ def test_set_hash
205
+ assert(set_hash(Set[1, 2, 3]) == set_hash(Set[3, 2, 1]))
206
+ assert(set_hash(Set[1, 2, 3]) == set_hash(Set[1, 2, 3]))
207
+
208
+ s1 = Set[]
209
+ s1 << 1
210
+ s1 << 2
211
+ s1 << 3
212
+ s2 = Set[]
213
+ s2 << 3
214
+ s2 << 2
215
+ s2 << 1
216
+ assert(set_hash(s1) == set_hash(s2))
217
+ end
218
+
219
+ def test_set_eql
220
+ assert(set_eql?(Set[1, 2, 3], Set[3, 2, 1]))
221
+ assert(set_eql?(Set[1, 2, 3], Set[1, 2, 3]))
222
+
223
+ s1 = Set[]
224
+ s1 << 1
225
+ s1 << 2
226
+ s1 << 3
227
+ s2 = Set[]
228
+ s2 << 3
229
+ s2 << 2
230
+ s2 << 1
231
+ assert(set_eql?(s1, s2))
232
+ end
233
+
234
+ def test_extract_and_inject_values
235
+ test = lambda {|arr| assert_equal(arr, with_extracted_values(arr) {|str| str})}
236
+
237
+ test[['foo bar']]
238
+ test[['foo {12} bar']]
239
+ test[['foo {{12} bar']]
240
+ test[['foo {{1', 12, '2} bar']]
241
+ test[['foo 1', 2, '{3', 4, 5, 6, '{7}', 8]]
242
+ test[['foo 1', [2, 3, 4], ' bar']]
243
+ test[['foo ', 1, "\n bar\n", [2, 3, 4], "\n baz"]]
244
+ end
245
+
246
+ def nested_caller_info_fn
247
+ caller_info
248
+ end
249
+
250
+ def double_nested_caller_info_fn
251
+ nested_caller_info_fn
252
+ end
253
+
254
+ def test_caller_info
255
+ assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle'"))
256
+ assert_equal(["/tmp/foo.rb", 12, nil], caller_info("/tmp/foo.rb:12"))
257
+ assert_equal(["(sass)", 12, "blah"], caller_info("(sass):12: in `blah'"))
258
+ assert_equal(["", 12, "boop"], caller_info(":12: in `boop'"))
259
+ assert_equal(["/tmp/foo.rb", -12, "fizzle"], caller_info("/tmp/foo.rb:-12: in `fizzle'"))
260
+ assert_equal(["/tmp/foo.rb", 12, "fizzle"], caller_info("/tmp/foo.rb:12: in `fizzle {}'"))
261
+
262
+ info = nested_caller_info_fn
263
+ assert_equal(__FILE__, info[0])
264
+ assert_equal("test_caller_info", info[2])
265
+
266
+ info = proc {nested_caller_info_fn}.call
267
+ assert_equal(__FILE__, info[0])
268
+ assert_match(/^(block in )?test_caller_info$/, info[2])
269
+
270
+ info = double_nested_caller_info_fn
271
+ assert_equal(__FILE__, info[0])
272
+ assert_equal("double_nested_caller_info_fn", info[2])
273
+
274
+ info = proc {double_nested_caller_info_fn}.call
275
+ assert_equal(__FILE__, info[0])
276
+ assert_equal("double_nested_caller_info_fn", info[2])
277
+ end
278
+
279
+ def test_version_gt
280
+ assert_version_gt("2.0.0", "1.0.0")
281
+ assert_version_gt("1.1.0", "1.0.0")
282
+ assert_version_gt("1.0.1", "1.0.0")
283
+ assert_version_gt("1.0.0", "1.0.0.rc")
284
+ assert_version_gt("1.0.0.1", "1.0.0.rc")
285
+ assert_version_gt("1.0.0.rc", "0.9.9")
286
+ assert_version_gt("1.0.0.beta", "1.0.0.alpha")
287
+
288
+ assert_version_eq("1.0.0", "1.0.0")
289
+ assert_version_eq("1.0.0", "1.0.0.0")
290
+ end
291
+
292
+ def assert_version_gt(v1, v2)
293
+ #assert(version_gt(v1, v2), "Expected #{v1} > #{v2}")
294
+ assert(!version_gt(v2, v1), "Expected #{v2} < #{v1}")
295
+ end
296
+
297
+ def assert_version_eq(v1, v2)
298
+ assert(!version_gt(v1, v2), "Expected #{v1} = #{v2}")
299
+ assert(!version_gt(v2, v1), "Expected #{v2} = #{v1}")
300
+ end
301
+
302
+ class FooBar
303
+ def foo
304
+ Sass::Util.abstract(self)
305
+ end
306
+ end
307
+
308
+ def test_abstract
309
+ assert_raise_message(NotImplementedError,
310
+ "UtilTest::FooBar must implement #foo") {FooBar.new.foo}
311
+ end
312
+
313
+ end