haml 3.0.25 → 3.1.0.alpha.2

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 (212) hide show
  1. data/.yardopts +1 -1
  2. data/CONTRIBUTING +0 -1
  3. data/EDGE_GEM_VERSION +1 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +10 -175
  6. data/Rakefile +56 -84
  7. data/VERSION +1 -1
  8. data/VERSION_NAME +1 -1
  9. data/init.rb +1 -1
  10. data/lib/haml.rb +14 -12
  11. data/lib/haml/engine.rb +1 -1
  12. data/lib/haml/exec.rb +19 -316
  13. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  14. data/lib/haml/html.rb +69 -76
  15. data/lib/haml/precompiler.rb +34 -41
  16. data/lib/haml/railtie.rb +4 -6
  17. data/lib/haml/template/plugin.rb +6 -16
  18. data/lib/haml/util.rb +91 -107
  19. data/lib/haml/version.rb +7 -0
  20. data/test/benchmark.rb +2 -9
  21. data/test/haml/engine_test.rb +195 -92
  22. data/test/haml/html2haml/erb_tests.rb +0 -14
  23. data/test/haml/util_test.rb +32 -0
  24. data/test/test_helper.rb +0 -39
  25. metadata +96 -324
  26. data/bin/css2sass +0 -13
  27. data/bin/sass +0 -8
  28. data/bin/sass-convert +0 -7
  29. data/extra/haml-mode.el +0 -753
  30. data/extra/sass-mode.el +0 -207
  31. data/lib/haml/util/subset_map.rb +0 -101
  32. data/lib/sass.rb +0 -29
  33. data/lib/sass/callbacks.rb +0 -52
  34. data/lib/sass/css.rb +0 -294
  35. data/lib/sass/engine.rb +0 -720
  36. data/lib/sass/environment.rb +0 -143
  37. data/lib/sass/error.rb +0 -198
  38. data/lib/sass/files.rb +0 -160
  39. data/lib/sass/less.rb +0 -382
  40. data/lib/sass/plugin.rb +0 -279
  41. data/lib/sass/plugin/configuration.rb +0 -221
  42. data/lib/sass/plugin/generic.rb +0 -15
  43. data/lib/sass/plugin/merb.rb +0 -37
  44. data/lib/sass/plugin/rack.rb +0 -47
  45. data/lib/sass/plugin/rails.rb +0 -32
  46. data/lib/sass/plugin/staleness_checker.rb +0 -123
  47. data/lib/sass/repl.rb +0 -58
  48. data/lib/sass/script.rb +0 -63
  49. data/lib/sass/script/bool.rb +0 -18
  50. data/lib/sass/script/color.rb +0 -491
  51. data/lib/sass/script/css_lexer.rb +0 -29
  52. data/lib/sass/script/css_parser.rb +0 -31
  53. data/lib/sass/script/funcall.rb +0 -77
  54. data/lib/sass/script/functions.rb +0 -861
  55. data/lib/sass/script/interpolation.rb +0 -70
  56. data/lib/sass/script/lexer.rb +0 -337
  57. data/lib/sass/script/literal.rb +0 -236
  58. data/lib/sass/script/node.rb +0 -112
  59. data/lib/sass/script/number.rb +0 -423
  60. data/lib/sass/script/operation.rb +0 -95
  61. data/lib/sass/script/parser.rb +0 -401
  62. data/lib/sass/script/string.rb +0 -67
  63. data/lib/sass/script/string_interpolation.rb +0 -93
  64. data/lib/sass/script/unary_operation.rb +0 -57
  65. data/lib/sass/script/variable.rb +0 -48
  66. data/lib/sass/scss.rb +0 -17
  67. data/lib/sass/scss/css_parser.rb +0 -46
  68. data/lib/sass/scss/parser.rb +0 -855
  69. data/lib/sass/scss/rx.rb +0 -126
  70. data/lib/sass/scss/sass_parser.rb +0 -11
  71. data/lib/sass/scss/script_lexer.rb +0 -15
  72. data/lib/sass/scss/script_parser.rb +0 -25
  73. data/lib/sass/scss/static_parser.rb +0 -40
  74. data/lib/sass/selector.rb +0 -361
  75. data/lib/sass/selector/abstract_sequence.rb +0 -62
  76. data/lib/sass/selector/comma_sequence.rb +0 -82
  77. data/lib/sass/selector/sequence.rb +0 -237
  78. data/lib/sass/selector/simple.rb +0 -113
  79. data/lib/sass/selector/simple_sequence.rb +0 -136
  80. data/lib/sass/tree/charset_node.rb +0 -37
  81. data/lib/sass/tree/comment_node.rb +0 -128
  82. data/lib/sass/tree/debug_node.rb +0 -36
  83. data/lib/sass/tree/directive_node.rb +0 -75
  84. data/lib/sass/tree/extend_node.rb +0 -65
  85. data/lib/sass/tree/for_node.rb +0 -55
  86. data/lib/sass/tree/if_node.rb +0 -69
  87. data/lib/sass/tree/import_node.rb +0 -102
  88. data/lib/sass/tree/mixin_def_node.rb +0 -48
  89. data/lib/sass/tree/mixin_node.rb +0 -111
  90. data/lib/sass/tree/node.rb +0 -464
  91. data/lib/sass/tree/prop_node.rb +0 -220
  92. data/lib/sass/tree/root_node.rb +0 -163
  93. data/lib/sass/tree/rule_node.rb +0 -261
  94. data/lib/sass/tree/variable_node.rb +0 -39
  95. data/lib/sass/tree/warn_node.rb +0 -42
  96. data/lib/sass/tree/while_node.rb +0 -36
  97. data/test/haml/util/subset_map_test.rb +0 -91
  98. data/test/sass/callbacks_test.rb +0 -61
  99. data/test/sass/conversion_test.rb +0 -1218
  100. data/test/sass/css2sass_test.rb +0 -364
  101. data/test/sass/data/hsl-rgb.txt +0 -319
  102. data/test/sass/engine_test.rb +0 -2267
  103. data/test/sass/extend_test.rb +0 -1348
  104. data/test/sass/functions_test.rb +0 -556
  105. data/test/sass/less_conversion_test.rb +0 -653
  106. data/test/sass/more_results/more1.css +0 -9
  107. data/test/sass/more_results/more1_with_line_comments.css +0 -26
  108. data/test/sass/more_results/more_import.css +0 -29
  109. data/test/sass/more_templates/_more_partial.sass +0 -2
  110. data/test/sass/more_templates/more1.sass +0 -23
  111. data/test/sass/more_templates/more_import.sass +0 -11
  112. data/test/sass/plugin_test.rb +0 -433
  113. data/test/sass/results/alt.css +0 -4
  114. data/test/sass/results/basic.css +0 -9
  115. data/test/sass/results/compact.css +0 -5
  116. data/test/sass/results/complex.css +0 -86
  117. data/test/sass/results/compressed.css +0 -1
  118. data/test/sass/results/expanded.css +0 -19
  119. data/test/sass/results/import.css +0 -31
  120. data/test/sass/results/import_charset.css +0 -4
  121. data/test/sass/results/import_charset_1_8.css +0 -4
  122. data/test/sass/results/import_charset_ibm866.css +0 -4
  123. data/test/sass/results/line_numbers.css +0 -49
  124. data/test/sass/results/mixins.css +0 -95
  125. data/test/sass/results/multiline.css +0 -24
  126. data/test/sass/results/nested.css +0 -22
  127. data/test/sass/results/options.css +0 -1
  128. data/test/sass/results/parent_ref.css +0 -13
  129. data/test/sass/results/script.css +0 -16
  130. data/test/sass/results/scss_import.css +0 -31
  131. data/test/sass/results/scss_importee.css +0 -2
  132. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  133. data/test/sass/results/subdir/subdir.css +0 -3
  134. data/test/sass/results/units.css +0 -11
  135. data/test/sass/results/warn.css +0 -0
  136. data/test/sass/results/warn_imported.css +0 -0
  137. data/test/sass/script_conversion_test.rb +0 -314
  138. data/test/sass/script_test.rb +0 -470
  139. data/test/sass/scss/css_test.rb +0 -916
  140. data/test/sass/scss/rx_test.rb +0 -156
  141. data/test/sass/scss/scss_test.rb +0 -1122
  142. data/test/sass/scss/test_helper.rb +0 -37
  143. data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
  144. data/test/sass/templates/_imported_charset_utf8.sass +0 -4
  145. data/test/sass/templates/_partial.sass +0 -2
  146. data/test/sass/templates/alt.sass +0 -16
  147. data/test/sass/templates/basic.sass +0 -23
  148. data/test/sass/templates/bork1.sass +0 -2
  149. data/test/sass/templates/bork2.sass +0 -2
  150. data/test/sass/templates/bork3.sass +0 -2
  151. data/test/sass/templates/bork4.sass +0 -2
  152. data/test/sass/templates/compact.sass +0 -17
  153. data/test/sass/templates/complex.sass +0 -305
  154. data/test/sass/templates/compressed.sass +0 -15
  155. data/test/sass/templates/expanded.sass +0 -17
  156. data/test/sass/templates/import.sass +0 -12
  157. data/test/sass/templates/import_charset.sass +0 -7
  158. data/test/sass/templates/import_charset_1_8.sass +0 -4
  159. data/test/sass/templates/import_charset_ibm866.sass +0 -9
  160. data/test/sass/templates/importee.less +0 -2
  161. data/test/sass/templates/importee.sass +0 -19
  162. data/test/sass/templates/line_numbers.sass +0 -13
  163. data/test/sass/templates/mixin_bork.sass +0 -5
  164. data/test/sass/templates/mixins.sass +0 -76
  165. data/test/sass/templates/multiline.sass +0 -20
  166. data/test/sass/templates/nested.sass +0 -25
  167. data/test/sass/templates/nested_bork1.sass +0 -2
  168. data/test/sass/templates/nested_bork2.sass +0 -2
  169. data/test/sass/templates/nested_bork3.sass +0 -2
  170. data/test/sass/templates/nested_bork4.sass +0 -2
  171. data/test/sass/templates/nested_mixin_bork.sass +0 -6
  172. data/test/sass/templates/options.sass +0 -2
  173. data/test/sass/templates/parent_ref.sass +0 -25
  174. data/test/sass/templates/script.sass +0 -101
  175. data/test/sass/templates/scss_import.scss +0 -11
  176. data/test/sass/templates/scss_importee.scss +0 -1
  177. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  178. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  179. data/test/sass/templates/subdir/subdir.sass +0 -6
  180. data/test/sass/templates/units.sass +0 -11
  181. data/test/sass/templates/warn.sass +0 -3
  182. data/test/sass/templates/warn_imported.sass +0 -4
  183. data/vendor/fssm/LICENSE +0 -20
  184. data/vendor/fssm/README.markdown +0 -55
  185. data/vendor/fssm/Rakefile +0 -59
  186. data/vendor/fssm/VERSION.yml +0 -5
  187. data/vendor/fssm/example.rb +0 -9
  188. data/vendor/fssm/fssm.gemspec +0 -77
  189. data/vendor/fssm/lib/fssm.rb +0 -33
  190. data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
  191. data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
  192. data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
  193. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
  194. data/vendor/fssm/lib/fssm/monitor.rb +0 -26
  195. data/vendor/fssm/lib/fssm/path.rb +0 -91
  196. data/vendor/fssm/lib/fssm/pathname.rb +0 -502
  197. data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
  198. data/vendor/fssm/lib/fssm/state/file.rb +0 -24
  199. data/vendor/fssm/lib/fssm/support.rb +0 -63
  200. data/vendor/fssm/lib/fssm/tree.rb +0 -176
  201. data/vendor/fssm/profile/prof-cache.rb +0 -40
  202. data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
  203. data/vendor/fssm/profile/prof-pathname.rb +0 -68
  204. data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
  205. data/vendor/fssm/profile/prof.html +0 -2379
  206. data/vendor/fssm/spec/path_spec.rb +0 -75
  207. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  208. data/vendor/fssm/spec/root/file.css +0 -0
  209. data/vendor/fssm/spec/root/file.rb +0 -0
  210. data/vendor/fssm/spec/root/file.yml +0 -0
  211. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  212. data/vendor/fssm/spec/spec_helper.rb +0 -14
@@ -1,2267 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- require File.dirname(__FILE__) + '/../test_helper'
4
- require 'sass/engine'
5
- require 'stringio'
6
-
7
- module Sass::Script::Functions::UserFunctions
8
- def option(name)
9
- Sass::Script::String.new(@options[name.value.to_sym].to_s)
10
- end
11
- end
12
-
13
- class SassEngineTest < Test::Unit::TestCase
14
- # A map of erroneous Sass documents to the error messages they should produce.
15
- # The error messages may be arrays;
16
- # if so, the second element should be the line number that should be reported for the error.
17
- # If this isn't provided, the tests will assume the line number should be the last line of the document.
18
- EXCEPTION_MAP = {
19
- "$a: 1 + " => 'Invalid CSS after "1 +": expected expression (e.g. 1px, bold), was ""',
20
- "$a: 1 + 2 +" => 'Invalid CSS after "1 + 2 +": expected expression (e.g. 1px, bold), was ""',
21
- "$a: 1 + 2 + %" => 'Invalid CSS after "1 + 2 + ": expected expression (e.g. 1px, bold), was "%"',
22
- "$a: foo(\"bar\"" => 'Invalid CSS after "foo("bar"": expected ")", was ""',
23
- "$a: 1 }" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}"',
24
- "$a: 1 }foo\"" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}foo""',
25
- ":" => 'Invalid property: ":".',
26
- ": a" => 'Invalid property: ": a".',
27
- "a\n :b" => <<MSG,
28
- Invalid property: ":b" (no value).
29
- If ":b" should be a selector, use "\\:b" instead.
30
- MSG
31
- "a\n b:" => 'Invalid property: "b:" (no value).',
32
- "a\n :b: c" => 'Invalid property: ":b: c".',
33
- "a\n :b:c d" => 'Invalid property: ":b:c d".',
34
- "a\n :b c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
35
- "a\n b: c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
36
- ".foo ^bar\n a: b" => ['Invalid CSS after ".foo ": expected selector, was "^bar"', 1],
37
- "a\n @extend .foo ^bar" => 'Invalid CSS after ".foo ": expected selector, was "^bar"',
38
- "a: b" => 'Properties aren\'t allowed at the root of a document.',
39
- ":a b" => 'Properties aren\'t allowed at the root of a document.',
40
- "!" => 'Invalid variable: "!".',
41
- "$a" => 'Invalid variable: "$a".',
42
- "! a" => 'Invalid variable: "! a".',
43
- "$a b" => 'Invalid variable: "$a b".',
44
- "$a: 1b + 2c" => "Incompatible units: 'c' and 'b'.",
45
- "$a: 1b < 2c" => "Incompatible units: 'c' and 'b'.",
46
- "$a: 1b > 2c" => "Incompatible units: 'c' and 'b'.",
47
- "$a: 1b <= 2c" => "Incompatible units: 'c' and 'b'.",
48
- "$a: 1b >= 2c" => "Incompatible units: 'c' and 'b'.",
49
- "a\n b: 1b * 2c" => "2b*c isn't a valid CSS value.",
50
- "a\n b: 1b % 2c" => "Cannot modulo by a number with units: 2c.",
51
- "$a: 2px + #ccc" => "Cannot add a number with units (2px) to a color (#cccccc).",
52
- "$a: #ccc + 2px" => "Cannot add a number with units (2px) to a color (#cccccc).",
53
- "& a\n :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
54
- "a\n :b\n c" => "Illegal nesting: Only properties may be nested beneath properties.",
55
- "a,\n :b c" => ["Rules can\'t end in commas.", 1],
56
- "a," => "Rules can\'t end in commas.",
57
- "a,\n$b: 1" => ["Rules can\'t end in commas.", 1],
58
- "$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
59
- "@import foo.sass" => "File to import not found or unreadable: foo.sass.",
60
- "a,\n$b: 1" => ["Rules can\'t end in commas.", 1],
61
- "$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
62
- "@import foo.sass" => <<MSG,
63
- File to import not found or unreadable: foo.sass.
64
- Load paths:
65
- #{File.dirname(__FILE__)}
66
- .
67
- MSG
68
- "@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
69
- "foo\n @import templates/basic" => "Import directives may only be used at the root of a document.",
70
- "foo\n @import #{File.dirname(__FILE__)}/templates/basic" => "Import directives may only be used at the root of a document.",
71
- '$foo: "bar" "baz" !' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "!"},
72
- "=foo\n :color red\n.bar\n +bang" => "Undefined mixin 'bang'.",
73
- "=foo\n :color red\n.bar\n +bang_bop" => "Undefined mixin 'bang_bop'.",
74
- "=foo\n :color red\n.bar\n +bang-bop" => "Undefined mixin 'bang-bop'.",
75
- ".bar\n =foo\n :color red\n" => ["Mixins may only be defined at the root of a document.", 2],
76
- "=foo\n :color red\n.bar\n +foo\n :color red" => "Illegal nesting: Nothing may be nested beneath mixin directives.",
77
- " a\n b: c" => ["Indenting at the beginning of the document is illegal.", 1],
78
- " \n \n\t\n a\n b: c" => ["Indenting at the beginning of the document is illegal.", 4],
79
- "a\n b: c\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 3],
80
- "a\n b: c\na\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 4],
81
- "a\n\t\tb: c\n\tb: c" => ["Inconsistent indentation: 1 tab was used for indentation, but the rest of the document was indented using 2 tabs.", 3],
82
- "a\n b: c\n b: c" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 3],
83
- "a\n b: c\n a\n d: e" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 4],
84
- "a\n b: c\na\n d: e" => ["The line was indented 2 levels deeper than the previous line.", 4],
85
- "a\n b: c\n a\n d: e" => ["The line was indented 3 levels deeper than the previous line.", 4],
86
- "a\n \tb: c" => ["Indentation can't use both tabs and spaces.", 2],
87
- "=a(" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ""',
88
- "=a(b)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "b)"',
89
- "=a(,)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ",)"',
90
- "=a($)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "$)"',
91
- "=a($foo bar)" => 'Invalid CSS after "($foo ": expected ")", was "bar)"',
92
- "=foo\n bar: baz\n+foo" => ["Properties aren't allowed at the root of a document.", 2],
93
- "a-\#{$b\n c: d" => ['Invalid CSS after "a-#{$b": expected "}", was ""', 1],
94
- "=a($b = 1, $c)" => "Required argument $c must come before any optional arguments.",
95
- "=a($b = 1)\n a: $b\ndiv\n +a(1,2)" => "Mixin a takes 1 argument but 2 were passed.",
96
- "=a($b)\n a: $b\ndiv\n +a" => "Mixin a is missing parameter $b.",
97
- "@else\n a\n b: c" => ["@else must come after @if.", 1],
98
- "@if false\n@else foo" => "Invalid else directive '@else foo': expected 'if <expr>'.",
99
- "@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
100
- "a\n !b: 12\nc\n d: !b" => 'Undefined variable: "$b".',
101
- "a\n $b: 12\nc\n d: $b" => 'Undefined variable: "$b".',
102
- "=foo\n $b: 12\nc\n +foo\n d: $b" => 'Undefined variable: "$b".',
103
- "c\n d: $b-foo" => 'Undefined variable: "$b-foo".',
104
- "c\n d: $b_foo" => 'Undefined variable: "$b_foo".',
105
- '@for $a from "foo" to 1' => '"foo" is not an integer.',
106
- '@for $a from 1 to "2"' => '"2" is not an integer.',
107
- '@for $a from 1 to "foo"' => '"foo" is not an integer.',
108
- '@for $a from 1 to 1.232323' => '1.232 is not an integer.',
109
- '@for $a from 1px to 3em' => "Incompatible units: 'em' and 'px'.",
110
- '@if' => "Invalid if directive '@if': expected expression.",
111
- '@while' => "Invalid while directive '@while': expected expression.",
112
- '@debug' => "Invalid debug directive '@debug': expected expression.",
113
- %Q{@debug "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath debug directives.",
114
- '@warn' => "Invalid warn directive '@warn': expected expression.",
115
- %Q{@warn "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath warn directives.",
116
- "/* foo\n bar\n baz" => "Inconsistent indentation: previous line was indented by 4 spaces, but this line was indented by 2 spaces.",
117
- "@if foo\n @extend .bar" => ["Extend directives may only be used within rules.", 2],
118
- "$var: true\n@while $var\n @extend .bar\n $var: false" => ["Extend directives may only be used within rules.", 3],
119
- "@for $i from 0 to 1\n @extend .bar" => ["Extend directives may only be used within rules.", 2],
120
- "@mixin foo\n @extend .bar\n@include foo" => ["Extend directives may only be used within rules.", 2],
121
-
122
- # Regression tests
123
- "a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3],
124
- "& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
125
- "a\n b: c\n& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 3],
126
- }
127
-
128
- def teardown
129
- clean_up_sassc
130
- end
131
-
132
- def test_basic_render
133
- renders_correctly "basic", { :style => :compact }
134
- end
135
-
136
- def test_empty_render
137
- assert_equal "", render("")
138
- end
139
-
140
- def test_multiple_calls_to_render
141
- sass = Sass::Engine.new("a\n b: c")
142
- assert_equal sass.render, sass.render
143
- end
144
-
145
- def test_alternate_styles
146
- renders_correctly "expanded", { :style => :expanded }
147
- renders_correctly "compact", { :style => :compact }
148
- renders_correctly "nested", { :style => :nested }
149
- renders_correctly "compressed", { :style => :compressed }
150
- end
151
-
152
- def test_flexible_tabulation
153
- assert_equal("p {\n a: b; }\n p q {\n c: d; }\n",
154
- render("p\n a: b\n q\n c: d\n"))
155
- assert_equal("p {\n a: b; }\n p q {\n c: d; }\n",
156
- render("p\n\ta: b\n\tq\n\t\tc: d\n"))
157
- end
158
-
159
- EXCEPTION_MAP.each do |key, value|
160
- define_method("test_exception (#{key.inspect})") do
161
- line = 10
162
- begin
163
- silence_warnings {Sass::Engine.new(key, :filename => __FILE__, :line => line).render}
164
- rescue Sass::SyntaxError => err
165
- value = [value] unless value.is_a?(Array)
166
-
167
- assert_equal(value.first.rstrip, err.message, "Line: #{key}")
168
- assert_equal(__FILE__, err.sass_filename)
169
- assert_equal((value[1] || key.split("\n").length) + line - 1, err.sass_line, "Line: #{key}")
170
- assert_match(/#{Regexp.escape(__FILE__)}:[0-9]+/, err.backtrace[0], "Line: #{key}")
171
- else
172
- assert(false, "Exception not raised for\n#{key}")
173
- end
174
- end
175
- end
176
-
177
- def test_exception_line
178
- to_render = <<SASS
179
- rule
180
- :prop val
181
- // comment!
182
-
183
- :broken
184
- SASS
185
- begin
186
- Sass::Engine.new(to_render).render
187
- rescue Sass::SyntaxError => err
188
- assert_equal(5, err.sass_line)
189
- else
190
- assert(false, "Exception not raised for '#{to_render}'!")
191
- end
192
- end
193
-
194
- def test_exception_location
195
- to_render = <<SASS
196
- rule
197
- :prop val
198
- // comment!
199
-
200
- :broken
201
- SASS
202
- begin
203
- Sass::Engine.new(to_render, :filename => __FILE__, :line => (__LINE__-7)).render
204
- rescue Sass::SyntaxError => err
205
- assert_equal(__FILE__, err.sass_filename)
206
- assert_equal((__LINE__-6), err.sass_line)
207
- else
208
- assert(false, "Exception not raised for '#{to_render}'!")
209
- end
210
- end
211
-
212
- def test_imported_exception
213
- [1, 2, 3, 4].each do |i|
214
- begin
215
- Sass::Engine.new("@import bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
216
- rescue Sass::SyntaxError => err
217
- assert_equal(2, err.sass_line)
218
- assert_match(/(\/|^)bork#{i}\.sass$/, err.sass_filename)
219
-
220
- assert_hash_has(err.sass_backtrace.first,
221
- :filename => err.sass_filename, :line => err.sass_line)
222
-
223
- assert_nil(err.sass_backtrace[1][:filename])
224
- assert_equal(1, err.sass_backtrace[1][:line])
225
-
226
- assert_match(/(\/|^)bork#{i}\.sass:2$/, err.backtrace.first)
227
- assert_equal("(sass):1", err.backtrace[1])
228
- else
229
- assert(false, "Exception not raised for imported template: bork#{i}")
230
- end
231
- end
232
- end
233
-
234
- def test_double_imported_exception
235
- [1, 2, 3, 4].each do |i|
236
- begin
237
- Sass::Engine.new("@import nested_bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
238
- rescue Sass::SyntaxError => err
239
- assert_equal(2, err.sass_line)
240
- assert_match(/(\/|^)bork#{i}\.sass$/, err.sass_filename)
241
-
242
- assert_hash_has(err.sass_backtrace.first,
243
- :filename => err.sass_filename, :line => err.sass_line)
244
-
245
- assert_match(/(\/|^)nested_bork#{i}\.sass$/, err.sass_backtrace[1][:filename])
246
- assert_equal(2, err.sass_backtrace[1][:line])
247
-
248
- assert_nil(err.sass_backtrace[2][:filename])
249
- assert_equal(1, err.sass_backtrace[2][:line])
250
-
251
- assert_match(/(\/|^)bork#{i}\.sass:2$/, err.backtrace.first)
252
- assert_match(/(\/|^)nested_bork#{i}\.sass:2$/, err.backtrace[1])
253
- assert_equal("(sass):1", err.backtrace[2])
254
- else
255
- assert(false, "Exception not raised for imported template: bork#{i}")
256
- end
257
- end
258
- end
259
-
260
- def test_mixin_exception
261
- render(<<SASS)
262
- =error-mixin($a)
263
- color: $a * 1em * 1px
264
-
265
- =outer-mixin($a)
266
- +error-mixin($a)
267
-
268
- .error
269
- +outer-mixin(12)
270
- SASS
271
- assert(false, "Exception not raised")
272
- rescue Sass::SyntaxError => err
273
- assert_equal(2, err.sass_line)
274
- assert_equal(filename_for_test, err.sass_filename)
275
- assert_equal("error-mixin", err.sass_mixin)
276
-
277
- assert_hash_has(err.sass_backtrace.first, :line => err.sass_line,
278
- :filename => err.sass_filename, :mixin => err.sass_mixin)
279
- assert_hash_has(err.sass_backtrace[1], :line => 5,
280
- :filename => filename_for_test, :mixin => "outer-mixin")
281
- assert_hash_has(err.sass_backtrace[2], :line => 8,
282
- :filename => filename_for_test, :mixin => nil)
283
-
284
- assert_equal("#{filename_for_test}:2:in `error-mixin'", err.backtrace.first)
285
- assert_equal("#{filename_for_test}:5:in `outer-mixin'", err.backtrace[1])
286
- assert_equal("#{filename_for_test}:8", err.backtrace[2])
287
- end
288
-
289
- def test_mixin_callsite_exception
290
- render(<<SASS)
291
- =one-arg-mixin($a)
292
- color: $a
293
-
294
- =outer-mixin($a)
295
- +one-arg-mixin($a, 12)
296
-
297
- .error
298
- +outer-mixin(12)
299
- SASS
300
- assert(false, "Exception not raised")
301
- rescue Sass::SyntaxError => err
302
- assert_hash_has(err.sass_backtrace.first, :line => 5,
303
- :filename => filename_for_test, :mixin => "one-arg-mixin")
304
- assert_hash_has(err.sass_backtrace[1], :line => 5,
305
- :filename => filename_for_test, :mixin => "outer-mixin")
306
- assert_hash_has(err.sass_backtrace[2], :line => 8,
307
- :filename => filename_for_test, :mixin => nil)
308
- end
309
-
310
- def test_mixin_exception_cssize
311
- render(<<SASS)
312
- =parent-ref-mixin
313
- & foo
314
- a: b
315
-
316
- =outer-mixin
317
- +parent-ref-mixin
318
-
319
- +outer-mixin
320
- SASS
321
- assert(false, "Exception not raised")
322
- rescue Sass::SyntaxError => err
323
- assert_hash_has(err.sass_backtrace.first, :line => 2,
324
- :filename => filename_for_test, :mixin => "parent-ref-mixin")
325
- assert_hash_has(err.sass_backtrace[1], :line => 6,
326
- :filename => filename_for_test, :mixin => "outer-mixin")
327
- assert_hash_has(err.sass_backtrace[2], :line => 8,
328
- :filename => filename_for_test, :mixin => nil)
329
- end
330
-
331
- def test_mixin_and_import_exception
332
- Sass::Engine.new("@import nested_mixin_bork", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
333
- assert(false, "Exception not raised")
334
- rescue Sass::SyntaxError => err
335
- assert_match(/(\/|^)nested_mixin_bork\.sass$/, err.sass_backtrace.first[:filename])
336
- assert_hash_has(err.sass_backtrace.first, :mixin => "error-mixin", :line => 4)
337
-
338
- assert_match(/(\/|^)mixin_bork\.sass$/, err.sass_backtrace[1][:filename])
339
- assert_hash_has(err.sass_backtrace[1], :mixin => "outer-mixin", :line => 2)
340
-
341
- assert_match(/(\/|^)mixin_bork\.sass$/, err.sass_backtrace[2][:filename])
342
- assert_hash_has(err.sass_backtrace[2], :mixin => nil, :line => 5)
343
-
344
- assert_match(/(\/|^)nested_mixin_bork\.sass$/, err.sass_backtrace[3][:filename])
345
- assert_hash_has(err.sass_backtrace[3], :mixin => nil, :line => 6)
346
-
347
- assert_hash_has(err.sass_backtrace[4], :filename => nil, :mixin => nil, :line => 1)
348
- end
349
-
350
- def test_basic_mixin_loop_exception
351
- render <<SASS
352
- @mixin foo
353
- @include foo
354
- @include foo
355
- SASS
356
- assert(false, "Exception not raised")
357
- rescue Sass::SyntaxError => err
358
- assert_equal("An @include loop has been found: foo includes itself", err.message)
359
- assert_hash_has(err.sass_backtrace[0], :mixin => "foo", :line => 2)
360
- end
361
-
362
- def test_double_mixin_loop_exception
363
- render <<SASS
364
- @mixin foo
365
- @include bar
366
- @mixin bar
367
- @include foo
368
- @include foo
369
- SASS
370
- assert(false, "Exception not raised")
371
- rescue Sass::SyntaxError => err
372
- assert_equal(<<MESSAGE.rstrip, err.message)
373
- An @include loop has been found:
374
- foo includes bar
375
- bar includes foo
376
- MESSAGE
377
- assert_hash_has(err.sass_backtrace[0], :mixin => "bar", :line => 4)
378
- assert_hash_has(err.sass_backtrace[1], :mixin => "foo", :line => 2)
379
- end
380
-
381
- def test_deep_mixin_loop_exception
382
- render <<SASS
383
- @mixin foo
384
- @include bar
385
-
386
- @mixin bar
387
- @include baz
388
-
389
- @mixin baz
390
- @include foo
391
-
392
- @include foo
393
- SASS
394
- assert(false, "Exception not raised")
395
- rescue Sass::SyntaxError => err
396
- assert_equal(<<MESSAGE.rstrip, err.message)
397
- An @include loop has been found:
398
- foo includes bar
399
- bar includes baz
400
- baz includes foo
401
- MESSAGE
402
- assert_hash_has(err.sass_backtrace[0], :mixin => "baz", :line => 8)
403
- assert_hash_has(err.sass_backtrace[1], :mixin => "bar", :line => 5)
404
- assert_hash_has(err.sass_backtrace[2], :mixin => "foo", :line => 2)
405
- end
406
-
407
- def test_exception_css_with_offset
408
- opts = {:full_exception => true, :line => 362}
409
- render(("a\n b: c\n" * 10) + "d\n e:\n" + ("f\n g: h\n" * 10), opts)
410
- rescue Sass::SyntaxError => e
411
- assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..15].join("\n"))
412
- /*
413
- Syntax error: Invalid property: "e:" (no value).
414
- on line 383 of test_exception_css_with_offset_inline.sass
415
-
416
- 378: a
417
- 379: b: c
418
- 380: a
419
- 381: b: c
420
- 382: d
421
- 383: e:
422
- 384: f
423
- 385: g: h
424
- 386: f
425
- 387: g: h
426
- 388: f
427
- CSS
428
- else
429
- assert(false, "Exception not raised for test_exception_css_with_offset")
430
- end
431
-
432
- def test_exception_css_with_mixins
433
- opts = {:full_exception => true}
434
- render(<<SASS, opts)
435
- =error-mixin($a)
436
- color: $a * 1em * 1px
437
-
438
- =outer-mixin($a)
439
- +error-mixin($a)
440
-
441
- .error
442
- +outer-mixin(12)
443
- SASS
444
- rescue Sass::SyntaxError => e
445
- assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..13].join("\n"))
446
- /*
447
- Syntax error: 12em*px isn't a valid CSS value.
448
- on line 2 of test_exception_css_with_mixins_inline.sass, in `error-mixin'
449
- from line 5 of test_exception_css_with_mixins_inline.sass, in `outer-mixin'
450
- from line 8 of test_exception_css_with_mixins_inline.sass
451
-
452
- 1: =error-mixin($a)
453
- 2: color: $a * 1em * 1px
454
- 3:
455
- 4: =outer-mixin($a)
456
- 5: +error-mixin($a)
457
- 6:
458
- 7: .error
459
- CSS
460
- else
461
- assert(false, "Exception not raised")
462
- end
463
-
464
- def test_cssize_exception_css
465
- opts = {:full_exception => true}
466
- render(<<SASS, opts)
467
- .filler
468
- stuff: "stuff!"
469
-
470
- a: b
471
-
472
- .more.filler
473
- a: b
474
- SASS
475
- rescue Sass::SyntaxError => e
476
- assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts).split("\n")[0..11].join("\n"))
477
- /*
478
- Syntax error: Properties aren't allowed at the root of a document.
479
- on line 4 of test_cssize_exception_css_inline.sass
480
-
481
- 1: .filler
482
- 2: stuff: "stuff!"
483
- 3:
484
- 4: a: b
485
- 5:
486
- 6: .more.filler
487
- 7: a: b
488
- CSS
489
- else
490
- assert(false, "Exception not raised")
491
- end
492
-
493
- def test_css_import
494
- assert_equal("@import url(./fonts.css);\n", render("@import \"./fonts.css\""))
495
- end
496
-
497
- def test_http_import
498
- assert_equal("@import url(http://fonts.googleapis.com/css?family=Droid+Sans);\n",
499
- render("@import \"http://fonts.googleapis.com/css?family=Droid+Sans\""))
500
- end
501
-
502
- def test_url_import
503
- assert_equal("@import url(fonts.sass);\n", render("@import url(fonts.sass)"))
504
- end
505
-
506
- def test_sass_import
507
- assert !File.exists?(sassc_path("importee"))
508
- renders_correctly "import", { :style => :compact, :load_paths => [File.dirname(__FILE__) + "/templates"] }
509
- assert File.exists?(sassc_path("importee"))
510
- end
511
-
512
- def test_nonexistent_extensionless_import
513
- assert_warning(<<WARN) do
514
- WARNING: Neither nonexistent.sass nor .scss found. Using nonexistent.css instead.
515
- This behavior is deprecated and will be removed in a future version.
516
- If you really need nonexistent.css, import it explicitly.
517
- WARN
518
- assert_equal("@import url(nonexistent.css);\n", render("@import nonexistent"))
519
- end
520
- end
521
-
522
- def test_no_cache
523
- assert !File.exists?(sassc_path("importee"))
524
- renders_correctly("import", {
525
- :style => :compact, :cache => false,
526
- :load_paths => [File.dirname(__FILE__) + "/templates"],
527
- })
528
- assert !File.exists?(sassc_path("importee"))
529
- end
530
-
531
- def test_units
532
- renders_correctly "units"
533
- end
534
-
535
- def test_default_function
536
- assert_equal(<<CSS, render(<<SASS))
537
- foo {
538
- bar: url("foo.png"); }
539
- CSS
540
- foo
541
- bar: url("foo.png")
542
- SASS
543
- assert_equal("foo {\n bar: url(); }\n", render("foo\n bar: url()\n"));
544
- end
545
-
546
- def test_string_minus
547
- assert_equal("foo {\n bar: baz-boom-bat; }\n", render(%Q{foo\n bar: baz-boom-bat}))
548
- assert_equal("foo {\n bar: -baz-boom; }\n", render(%Q{foo\n bar: -baz-boom}))
549
- end
550
-
551
- def test_string_div
552
- assert_equal("foo {\n bar: baz/boom/bat; }\n", render(%Q{foo\n bar: baz/boom/bat}))
553
- assert_equal("foo {\n bar: /baz/boom; }\n", render(%Q{foo\n bar: /baz/boom}))
554
- end
555
-
556
- def test_basic_multiline_selector
557
- assert_equal("#foo #bar,\n#baz #boom {\n foo: bar; }\n",
558
- render("#foo #bar,\n#baz #boom\n :foo bar"))
559
- assert_equal("#foo #bar,\n#foo #baz {\n foo: bar; }\n",
560
- render("#foo\n #bar,\n #baz\n :foo bar"))
561
- assert_equal("#foo,\n#bar {\n foo: bar; }\n #foo #baz,\n #bar #baz {\n foo: bar; }\n",
562
- render("#foo,\n#bar\n :foo bar\n #baz\n :foo bar"))
563
- assert_equal("#foo #bar, #baz #boom { foo: bar; }\n",
564
- render("#foo #bar,\n#baz #boom\n :foo bar", :style => :compact))
565
-
566
- assert_equal("#foo #bar,#baz #boom{foo:bar}\n",
567
- render("#foo #bar,\n#baz #boom\n :foo bar", :style => :compressed))
568
- end
569
-
570
- def test_complex_multiline_selector
571
- renders_correctly "multiline"
572
- end
573
-
574
- def test_colon_only
575
- begin
576
- render("a\n b: c", :property_syntax => :old)
577
- rescue Sass::SyntaxError => e
578
- assert_equal("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.",
579
- e.message)
580
- assert_equal(2, e.sass_line)
581
- else
582
- assert(false, "SyntaxError not raised for :property_syntax => :old")
583
- end
584
-
585
- begin
586
- render("a\n :b c", :property_syntax => :new)
587
- assert_equal(2, e.sass_line)
588
- rescue Sass::SyntaxError => e
589
- assert_equal("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.",
590
- e.message)
591
- else
592
- assert(false, "SyntaxError not raised for :property_syntax => :new")
593
- end
594
- end
595
-
596
- def test_pseudo_elements
597
- assert_equal(<<CSS, render(<<SASS))
598
- ::first-line {
599
- size: 10em; }
600
- CSS
601
- ::first-line
602
- size: 10em
603
- SASS
604
- end
605
-
606
- def test_directive
607
- assert_equal("@a b;\n", render("@a b"))
608
-
609
- assert_equal("@a {\n b: c; }\n", render("@a\n :b c"))
610
- assert_equal("@a { b: c; }\n", render("@a\n :b c", :style => :compact))
611
- assert_equal("@a {\n b: c;\n}\n", render("@a\n :b c", :style => :expanded))
612
- assert_equal("@a{b:c}\n", render("@a\n :b c", :style => :compressed))
613
-
614
- assert_equal("@a {\n b: c;\n d: e; }\n",
615
- render("@a\n :b c\n :d e"))
616
- assert_equal("@a { b: c; d: e; }\n",
617
- render("@a\n :b c\n :d e", :style => :compact))
618
- assert_equal("@a {\n b: c;\n d: e;\n}\n",
619
- render("@a\n :b c\n :d e", :style => :expanded))
620
- assert_equal("@a{b:c;d:e}\n",
621
- render("@a\n :b c\n :d e", :style => :compressed))
622
-
623
- assert_equal("@a {\n #b {\n c: d; } }\n",
624
- render("@a\n #b\n :c d"))
625
- assert_equal("@a { #b { c: d; } }\n",
626
- render("@a\n #b\n :c d", :style => :compact))
627
- assert_equal("@a {\n #b {\n c: d;\n }\n}\n",
628
- render("@a\n #b\n :c d", :style => :expanded))
629
- assert_equal("@a{#b{c:d}}\n",
630
- render("@a\n #b\n :c d", :style => :compressed))
631
-
632
- assert_equal("@a {\n #b {\n a: b; }\n #b #c {\n d: e; } }\n",
633
- render("@a\n #b\n :a b\n #c\n :d e"))
634
- assert_equal("@a { #b { a: b; }\n #b #c { d: e; } }\n",
635
- render("@a\n #b\n :a b\n #c\n :d e", :style => :compact))
636
- assert_equal("@a {\n #b {\n a: b;\n }\n #b #c {\n d: e;\n }\n}\n",
637
- render("@a\n #b\n :a b\n #c\n :d e", :style => :expanded))
638
- assert_equal("@a{#b{a:b}#b #c{d:e}}\n",
639
- render("@a\n #b\n :a b\n #c\n :d e", :style => :compressed))
640
-
641
- assert_equal("@a {\n #foo,\n #bar {\n b: c; } }\n",
642
- render("@a\n #foo, \n #bar\n :b c"))
643
- assert_equal("@a { #foo, #bar { b: c; } }\n",
644
- render("@a\n #foo, \n #bar\n :b c", :style => :compact))
645
- assert_equal("@a {\n #foo,\n #bar {\n b: c;\n }\n}\n",
646
- render("@a\n #foo, \n #bar\n :b c", :style => :expanded))
647
- assert_equal("@a{#foo,#bar{b:c}}\n",
648
- render("@a\n #foo, \n #bar\n :b c", :style => :compressed))
649
-
650
- to_render = <<END
651
- @a
652
- :b c
653
- #d
654
- :e f
655
- :g h
656
- END
657
- rendered = <<END
658
- @a { b: c;
659
- #d { e: f; }
660
- g: h; }
661
- END
662
- assert_equal(rendered, render(to_render, :style => :compact))
663
-
664
- assert_equal("@a{b:c;#d{e:f}g:h}\n", render(to_render, :style => :compressed))
665
- end
666
-
667
- def test_property_hacks
668
- assert_equal(<<CSS, render(<<SASS))
669
- foo {
670
- _name: val;
671
- *name: val;
672
- #name: val;
673
- .name: val;
674
- name/**/: val;
675
- name/*\\**/: val;
676
- name: val; }
677
- CSS
678
- foo
679
- _name: val
680
- *name: val
681
- #name: val
682
- .name: val
683
- name/**/: val
684
- name/*\\**/: val
685
- name: val
686
- SASS
687
- end
688
-
689
- def test_properties_with_space_after_colon
690
- assert_equal <<CSS, render(<<SASS)
691
- foo {
692
- bar: baz;
693
- bizz: bap; }
694
- CSS
695
- foo
696
- bar : baz
697
- bizz : bap
698
- SASS
699
- end
700
-
701
- def test_line_annotations
702
- assert_equal(<<CSS, render(<<SASS, :line_comments => true, :style => :compact))
703
- /* line 2, test_line_annotations_inline.sass */
704
- foo bar { foo: bar; }
705
- /* line 5, test_line_annotations_inline.sass */
706
- foo baz { blip: blop; }
707
-
708
- /* line 9, test_line_annotations_inline.sass */
709
- floodle { flop: blop; }
710
-
711
- /* line 18, test_line_annotations_inline.sass */
712
- bup { mix: on; }
713
- /* line 15, test_line_annotations_inline.sass */
714
- bup mixin { moop: mup; }
715
-
716
- /* line 22, test_line_annotations_inline.sass */
717
- bip hop, skip hop { a: b; }
718
- CSS
719
- foo
720
- bar
721
- foo: bar
722
-
723
- baz
724
- blip: blop
725
-
726
-
727
- floodle
728
-
729
- flop: blop
730
-
731
- =mxn
732
- mix: on
733
- mixin
734
- moop: mup
735
-
736
- bup
737
- +mxn
738
-
739
- bip, skip
740
- hop
741
- a: b
742
- SASS
743
- end
744
-
745
- def test_line_annotations_with_filename
746
- renders_correctly "line_numbers", :line_comments => true, :load_paths => [File.dirname(__FILE__) + "/templates"]
747
- end
748
-
749
- def test_debug_info
750
- esc_file_name = Sass::SCSS::RX.escape_ident(Haml::Util.scope("test_debug_info_inline.sass"))
751
-
752
- assert_equal(<<CSS, render(<<SASS, :debug_info => true, :style => :compact))
753
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000032}}
754
- foo bar { foo: bar; }
755
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000035}}
756
- foo baz { blip: blop; }
757
-
758
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000039}}
759
- floodle { flop: blop; }
760
-
761
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\0000318}}
762
- bup { mix: on; }
763
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\0000315}}
764
- bup mixin { moop: mup; }
765
-
766
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\0000322}}
767
- bip hop, skip hop { a: b; }
768
- CSS
769
- foo
770
- bar
771
- foo: bar
772
-
773
- baz
774
- blip: blop
775
-
776
-
777
- floodle
778
-
779
- flop: blop
780
-
781
- =mxn
782
- mix: on
783
- mixin
784
- moop: mup
785
-
786
- bup
787
- +mxn
788
-
789
- bip, skip
790
- hop
791
- a: b
792
- SASS
793
- end
794
-
795
- def test_debug_info_without_filename
796
- assert_equal(<<CSS, Sass::Engine.new(<<SASS, :debug_info => true).render)
797
- @media -sass-debug-info{filename{font-family:}line{font-family:\\000031}}
798
- foo {
799
- a: b; }
800
- CSS
801
- foo
802
- a: b
803
- SASS
804
- end
805
-
806
- def test_debug_info_with_compressed
807
- assert_equal(<<CSS, render(<<SASS, :debug_info => true, :style => :compressed))
808
- foo{a:b}
809
- CSS
810
- foo
811
- a: b
812
- SASS
813
- end
814
-
815
- def test_debug_info_with_line_annotations
816
- esc_file_name = Sass::SCSS::RX.escape_ident(Haml::Util.scope("test_debug_info_with_line_annotations_inline.sass"))
817
-
818
- assert_equal(<<CSS, render(<<SASS, :debug_info => true, :line_comments => true))
819
- @media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000031}}
820
- foo {
821
- a: b; }
822
- CSS
823
- foo
824
- a: b
825
- SASS
826
- end
827
-
828
- def test_empty_first_line
829
- assert_equal("#a {\n b: c; }\n", render("#a\n\n b: c"))
830
- end
831
-
832
- def test_escaped_rule
833
- assert_equal(":focus {\n a: b; }\n", render("\\:focus\n a: b"))
834
- assert_equal("a {\n b: c; }\n a :focus {\n d: e; }\n", render("\\a\n b: c\n \\:focus\n d: e"))
835
- end
836
-
837
- def test_cr_newline
838
- assert_equal("foo {\n a: b;\n c: d;\n e: f; }\n", render("foo\r a: b\r\n c: d\n\r e: f"))
839
- end
840
-
841
- def test_property_with_content_and_nested_props
842
- assert_equal(<<CSS, render(<<SASS))
843
- foo {
844
- a: b;
845
- a-c: d;
846
- a-c-e: f; }
847
- CSS
848
- foo
849
- a: b
850
- c: d
851
- e: f
852
- SASS
853
-
854
- assert_equal(<<CSS, render(<<SASS))
855
- foo {
856
- a: b;
857
- a-c-e: f; }
858
- CSS
859
- foo
860
- a: b
861
- c:
862
- e: f
863
- SASS
864
- end
865
-
866
- def test_equals_warning_for_properties
867
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
868
- DEPRECATION WARNING:
869
- On line 3, character 3 of 'test_equals_warning_for_properties_inline.sass'
870
- Setting properties with = has been deprecated and will be removed in version 3.2.
871
- Use "a: $var" instead.
872
-
873
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
874
- WARN
875
- foo {
876
- a: 2px 3px; }
877
- CSS
878
- $var: 2px 3px
879
- foo
880
- a = $var
881
- SASS
882
- end
883
-
884
- def test_equals_warning_for_dynamic_properties
885
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
886
- DEPRECATION WARNING:
887
- On line 4, character 3 of 'test_equals_warning_for_dynamic_properties_inline.sass'
888
- Setting properties with = has been deprecated and will be removed in version 3.2.
889
- Use "a-\#{$i}: $var" instead.
890
-
891
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
892
- WARN
893
- foo {
894
- a-12: 2px 3px; }
895
- CSS
896
- $var: 2px 3px
897
- $i: 12
898
- foo
899
- a-\#{$i} = $var
900
- SASS
901
- end
902
-
903
- def test_equals_warning_for_property_with_string
904
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
905
- DEPRECATION WARNING:
906
- On line 2, character 3 of 'test_equals_warning_for_property_with_string_inline.sass'
907
- Setting properties with = has been deprecated and will be removed in version 3.2.
908
- Use "a: foo" instead.
909
-
910
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
911
- WARN
912
- foo {
913
- a: foo; }
914
- CSS
915
- foo
916
- a = "foo"
917
- SASS
918
- end
919
-
920
- def test_equals_warning_for_property_with_division
921
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
922
- DEPRECATION WARNING:
923
- On line 2, character 3 of 'test_equals_warning_for_property_with_division_inline.sass'
924
- Setting properties with = has been deprecated and will be removed in version 3.2.
925
- Use "a: (1px / 2px)" instead.
926
-
927
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
928
- WARN
929
- foo {
930
- a: 0.5; }
931
- CSS
932
- foo
933
- a = 1px/2px
934
- SASS
935
- end
936
-
937
- def test_guarded_assign
938
- assert_equal("foo {\n a: b; }\n", render(%Q{$foo: b\n$foo: c !default\nfoo\n a: $foo}))
939
- assert_equal("foo {\n a: b; }\n", render(%Q{$foo: b !default\nfoo\n a: $foo}))
940
- end
941
-
942
- def test_mixins
943
- renders_correctly "mixins", { :style => :expanded }
944
- end
945
-
946
- def test_directive_style_mixins
947
- assert_equal <<CSS, render(<<SASS)
948
- bar {
949
- prop: baz; }
950
- CSS
951
- @mixin foo($arg)
952
- prop: $arg
953
-
954
- bar
955
- @include foo(baz)
956
- SASS
957
- end
958
-
959
- def test_mixins_dont_interfere_with_sibling_combinator
960
- assert_equal("foo + bar {\n a: b; }\nfoo + baz {\n c: d; }\n",
961
- render("foo\n +\n bar\n a: b\n baz\n c: d"))
962
- end
963
-
964
- def test_mixin_args
965
- assert_equal("blat {\n baz: hi; }\n", render(<<SASS))
966
- =foo($bar)
967
- baz: $bar
968
- blat
969
- +foo(hi)
970
- SASS
971
- assert_equal("blat {\n baz: 3; }\n", render(<<SASS))
972
- =foo($a, $b)
973
- baz: $a + $b
974
- blat
975
- +foo(1, 2)
976
- SASS
977
- assert_equal("blat {\n baz: 4;\n baz: 3;\n baz: 5;\n bang: 3; }\n", render(<<SASS))
978
- =foo($c: (6 + 4) / 2)
979
- baz: $c
980
- $c: 3
981
- blat
982
- +foo($c + 1)
983
- +foo(($c + 3)/2)
984
- +foo
985
- bang: $c
986
- SASS
987
- end
988
-
989
- def test_default_values_for_mixin_arguments
990
- assert_equal("white {\n color: white; }\n\nblack {\n color: black; }\n", render(<<SASS))
991
- =foo($a: #FFF)
992
- :color $a
993
- white
994
- +foo
995
- black
996
- +foo(#000)
997
- SASS
998
- assert_equal(<<CSS, render(<<SASS))
999
- one {
1000
- color: white;
1001
- padding: 1px;
1002
- margin: 4px; }
1003
-
1004
- two {
1005
- color: white;
1006
- padding: 2px;
1007
- margin: 5px; }
1008
-
1009
- three {
1010
- color: white;
1011
- padding: 2px;
1012
- margin: 3px; }
1013
- CSS
1014
- $a: 5px
1015
- =foo($a, $b: 1px, $c: 3px + $b)
1016
- :color $a
1017
- :padding $b
1018
- :margin $c
1019
- one
1020
- +foo(#fff)
1021
- two
1022
- +foo(#fff, 2px)
1023
- three
1024
- +foo(#fff, 2px, 3px)
1025
- SASS
1026
- end
1027
-
1028
- def test_hyphen_underscore_insensitive_mixins
1029
- assert_equal(<<CSS, render(<<SASS))
1030
- a {
1031
- b: 12;
1032
- c: foo; }
1033
- CSS
1034
- =mixin-hyphen
1035
- b: 12
1036
-
1037
- =mixin_under
1038
- c: foo
1039
-
1040
- a
1041
- +mixin_hyphen
1042
- +mixin-under
1043
- SASS
1044
- end
1045
-
1046
- def test_equals_warning_for_mixin_args
1047
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
1048
- DEPRECATION WARNING:
1049
- On line 1, character 10 of 'test_equals_warning_for_mixin_args_inline.sass'
1050
- Setting mixin argument defaults with = has been deprecated and will be removed in version 3.2.
1051
- Use "$arg: 1px" instead.
1052
-
1053
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
1054
- WARN
1055
- bar {
1056
- a: 1px; }
1057
- CSS
1058
- =foo($arg = 1px)
1059
- a: $arg
1060
-
1061
- bar
1062
- +foo
1063
- SASS
1064
- end
1065
-
1066
- def test_css_identifier_mixin
1067
- assert_equal(<<CSS, render(<<SASS))
1068
- a {
1069
- foo: 12; }
1070
- CSS
1071
- =\\{foo\\(12\\)($a)
1072
- foo: $a
1073
-
1074
- a
1075
- +\\{foo\\(12\\)(12)
1076
- SASS
1077
- end
1078
-
1079
- def test_interpolation
1080
- assert_equal("a-1 {\n b-2-3: c-3; }\n", render(<<SASS))
1081
- $a: 1
1082
- $b: 2
1083
- $c: 3
1084
- a-\#{$a}
1085
- b-\#{$b}-\#{$c}: c-\#{$a + $b}
1086
- SASS
1087
- end
1088
-
1089
- def test_complex_property_interpolation
1090
- assert_equal(<<CSS, render(<<SASS))
1091
- a-1 {
1092
- b-2 3-fizzap18: c-3; }
1093
- CSS
1094
- $a: 1
1095
- $b: 2
1096
- $c: 3
1097
- a-\#{$a}
1098
- b-\#{$b $c}-\#{fizzap + ($c + 15)}: c-\#{$a + $b}
1099
- SASS
1100
- end
1101
-
1102
- def test_if_directive
1103
- assert_equal("a {\n b: 1; }\n", render(<<SASS))
1104
- $var: true
1105
- a
1106
- @if $var
1107
- b: 1
1108
- @if not $var
1109
- b: 2
1110
- SASS
1111
- end
1112
-
1113
- def test_for
1114
- assert_equal(<<CSS, render(<<SASS))
1115
- a-0 {
1116
- two-i: 0; }
1117
-
1118
- a-1 {
1119
- two-i: 2; }
1120
-
1121
- a-2 {
1122
- two-i: 4; }
1123
-
1124
- a-3 {
1125
- two-i: 6; }
1126
-
1127
- b-1 {
1128
- j-1: 0; }
1129
-
1130
- b-2 {
1131
- j-1: 1; }
1132
-
1133
- b-3 {
1134
- j-1: 2; }
1135
-
1136
- b-4 {
1137
- j-1: 3; }
1138
- CSS
1139
- $a: 3
1140
- @for $i from 0 to $a + 1
1141
- a-\#{$i}
1142
- two-i: 2 * $i
1143
-
1144
- @for $j from 1 through 4
1145
- b-\#{$j}
1146
- j-1: $j - 1
1147
- SASS
1148
- end
1149
-
1150
- def test_for_with_bang_var
1151
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
1152
- DEPRECATION WARNING:
1153
- On line 1, character 6 of 'test_for_with_bang_var_inline.sass'
1154
- Variables with ! have been deprecated and will be removed in version 3.2.
1155
- Use "$bar" instead.
1156
-
1157
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
1158
- WARN
1159
- a-0 {
1160
- b: c; }
1161
-
1162
- a-1 {
1163
- b: c; }
1164
-
1165
- a-2 {
1166
- b: c; }
1167
- CSS
1168
- @for !bar from 0 to 3
1169
- a-\#{$bar}
1170
- b: c
1171
- SASS
1172
- end
1173
-
1174
- def test_while
1175
- assert_equal(<<CSS, render(<<SASS))
1176
- a-5 {
1177
- blooble: gloop; }
1178
-
1179
- a-4 {
1180
- blooble: gloop; }
1181
-
1182
- a-3 {
1183
- blooble: gloop; }
1184
-
1185
- a-2 {
1186
- blooble: gloop; }
1187
-
1188
- a-1 {
1189
- blooble: gloop; }
1190
- CSS
1191
- $a: 5
1192
- @while $a != 0
1193
- a-\#{$a}
1194
- blooble: gloop
1195
- $a: $a - 1
1196
- SASS
1197
- end
1198
-
1199
- def test_else
1200
- assert_equal(<<CSS, render(<<SASS))
1201
- a {
1202
- t1: t;
1203
- t2: t;
1204
- t3: t;
1205
- t4: t; }
1206
- CSS
1207
- a
1208
- @if true
1209
- t1: t
1210
- @else
1211
- f1: f
1212
-
1213
- @if false
1214
- f2: f
1215
- @else
1216
- t2: t
1217
-
1218
- @if false
1219
- f3: f1
1220
- @else if 1 + 1 == 3
1221
- f3: f2
1222
- @else
1223
- t3: t
1224
-
1225
- @if false
1226
- f4: f1
1227
- @else if 1 + 1 == 2
1228
- t4: t
1229
- @else
1230
- f4: f2
1231
-
1232
- @if false
1233
- f5: f1
1234
- @else if false
1235
- f5: f2
1236
- SASS
1237
- end
1238
-
1239
- def test_variable_reassignment
1240
- assert_equal(<<CSS, render(<<SASS))
1241
- a {
1242
- b: 1;
1243
- c: 2; }
1244
- CSS
1245
- $a: 1
1246
- a
1247
- b: $a
1248
- $a: 2
1249
- c: $a
1250
- SASS
1251
- end
1252
-
1253
- def test_bang_variables
1254
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
1255
- DEPRECATION WARNING:
1256
- On line 1, character 1 of 'test_bang_variables_inline.sass'
1257
- Variables with ! have been deprecated and will be removed in version 3.2.
1258
- Use "$bang-var" instead.
1259
-
1260
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
1261
- WARN
1262
- foo {
1263
- a: 1px; }
1264
- CSS
1265
- !bang-var: 1px
1266
- foo
1267
- a: $bang-var
1268
- SASS
1269
-
1270
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
1271
- DEPRECATION WARNING:
1272
- On line 3, character 6 of 'test_bang_variables_inline.sass'
1273
- Variables with ! have been deprecated and will be removed in version 3.2.
1274
- Use "$dollar-var" instead.
1275
-
1276
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
1277
- WARN
1278
- foo {
1279
- a: 1px; }
1280
- CSS
1281
- $dollar-var: 1px
1282
- foo
1283
- a: !dollar-var
1284
- SASS
1285
- end
1286
-
1287
- def test_equals_warning_for_variables
1288
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
1289
- DEPRECATION WARNING:
1290
- On line 2, character 1 of 'test_equals_warning_for_variables_inline.sass'
1291
- Setting variables with = has been deprecated and will be removed in version 3.2.
1292
- Use "$equals-var: 2px 3px" instead.
1293
-
1294
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
1295
- WARN
1296
- foo {
1297
- a: 2px 3px; }
1298
- CSS
1299
-
1300
- $equals-var = 2px 3px
1301
- foo
1302
- a: $equals-var
1303
- SASS
1304
- end
1305
-
1306
- def test_equals_warning_for_guarded_variables
1307
- assert_warning(<<WARN) {assert_equal(<<CSS, render(<<SASS))}
1308
- DEPRECATION WARNING:
1309
- On line 2, character 1 of 'test_equals_warning_for_guarded_variables_inline.sass'
1310
- Setting variable defaults with ||= has been deprecated and will be removed in version 3.2.
1311
- Use "$equals-var: 2px 3px !default" instead.
1312
-
1313
- You can use `sass-convert --in-place --from sass2 file.sass' to convert files automatically.
1314
- WARN
1315
- foo {
1316
- a: 2px 3px; }
1317
- CSS
1318
-
1319
- $equals-var ||= 2px 3px
1320
- foo
1321
- a: $equals-var
1322
- SASS
1323
- end
1324
-
1325
- def test_variable_scope
1326
- assert_equal(<<CSS, render(<<SASS))
1327
- a {
1328
- b-1: c;
1329
- b-2: c;
1330
- d: 12; }
1331
-
1332
- b {
1333
- d: 17; }
1334
- CSS
1335
- $i: 12
1336
- a
1337
- @for $i from 1 through 2
1338
- b-\#{$i}: c
1339
- d: $i
1340
-
1341
- =foo
1342
- $i: 17
1343
-
1344
- b
1345
- +foo
1346
- d: $i
1347
- SASS
1348
- end
1349
-
1350
- def test_hyphen_underscore_insensitive_variables
1351
- assert_equal(<<CSS, render(<<SASS))
1352
- a {
1353
- b: c; }
1354
-
1355
- d {
1356
- e: 13;
1357
- f: foobar; }
1358
- CSS
1359
- $var-hyphen: 12
1360
- $var_under: foo
1361
-
1362
- a
1363
- $var_hyphen: 1 + $var_hyphen
1364
- $var-under: $var-under + bar
1365
- b: c
1366
-
1367
- d
1368
- e: $var-hyphen
1369
- f: $var_under
1370
- SASS
1371
- end
1372
-
1373
- def test_css_identifier_variable
1374
- assert_equal(<<CSS, render(<<SASS))
1375
- a {
1376
- b: 12; }
1377
- CSS
1378
- $\\{foo\\(12\\): 12
1379
-
1380
- a
1381
- b: $\\{foo\\(12\\)
1382
- SASS
1383
- end
1384
-
1385
- def test_important
1386
- assert_equal(<<CSS, render(<<SASS))
1387
- a {
1388
- b: 12px !important; }
1389
- CSS
1390
- $foo: 12px
1391
- a
1392
- b: $foo !important
1393
- SASS
1394
- end
1395
-
1396
- def test_argument_error
1397
- assert_raise(Sass::SyntaxError) { render("a\n b: hsl(1)") }
1398
- end
1399
-
1400
- def test_comments_at_the_top_of_a_document
1401
- render(<<SASS)
1402
- //
1403
- This is a comment that
1404
- continues to the second line.
1405
- foo
1406
- bar: baz
1407
- SASS
1408
- end
1409
-
1410
- def test_loud_comments_containing_a_comment_close
1411
- actual_css = render(<<SASS)
1412
- /*
1413
- This is a comment that
1414
- continues to the second line. */
1415
- foo
1416
- bar: baz
1417
- SASS
1418
- assert_equal(<<CSS, actual_css)
1419
- /* This is a comment that
1420
- * continues to the second line. */
1421
- foo {
1422
- bar: baz; }
1423
- CSS
1424
- end
1425
-
1426
- def test_loud_comments_with_starred_lines
1427
- assert_equal(<<CSS, render(<<SASS))
1428
- /* This is a comment that
1429
- * continues to the second line.
1430
- * And even to the third! */
1431
- CSS
1432
- /* This is a comment that
1433
- * continues to the second line.
1434
- * And even to the third!
1435
- SASS
1436
- end
1437
-
1438
- def test_loud_comments_with_no_space_after_starred_lines
1439
- assert_equal(<<CSS, render(<<SASS))
1440
- /*bip bop
1441
- *beep boop
1442
- *bap blimp */
1443
- CSS
1444
- /*bip bop
1445
- *beep boop
1446
- *bap blimp
1447
- SASS
1448
- end
1449
-
1450
- def test_comment_indentation_at_beginning_of_doc
1451
- assert_equal <<CSS, render(<<SASS)
1452
- /* foo
1453
- * bar
1454
- * baz */
1455
- foo {
1456
- a: b; }
1457
- CSS
1458
- /* foo
1459
- bar
1460
- baz
1461
- foo
1462
- a: b
1463
- SASS
1464
- end
1465
-
1466
- def test_unusual_comment_indentation
1467
- assert_equal <<CSS, render(<<SASS)
1468
- foo {
1469
- /* foo
1470
- * bar
1471
- * baz */ }
1472
- CSS
1473
- foo
1474
- /* foo
1475
- bar
1476
- baz
1477
- SASS
1478
- end
1479
-
1480
- def test_loud_comment_with_close
1481
- assert_equal <<CSS, render(<<SASS)
1482
- foo {
1483
- /* foo
1484
- * bar */ }
1485
- CSS
1486
- foo
1487
- /* foo
1488
- bar */
1489
- SASS
1490
- end
1491
-
1492
- def test_loud_comment_with_separate_line_close
1493
- assert_equal <<CSS, render(<<SASS)
1494
- foo {
1495
- /* foo
1496
- * bar
1497
- */ }
1498
- CSS
1499
- foo
1500
- /* foo
1501
- * bar
1502
- */
1503
- SASS
1504
- end
1505
-
1506
- def test_attribute_selector_with_spaces
1507
- assert_equal(<<CSS, render(<<SASS))
1508
- a b[foo=bar] {
1509
- c: d; }
1510
- CSS
1511
- a
1512
- b[foo = bar]
1513
- c: d
1514
- SASS
1515
- end
1516
-
1517
- def test_quoted_colon
1518
- assert_equal(<<CSS, render(<<SASS))
1519
- a b[foo="bar: baz"] {
1520
- c: d; }
1521
- CSS
1522
- a
1523
- b[foo="bar: baz"]
1524
- c: d
1525
- SASS
1526
- end
1527
-
1528
- def test_quoted_comma
1529
- assert_equal(<<CSS, render(<<SASS))
1530
- a b[foo="bar, baz"] {
1531
- c: d; }
1532
- CSS
1533
- a
1534
- b[foo="bar, baz"]
1535
- c: d
1536
- SASS
1537
- end
1538
-
1539
- def test_quoted_ampersand
1540
- assert_equal(<<CSS, render(<<SASS))
1541
- a b[foo="bar & baz"] {
1542
- c: d; }
1543
- CSS
1544
- a
1545
- b[foo="bar & baz"]
1546
- c: d
1547
- SASS
1548
- end
1549
-
1550
- def test_empty_selector_warning
1551
- assert_warning(<<END) {render("foo bar")}
1552
- WARNING on line 1 of test_empty_selector_warning_inline.sass:
1553
- This selector doesn't have any properties and will not be rendered.
1554
- END
1555
- end
1556
-
1557
- def test_root_level_pseudo_class_with_new_properties
1558
- assert_equal(<<CSS, render(<<SASS, :property_syntax => :new))
1559
- :focus {
1560
- outline: 0; }
1561
- CSS
1562
- :focus
1563
- outline: 0
1564
- SASS
1565
- end
1566
-
1567
- def test_pseudo_class_with_new_properties
1568
- assert_equal(<<CSS, render(<<SASS, :property_syntax => :new))
1569
- p :focus {
1570
- outline: 0; }
1571
- CSS
1572
- p
1573
- :focus
1574
- outline: 0
1575
- SASS
1576
- end
1577
-
1578
- def test_nil_option
1579
- assert_equal(<<CSS, render(<<SASS, :format => nil))
1580
- foo {
1581
- a: b; }
1582
- CSS
1583
- foo
1584
- a: b
1585
- SASS
1586
- end
1587
-
1588
- def test_interpolation_in_raw_functions
1589
- assert_equal(<<CSS, render(<<SASS))
1590
- foo {
1591
- filter: progid:Microsoft.foo.bar.Baz(flip=foobar, bang=#00ff00cc); }
1592
- CSS
1593
- foo
1594
- filter: progid:Microsoft.foo.bar.Baz(flip=\#{foo + bar}, bang=#00ff00cc)
1595
- SASS
1596
- end
1597
-
1598
- # SassScript string behavior
1599
-
1600
- def test_plus_preserves_quotedness
1601
- assert_equal(<<CSS, render(<<SASS))
1602
- foo {
1603
- a: "foo1";
1604
- b: "1foo";
1605
- c: foo1;
1606
- d: 1foo;
1607
- e: "foobar";
1608
- f: foobar; }
1609
- CSS
1610
- foo
1611
- a: "foo" + 1
1612
- b: 1 + "foo"
1613
- c: foo + 1
1614
- d: 1 + foo
1615
- e: "foo" + bar
1616
- f: foo + "bar"
1617
- SASS
1618
- end
1619
-
1620
- def test_colon_properties_preserve_quotedness
1621
- assert_equal(<<CSS, render(<<SASS))
1622
- foo {
1623
- a: "foo";
1624
- b: bar;
1625
- c: "foo" bar;
1626
- d: foo, "bar"; }
1627
- CSS
1628
- foo
1629
- a: "foo"
1630
- b: bar
1631
- c: "foo" bar
1632
- d: foo, "bar"
1633
- SASS
1634
- end
1635
-
1636
- def test_colon_variables_preserve_quotedness
1637
- assert_equal(<<CSS, render(<<SASS))
1638
- foo {
1639
- a: "foo";
1640
- b: bar; }
1641
- CSS
1642
- $a: "foo"
1643
- $b: bar
1644
-
1645
- foo
1646
- a: $a
1647
- b: $b
1648
- SASS
1649
- end
1650
-
1651
- def test_colon_args_preserve_quotedness
1652
- assert_equal(<<CSS, render(<<SASS))
1653
- foo {
1654
- a: "foo";
1655
- b: bar;
1656
- c: "foo" bar;
1657
- d: foo, "bar"; }
1658
- CSS
1659
- =foo($a: "foo", $b: bar, $c: "foo" bar, $d: (foo, "bar"))
1660
- foo
1661
- a: $a
1662
- b: $b
1663
- c: $c
1664
- d: $d
1665
-
1666
- +foo
1667
- SASS
1668
- end
1669
-
1670
- def test_interpolation_unquotes_strings
1671
- assert_equal(<<CSS, render(<<SASS))
1672
- .foo-bar {
1673
- a: b; }
1674
- CSS
1675
- .foo-\#{"bar"}
1676
- a: b
1677
- SASS
1678
-
1679
- assert_equal(<<CSS, render(<<SASS))
1680
- .foo {
1681
- a: b c; }
1682
- CSS
1683
- .foo
1684
- a: b \#{"c"}
1685
- SASS
1686
- end
1687
-
1688
- def test_interpolation_unquotes_strings_in_vars
1689
- assert_equal(<<CSS, render(<<SASS))
1690
- .foo-bar {
1691
- a: b; }
1692
- CSS
1693
- $var: "bar"
1694
-
1695
- .foo-\#{$var}
1696
- a: b
1697
- SASS
1698
- end
1699
-
1700
- def test_interpolation_doesnt_deep_unquote_strings
1701
- assert_equal(<<CSS, render(<<SASS))
1702
- .foo- "bar" "baz" {
1703
- a: b; }
1704
- CSS
1705
- .foo-\#{"bar" "baz"}
1706
- a: b
1707
- SASS
1708
- end
1709
-
1710
- # Deprecated equals behavior
1711
-
1712
- def test_equals_properties_unquote_strings
1713
- silence_warnings do
1714
- assert_equal(<<CSS, render(<<SASS))
1715
- foo {
1716
- a: foo;
1717
- b: bar;
1718
- c: foo bar;
1719
- d: foo, bar baz;
1720
- e: foo bar, bar; }
1721
- CSS
1722
- foo
1723
- a= "foo"
1724
- b= bar
1725
- c= "foo" bar
1726
- d= foo, "bar baz"
1727
- e= "foo bar", bar
1728
- SASS
1729
- end
1730
- end
1731
-
1732
- def test_equals_properties_unquote_value
1733
- silence_warnings do
1734
- assert_equal(<<CSS, render(<<SASS))
1735
- foo {
1736
- a: foo; }
1737
- CSS
1738
- $var: "foo"
1739
-
1740
- foo
1741
- a= $var
1742
- SASS
1743
- end
1744
- end
1745
-
1746
- def test_equals_properties_deep_unquote_vars
1747
- silence_warnings do
1748
- assert_equal(<<CSS, render(<<SASS))
1749
- foo {
1750
- a: foo bar;
1751
- b: bar foo; }
1752
- CSS
1753
- $var: "foo"
1754
-
1755
- foo
1756
- a= $var "bar"
1757
- b= "bar" $var
1758
- SASS
1759
- end
1760
- end
1761
-
1762
- def test_equals_vars_unquote_strings
1763
- silence_warnings do
1764
- assert_equal(<<CSS, render(<<SASS))
1765
- foo {
1766
- a: foo;
1767
- b: bar;
1768
- c: foo bar;
1769
- d: foo, bar; }
1770
- CSS
1771
- $a = "foo"
1772
- $b = bar
1773
- $c = "foo" bar
1774
- $d = foo, "bar"
1775
-
1776
- foo
1777
- a: $a
1778
- b: $b
1779
- c: $c
1780
- d: $d
1781
- SASS
1782
- end
1783
- end
1784
-
1785
- def test_equals_vars_unquote_value
1786
- silence_warnings do
1787
- assert_equal(<<CSS, render(<<SASS))
1788
- foo {
1789
- a: foo; }
1790
- CSS
1791
- $var1: "foo"
1792
- $var2 = $var1
1793
-
1794
- foo
1795
- a: $var2
1796
- SASS
1797
- end
1798
- end
1799
-
1800
- def test_equals_vars_deep_unquote_vars
1801
- silence_warnings do
1802
- assert_equal(<<CSS, render(<<SASS))
1803
- foo {
1804
- a: foo bar;
1805
- b: bar foo; }
1806
- CSS
1807
- $var: "foo"
1808
- $a = $var "bar"
1809
- $b = "bar" $var
1810
-
1811
- foo
1812
- a: $a
1813
- b: $b
1814
- SASS
1815
- end
1816
- end
1817
-
1818
- def test_equals_args_unquote_strings
1819
- silence_warnings do
1820
- assert_equal(<<CSS, render(<<SASS))
1821
- foo {
1822
- a: foo;
1823
- b: bar;
1824
- c: foo bar;
1825
- d: foo, bar; }
1826
- CSS
1827
- =foo($a = "foo", $b = bar, $c = "foo" bar, $d = (foo, "bar"))
1828
- foo
1829
- a: $a
1830
- b: $b
1831
- c: $c
1832
- d: $d
1833
-
1834
- +foo
1835
- SASS
1836
- end
1837
- end
1838
-
1839
- def test_equals_args_unquote_value
1840
- silence_warnings do
1841
- assert_equal(<<CSS, render(<<SASS))
1842
- foo {
1843
- a: foo; }
1844
- CSS
1845
- $var1: "foo"
1846
-
1847
- =foo($var2 = $var1)
1848
- foo
1849
- a: $var2
1850
-
1851
- +foo
1852
- SASS
1853
- end
1854
- end
1855
-
1856
- def test_equals_args_deep_unquote_vars
1857
- silence_warnings do
1858
- assert_equal(<<CSS, render(<<SASS))
1859
- foo {
1860
- a: foo bar;
1861
- b: bar foo; }
1862
- CSS
1863
- $var: "foo"
1864
- =foo($a = $var "bar", $b = "bar" $var)
1865
- foo
1866
- a: $a
1867
- b: $b
1868
-
1869
- +foo
1870
- SASS
1871
- end
1872
- end
1873
-
1874
- def test_equals_properties_force_division
1875
- silence_warnings do
1876
- assert_equal(<<CSS, render(<<SASS))
1877
- foo {
1878
- a: 0.5; }
1879
- CSS
1880
- foo
1881
- a = 1px/2px
1882
- SASS
1883
- end
1884
- end
1885
-
1886
- def test_warn_directive
1887
- expected_warning = <<EXPECTATION
1888
- WARNING: this is a warning
1889
- on line 4 of test_warn_directive_inline.sass
1890
-
1891
- WARNING: this is a mixin warning
1892
- on line 2 of test_warn_directive_inline.sass, in `foo'
1893
- from line 7 of test_warn_directive_inline.sass
1894
- EXPECTATION
1895
- assert_warning expected_warning do
1896
- assert_equal <<CSS, render(<<SASS)
1897
- bar {
1898
- c: d; }
1899
- CSS
1900
- =foo
1901
- @warn "this is a mixin warning"
1902
-
1903
- @warn "this is a warning"
1904
- bar
1905
- c: d
1906
- +foo
1907
- SASS
1908
- end
1909
- end
1910
-
1911
- def test_warn_directive_when_quiet
1912
- assert_warning "" do
1913
- assert_equal <<CSS, render(<<SASS, :quiet => true)
1914
- CSS
1915
- @warn "this is a warning"
1916
- SASS
1917
- end
1918
- end
1919
-
1920
- def test_warn_with_imports
1921
- expected_warning = <<WARN
1922
- WARNING: In the main file
1923
- on line 1 of #{File.dirname(__FILE__)}/templates/warn.sass
1924
-
1925
- WARNING: Imported
1926
- on line 1 of #{File.dirname(__FILE__)}/templates/warn_imported.sass
1927
- from line 2 of #{File.dirname(__FILE__)}/templates/warn.sass
1928
-
1929
- WARNING: In an imported mixin
1930
- on line 4 of #{File.dirname(__FILE__)}/templates/warn_imported.sass, in `emits-a-warning'
1931
- from line 3 of #{File.dirname(__FILE__)}/templates/warn.sass
1932
- WARN
1933
- assert_warning expected_warning do
1934
- renders_correctly "warn", :style => :compact, :load_paths => [File.dirname(__FILE__) + "/templates"]
1935
- end
1936
- end
1937
-
1938
- # Regression tests
1939
-
1940
- def test_parens_in_mixins
1941
- assert_equal(<<CSS, render(<<SASS))
1942
- .foo {
1943
- color: #01ff7f;
1944
- background-color: #000102; }
1945
- CSS
1946
- =foo($c1, $c2: rgb(0, 1, 2))
1947
- color: $c1
1948
- background-color: $c2
1949
-
1950
- .foo
1951
- +foo(rgb(1,255,127))
1952
- SASS
1953
- end
1954
-
1955
- def test_comment_beneath_prop
1956
- assert_equal(<<RESULT, render(<<SOURCE))
1957
- .box {
1958
- border-style: solid; }
1959
- RESULT
1960
- .box
1961
- :border
1962
- //:color black
1963
- :style solid
1964
- SOURCE
1965
-
1966
- assert_equal(<<RESULT, render(<<SOURCE))
1967
- .box {
1968
- /* :color black */
1969
- border-style: solid; }
1970
- RESULT
1971
- .box
1972
- :border
1973
- /* :color black
1974
- :style solid
1975
- SOURCE
1976
-
1977
- assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
1978
- .box{border-style:solid}
1979
- RESULT
1980
- .box
1981
- :border
1982
- /*:color black
1983
- :style solid
1984
- SOURCE
1985
- end
1986
-
1987
- def test_compressed_comment_beneath_directive
1988
- assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
1989
- @foo{a:b}
1990
- RESULT
1991
- @foo
1992
- a: b
1993
- /*b: c
1994
- SOURCE
1995
- end
1996
-
1997
- def test_comment_with_crazy_indentation
1998
- assert_equal(<<CSS, render(<<SASS))
1999
- /* This is a loud comment:
2000
- * Where the indentation is wonky. */
2001
- .comment {
2002
- width: 1px; }
2003
- CSS
2004
- /*
2005
- This is a loud comment:
2006
- Where the indentation is wonky.
2007
- //
2008
- This is a silent comment:
2009
- Where the indentation is wonky.
2010
- .comment
2011
- width: 1px
2012
- SASS
2013
- end
2014
-
2015
- def test_plus_with_space
2016
- assert_equal(<<CSS, render(<<SASS))
2017
- a + b {
2018
- color: green; }
2019
- CSS
2020
- a
2021
- + b
2022
- color: green
2023
- SASS
2024
- end
2025
-
2026
- def test_empty_line_comment
2027
- assert_equal(<<CSS, render(<<SASS))
2028
- /* Foo
2029
- *
2030
- * Bar */
2031
- CSS
2032
- /*
2033
- Foo
2034
-
2035
- Bar
2036
- SASS
2037
- end
2038
-
2039
- def test_empty_comment
2040
- assert_equal(<<CSS, render(<<SASS))
2041
- /* */
2042
- a {
2043
- /* */
2044
- b: c; }
2045
- CSS
2046
- /*
2047
- a
2048
- /*
2049
- b: c
2050
- SASS
2051
- end
2052
-
2053
- def test_options_available_in_environment
2054
- assert_equal(<<CSS, render(<<SASS))
2055
- a {
2056
- b: nested; }
2057
- CSS
2058
- a
2059
- b: option("style")
2060
- SASS
2061
- end
2062
-
2063
- def test_mixin_no_arg_error
2064
- assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "($bar,": expected variable (e.g. $foo), was ")"') do
2065
- render(<<SASS)
2066
- =foo($bar,)
2067
- bip: bap
2068
- SASS
2069
- end
2070
- end
2071
-
2072
- def test_import_with_commas_in_url
2073
- assert_equal <<CSS, render(<<SASS)
2074
- @import url(foo.css?bar,baz);
2075
- CSS
2076
- @import url(foo.css?bar,baz)
2077
- SASS
2078
- end
2079
-
2080
- def test_function_output_with_comma
2081
- assert_equal <<CSS, render(<<SASS)
2082
- foo {
2083
- a: b(c), d(e); }
2084
- CSS
2085
- foo
2086
- a: b(c), d(e)
2087
- SASS
2088
- end
2089
-
2090
- def test_interpolation_with_comma
2091
- assert_equal <<CSS, render(<<SASS)
2092
- foo {
2093
- a: foo, bar; }
2094
- CSS
2095
- $foo: foo
2096
- foo
2097
- a: \#{$foo}, bar
2098
- SASS
2099
- end
2100
-
2101
- def test_string_interpolation_with_comma
2102
- assert_equal <<CSS, render(<<SASS)
2103
- foo {
2104
- a: "bip foo bap", bar; }
2105
- CSS
2106
- $foo: foo
2107
- foo
2108
- a: "bip \#{$foo} bap", bar
2109
- SASS
2110
- end
2111
-
2112
- # Encodings
2113
-
2114
- unless Haml::Util.ruby1_8?
2115
- def test_encoding_error
2116
- render("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
2117
- assert(false, "Expected exception")
2118
- rescue Sass::SyntaxError => e
2119
- assert_equal(3, e.sass_line)
2120
- assert_equal('Invalid UTF-8 character "\xFE"', e.message)
2121
- end
2122
-
2123
- def test_ascii_incompatible_encoding_error
2124
- template = "foo\nbar\nb_z".encode("utf-16le")
2125
- template[9] = "\xFE".force_encoding("utf-16le")
2126
- render(template)
2127
- assert(false, "Expected exception")
2128
- rescue Sass::SyntaxError => e
2129
- assert_equal(3, e.sass_line)
2130
- assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
2131
- end
2132
-
2133
- def test_same_charset_as_encoding
2134
- assert_renders_encoded(<<CSS, <<SASS)
2135
- @charset "UTF-8";
2136
- fóó {
2137
- a: b; }
2138
- CSS
2139
- @charset "utf-8"
2140
- fóó
2141
- a: b
2142
- SASS
2143
- end
2144
-
2145
- def test_different_charset_than_encoding
2146
- assert_renders_encoded(<<CSS.force_encoding("IBM866"), <<SASS)
2147
- @charset "IBM866";
2148
- fóó {
2149
- a: b; }
2150
- CSS
2151
- @charset "ibm866"
2152
- fóó
2153
- a: b
2154
- SASS
2155
- end
2156
-
2157
- def test_different_encoding_than_system
2158
- assert_renders_encoded(<<CSS.encode("IBM866"), <<SASS.encode("IBM866"))
2159
- @charset "IBM866";
2160
- тАЬ {
2161
- a: b; }
2162
- CSS
2163
- тАЬ
2164
- a: b
2165
- SASS
2166
- end
2167
-
2168
- def test_multibyte_charset
2169
- assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("UTF-8"))
2170
- @charset "UTF-16LE";
2171
- fóó {
2172
- a: b; }
2173
- CSS
2174
- @charset "utf-16le"
2175
- fóó
2176
- a: b
2177
- SASS
2178
- end
2179
-
2180
- def test_multibyte_charset_without_endian_specifier
2181
- assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("UTF-8"))
2182
- @charset "UTF-32BE";
2183
- fóó {
2184
- a: b; }
2185
- CSS
2186
- @charset "utf-32"
2187
- fóó
2188
- a: b
2189
- SASS
2190
- end
2191
-
2192
- def test_utf8_bom
2193
- assert_renders_encoded(<<CSS, <<SASS.force_encoding("BINARY"))
2194
- @charset "UTF-8";
2195
- fóó {
2196
- a: b; }
2197
- CSS
2198
- \uFEFFfóó
2199
- a: b
2200
- SASS
2201
- end
2202
-
2203
- def test_utf16le_bom
2204
- assert_renders_encoded(<<CSS.encode("UTF-16LE"), <<SASS.encode("UTF-16LE").force_encoding("BINARY"))
2205
- @charset "UTF-16LE";
2206
- fóó {
2207
- a: b; }
2208
- CSS
2209
- \uFEFFfóó
2210
- a: b
2211
- SASS
2212
- end
2213
-
2214
- def test_utf32be_bom
2215
- assert_renders_encoded(<<CSS.encode("UTF-32BE"), <<SASS.encode("UTF-32BE").force_encoding("BINARY"))
2216
- @charset "UTF-32BE";
2217
- fóó {
2218
- a: b; }
2219
- CSS
2220
- \uFEFFfóó
2221
- a: b
2222
- SASS
2223
- end
2224
- end
2225
-
2226
- private
2227
-
2228
- def assert_hash_has(hash, expected)
2229
- expected.each {|k, v| assert_equal(v, hash[k])}
2230
- end
2231
-
2232
- def assert_renders_encoded(css, sass)
2233
- result = render(sass)
2234
- assert_equal css.encoding, result.encoding
2235
- assert_equal css, result
2236
- end
2237
-
2238
- def render(sass, options = {})
2239
- munge_filename options
2240
- Sass::Engine.new(sass, options).render
2241
- end
2242
-
2243
- def renders_correctly(name, options={})
2244
- sass_file = load_file(name, "sass")
2245
- css_file = load_file(name, "css")
2246
- options[:filename] ||= filename(name, "sass")
2247
- options[:css_filename] ||= filename(name, "css")
2248
- css_result = Sass::Engine.new(sass_file, options).render
2249
- assert_equal css_file, css_result
2250
- end
2251
-
2252
- def load_file(name, type = "sass")
2253
- @result = ''
2254
- File.new(filename(name, type)).each_line { |l| @result += l }
2255
- @result
2256
- end
2257
-
2258
- def filename(name, type)
2259
- File.dirname(__FILE__) + "/#{type == 'sass' ? 'templates' : 'results'}/#{name}.#{type}"
2260
- end
2261
-
2262
- def sassc_path(template)
2263
- sassc_path = File.join(File.dirname(__FILE__) + "/templates/#{template}.sass")
2264
- Sass::Files.send(:sassc_filename, sassc_path, Sass::Engine::DEFAULT_OPTIONS)
2265
- end
2266
- end
2267
-