sass-embedded 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,276 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- module Sass
6
- class EmbeddedTest < MiniTest::Test
7
- include TempFileTest
8
-
9
- def setup
10
- @embedded = Embedded.new
11
- end
12
-
13
- def teardown
14
- @embedded.close
15
- end
16
-
17
- def render(data)
18
- @embedded.render({ data: data })[:css]
19
- end
20
-
21
- def test_line_comments
22
- skip 'not supported'
23
-
24
- template = <<~SCSS
25
- .foo {
26
- baz: bang; }
27
- SCSS
28
- expected_output = <<~CSS
29
- /* line 1, stdin */
30
- .foo {
31
- baz: bang;
32
- }
33
- CSS
34
- output = @embedded.render({
35
- data: template,
36
- source_comments: true
37
- })
38
- assert_equal expected_output, output[:css]
39
- end
40
-
41
- def test_one_line_comments
42
- assert_equal <<~CSS.chomp, render(<<~SCSS)
43
- .foo {
44
- baz: bang;
45
- }
46
- CSS
47
- .foo {// bar: baz;}
48
- baz: bang; //}
49
- }
50
- SCSS
51
- assert_equal <<~CSS.chomp, render(<<~SCSS)
52
- .foo bar[val="//"] {
53
- baz: bang;
54
- }
55
- CSS
56
- .foo bar[val="//"] {
57
- baz: bang; //}
58
- }
59
- SCSS
60
- end
61
-
62
- def test_variables
63
- assert_equal <<~CSS.chomp, render(<<~SCSS)
64
- blat {
65
- a: foo;
66
- }
67
- CSS
68
- $var: foo;
69
- #{' '}
70
- blat {a: $var}
71
- SCSS
72
-
73
- assert_equal <<~CSS.chomp, render(<<~SCSS)
74
- foo {
75
- a: 2;
76
- b: 6;
77
- }
78
- CSS
79
- foo {
80
- $var: 2;
81
- $another-var: 4;
82
- a: $var;
83
- b: $var + $another-var;}
84
- SCSS
85
- end
86
-
87
- def test_precision
88
- skip 'not supported'
89
-
90
- template = <<~SCSS
91
- $var: 1;
92
- .foo {
93
- baz: $var / 3; }
94
- SCSS
95
- expected_output = <<~CSS.chomp
96
- .foo {
97
- baz: 0.33333333;
98
- }
99
- CSS
100
- output = @embedded.render({
101
- data: template,
102
- precision: 8
103
- })
104
- assert_equal expected_output, output
105
- end
106
-
107
- def test_precision_not_specified
108
- template = <<~SCSS
109
- $var: 1;
110
- .foo {
111
- baz: $var / 3; }
112
- SCSS
113
- expected_output = <<~CSS.chomp
114
- .foo {
115
- baz: 0.3333333333;
116
- }
117
- CSS
118
- output = render(template)
119
- assert_equal expected_output, output
120
- end
121
-
122
- def test_source_map
123
- temp_dir('admin')
124
-
125
- temp_file('admin/text-color.scss', <<~SCSS)
126
- p {
127
- color: red;
128
- }
129
- SCSS
130
- temp_file('style.scss', <<~SCSS)
131
- @use 'admin/text-color';
132
- #{' '}
133
- p {
134
- padding: 20px;
135
- }
136
- SCSS
137
- output = @embedded.render({
138
- data: File.read('style.scss'),
139
- source_map: 'style.scss.map'
140
- })
141
-
142
- assert output[:map].start_with? '{"version":3,'
143
- end
144
-
145
- def test_no_source_map
146
- output = @embedded.render({
147
- data: '$size: 30px;'
148
- })
149
- assert_equal '', output[:map]
150
- end
151
-
152
- def test_include_paths
153
- temp_dir('included_1')
154
- temp_dir('included_2')
155
-
156
- temp_file('included_1/import_parent.scss', '$s: 30px;')
157
- temp_file('included_2/import.scss', "@use 'import_parent' as *; $size: $s;")
158
- temp_file('styles.scss', "@use 'import.scss' as *; .hi { width: $size; }")
159
-
160
- assert_equal ".hi {\n width: 30px;\n}", @embedded.render({
161
- data: File.read('styles.scss'),
162
- include_paths: %w[
163
- included_1 included_2
164
- ]
165
- })[:css]
166
- end
167
-
168
- def test_global_include_paths
169
- temp_dir('included_1')
170
- temp_dir('included_2')
171
-
172
- temp_file('included_1/import_parent.scss', '$s: 30px;')
173
- temp_file('included_2/import.scss', "@use 'import_parent' as *; $size: $s;")
174
- temp_file('styles.scss', "@use 'import.scss' as *; .hi { width: $size; }")
175
-
176
- ::Sass.include_paths << 'included_1'
177
- ::Sass.include_paths << 'included_2'
178
-
179
- assert_equal ".hi {\n width: 30px;\n}", render(File.read('styles.scss'))
180
- end
181
-
182
- def test_env_include_paths
183
- expected_include_paths = %w[included_3 included_4]
184
-
185
- ::Sass.instance_eval { @include_paths = nil }
186
-
187
- ENV['SASS_PATH'] = expected_include_paths.join(File::PATH_SEPARATOR)
188
-
189
- assert_equal expected_include_paths, Sass.include_paths
190
-
191
- ::Sass.include_paths.clear
192
- end
193
-
194
- def test_include_paths_not_configured
195
- temp_dir('included_5')
196
- temp_dir('included_6')
197
- temp_file('included_5/import_parent.scss', '$s: 30px;')
198
- temp_file('included_6/import.scss', "@use 'import_parent' as *; $size: $s;")
199
- temp_file('styles.scss', "@use 'import.scss' as *; .hi { width: $size; }")
200
-
201
- assert_raises(CompilationError) do
202
- render(File.read('styles.scss'))
203
- end
204
- end
205
-
206
- def test_sass_variation
207
- sass = <<~SASS
208
- $size: 30px
209
- .foo
210
- width: $size
211
- SASS
212
-
213
- css = <<~CSS.chomp
214
- .foo {
215
- width: 30px;
216
- }
217
- CSS
218
-
219
- assert_equal css, @embedded.render({ data: sass, indented_syntax: true })[:css]
220
- assert_raises(CompilationError) do
221
- @embedded.render({ data: sass, indented_syntax: false })
222
- end
223
- end
224
-
225
- def test_inline_source_maps
226
- skip 'not supported'
227
-
228
- template = <<~SCSS
229
- .foo {
230
- baz: bang; }
231
- SCSS
232
-
233
- output = @embedded.render({
234
- data: template,
235
- source_map: '.',
236
- source_map_embed: true,
237
- source_map_contents: true
238
- })[:css]
239
-
240
- assert_match(/sourceMappingURL/, output)
241
- assert_match(/.foo/, output)
242
- end
243
-
244
- def test_empty_template
245
- output = render('')
246
- assert_equal '', output
247
- end
248
-
249
- def test_import_plain_css
250
- temp_file('test.css', '.something{color: red}')
251
- expected_output = <<~CSS.chomp
252
- .something {
253
- color: red;
254
- }
255
- CSS
256
-
257
- output = render("@use 'test';")
258
- assert_equal expected_output, output
259
- end
260
-
261
- def test_concurrency
262
- 10.times do
263
- threads = []
264
- 10.times do |i|
265
- threads << Thread.new(i) do |id|
266
- output = @embedded.render({
267
- data: "div { width: #{id} }"
268
- })[:css]
269
- assert_match(/#{id}/, output)
270
- end
271
- end
272
- threads.each(&:join)
273
- end
274
- end
275
- end
276
- end
data/test/error_test.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- module Sass
6
- class ErrorTest < MiniTest::Test
7
- def setup
8
- @embedded = Embedded.new
9
- end
10
-
11
- def teardown
12
- @embedded.close
13
- end
14
-
15
- def test_first_backtrace_is_sass
16
- template = <<~SCSS
17
- .foo {
18
- baz: bang;
19
- padding top: 10px;
20
- }
21
- SCSS
22
-
23
- @embedded.render({
24
- data: template
25
- })
26
- rescue Sass::CompilationError => e
27
- expected = 'stdin:3:20'
28
- assert_equal expected, e.backtrace.first
29
- end
30
- end
31
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- module Sass
6
- class OutputStyleTest < MiniTest::Test
7
- def setup
8
- @embedded = Embedded.new
9
- end
10
-
11
- def teardown
12
- @embedded.close
13
- end
14
-
15
- def input_scss
16
- <<~CSS
17
- $color: #fff;
18
-
19
- #main {
20
- color: $color;
21
- background-color: #000;
22
- p {
23
- width: 10em;
24
- }
25
- }
26
-
27
- .huge {
28
- font-size: 10em;
29
- font-weight: bold;
30
- text-decoration: underline;
31
- }
32
- CSS
33
- end
34
-
35
- def expected_expanded_output
36
- <<~CSS.chomp
37
- #main {
38
- color: #fff;
39
- background-color: #000;
40
- }
41
- #main p {
42
- width: 10em;
43
- }
44
-
45
- .huge {
46
- font-size: 10em;
47
- font-weight: bold;
48
- text-decoration: underline;
49
- }
50
- CSS
51
- end
52
-
53
- def test_expanded_output_is_default
54
- output = @embedded.render({ data: input_scss })[:css]
55
- assert_equal expected_expanded_output, output
56
- end
57
-
58
- def test_output_style_accepts_strings
59
- output = @embedded.render({ data: input_scss, output_style: :expanded })[:css]
60
- assert_equal expected_expanded_output, output
61
- end
62
-
63
- def test_invalid_output_style
64
- assert_raises(InvalidStyleError) do
65
- @embedded.render({ data: input_scss, output_style: :totally_wrong })[:css]
66
- end
67
- end
68
-
69
- def test_unsupported_output_style
70
- assert_raises(UnsupportedValue) do
71
- @embedded.render({ data: input_scss, output_style: :nested })[:css]
72
- end
73
-
74
- assert_raises(UnsupportedValue) do
75
- @embedded.render({ data: input_scss, output_style: :compact })[:css]
76
- end
77
- end
78
-
79
- def test_compressed_output
80
- output = @embedded.render({ data: input_scss, output_style: :compressed })[:css]
81
- assert_equal <<~CSS.chomp, output
82
- #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
83
- CSS
84
- end
85
-
86
- def test_string_output_style_names
87
- output = @embedded.render({ data: input_scss, output_style: 'compressed' })[:css]
88
- assert_equal <<~CSS.chomp, output
89
- #main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
90
- CSS
91
- end
92
- end
93
- end
data/test/sass_test.rb DELETED
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'test_helper'
4
-
5
- module Sass
6
- class SassTest < MiniTest::Test
7
- def test_sass_works
8
- assert_equal '', Sass.render({
9
- data: ''
10
- })[:css]
11
-
12
- css = <<~CSS.chomp
13
- h1 {
14
- font-size: 2rem;
15
- }
16
- CSS
17
- assert_equal css, Sass.render({
18
- data: 'h1 { font-size: 2rem; }'
19
- })[:css]
20
- end
21
- end
22
- end