File: script_test.rb

package info (click to toggle)
ruby-sass 3.7.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,396 kB
  • sloc: ruby: 32,443; sh: 26; makefile: 25
file content (1427 lines) | stat: -rwxr-xr-x 51,418 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/../test_helper'
require 'sass/engine'

module Sass::Script::Functions::UserFunctions
  def assert_options(val)
    val.options[:foo]
    Sass::Script::Value::String.new("Options defined!")
  end

  def arg_error
    assert_options
  end
end

module Sass::Script::Functions
  include Sass::Script::Functions::UserFunctions
end

class SassScriptTest < Minitest::Test
  include Sass::Script

  def test_color_clamps_input
    assert_equal 0, Sass::Script::Value::Color.new([1, 2, -1]).blue
    assert_equal 255, Sass::Script::Value::Color.new([256, 2, 3]).red
  end

  def test_color_clamps_rgba_input
    assert_equal 1, Sass::Script::Value::Color.new([1, 2, 3, 1.1]).alpha
    assert_equal 0, Sass::Script::Value::Color.new([1, 2, 3, -0.1]).alpha
  end

  def test_color_from_hex
    assert_equal Sass::Script::Value::Color.new([0,0,0]), Sass::Script::Value::Color.from_hex('000000')
    assert_equal Sass::Script::Value::Color.new([0,0,0]), Sass::Script::Value::Color.from_hex('#000000')
  end

  def test_string_escapes
    assert_equal "'", resolve("\"'\"")
    assert_equal '"', resolve("\"\\\"\"")
    assert_equal "\\", resolve("\"\\\\\"")
    assert_equal "☃", resolve("\"\\2603\"")
    assert_equal "☃f", resolve("\"\\2603 f\"")
    assert_equal "☃x", resolve("\"\\2603x\"")
    assert_equal "\\2603", resolve("\"\\\\2603\"")
    assert_equal "\#{foo}", resolve("\"\\\#{foo}\"")

    # U+FFFD is the replacement character, "�".
    assert_equal [0xFFFD].pack("U"), resolve("\"\\0\"")
    assert_equal [0xFFFD].pack("U"), resolve("\"\\FFFFFF\"")
    assert_equal [0xFFFD].pack("U"), resolve("\"\\D800\"")
    assert_equal [0xD7FF].pack("U"), resolve("\"\\D7FF\"")
    assert_equal [0xFFFD].pack("U"), resolve("\"\\DFFF\"")
    assert_equal [0xE000].pack("U"), resolve("\"\\E000\"")
  end

  def test_string_escapes_are_resolved_before_operators
    assert_equal "true", resolve('"abc" == "\61\62\63"')
  end

  def test_string_quote
    assert_equal '"foo"', resolve_quoted('"foo"')
    assert_equal "'f\"oo'", resolve_quoted('"f\"oo"')
    assert_equal "\"f'oo\"", resolve_quoted("'f\\'oo'")
    assert_equal "\"f'o\\\"o\"", resolve_quoted("'f\\'o\"o'")
    assert_equal '"foo bar"', resolve_quoted('"foo\20 bar"')
    assert_equal '"foo\a bar"', resolve_quoted('"foo\a bar"')
    assert_equal '"x\ay"', resolve_quoted('"x\a y"')
    assert_equal '"\a  "', resolve_quoted('"\a\20"')
    assert_equal '"\a abcdef"', resolve_quoted('"\a abcdef"')
    assert_equal '"☃abcdef"', resolve_quoted('"\2603 abcdef"')
    assert_equal '"\\\\"', resolve_quoted('"\\\\"')
    assert_equal '"foobar"', resolve_quoted("\"foo\\\nbar\"")
    assert_equal '"#{foo}"', resolve_quoted("\"\\\#{foo}\"")
  end

  def test_color_names
    assert_equal "white", resolve("white")
    assert_equal "#ffffff", resolve("#ffffff")
    silence_warnings {assert_equal "#fffffe", resolve("white - #000001")}
    assert_equal "transparent", resolve("transparent")
    assert_equal "rgba(0, 0, 0, 0)", resolve("rgba(0, 0, 0, 0)")
  end

  def test_rgba_color_literals
    assert_equal Sass::Script::Value::Color.new([1, 2, 3, 0.75]), eval("rgba(1, 2, 3, 0.75)")
    assert_equal "rgba(1, 2, 3, 0.75)", resolve("rgba(1, 2, 3, 0.75)")

    assert_equal Sass::Script::Value::Color.new([1, 2, 3, 0]), eval("rgba(1, 2, 3, 0)")
    assert_equal "rgba(1, 2, 3, 0)", resolve("rgba(1, 2, 3, 0)")

    assert_equal Sass::Script::Value::Color.new([1, 2, 3]), eval("rgba(1, 2, 3, 1)")
    assert_equal Sass::Script::Value::Color.new([1, 2, 3, 1]), eval("rgba(1, 2, 3, 1)")
    assert_equal "#010203", resolve("rgba(1, 2, 3, 1)")
    assert_equal "white", resolve("rgba(255, 255, 255, 1)")
  end

  def test_rgba_color_math
    silence_warnings {assert_equal "rgba(50, 50, 100, 0.35)", resolve("rgba(1, 1, 2, 0.35) * rgba(50, 50, 50, 0.35)")}
    silence_warnings {assert_equal "rgba(52, 52, 52, 0.25)", resolve("rgba(2, 2, 2, 0.25) + rgba(50, 50, 50, 0.25)")}

    assert_raise_message(Sass::SyntaxError, "Alpha channels must be equal: rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)") do
      silence_warnings {resolve("rgba(1, 2, 3, 0.15) + rgba(50, 50, 50, 0.75)")}
    end
    assert_raise_message(Sass::SyntaxError, "Alpha channels must be equal: #123456 * rgba(50, 50, 50, 0.75)") do
      silence_warnings {resolve("#123456 * rgba(50, 50, 50, 0.75)")}
    end
    assert_raise_message(Sass::SyntaxError, "Alpha channels must be equal: rgba(50, 50, 50, 0.75) / #123456") do
      silence_warnings {resolve("rgba(50, 50, 50, 0.75) / #123456")}
    end
  end

  def test_rgba_number_math
    silence_warnings {assert_equal "rgba(49, 49, 49, 0.75)", resolve("rgba(50, 50, 50, 0.75) - 1")}
    silence_warnings {assert_equal "rgba(100, 100, 100, 0.75)", resolve("rgba(50, 50, 50, 0.75) * 2")}
  end

  def test_rgba_rounding
    assert_equal "rgba(10, 1, 0, 0.1234567892)", resolve("rgba(10.0, 1.23456789, 0.0, 0.12345678919)")
  end

  def test_rgb_calc
    assert_equal "rgb(calc(255 - 5), 0, 0)", resolve("rgb(calc(255 - 5), 0, 0)")
  end

  def test_rgba_calc
    assert_equal "rgba(calc(255 - 5), 0, 0, 0.1)",
      resolve("rgba(calc(255 - 5), 0, 0, 0.1)")
    assert_equal "rgba(127, 0, 0, calc(0.1 + 0.5))",
      resolve("rgba(127, 0, 0, calc(0.1 + 0.5))")
  end

  def test_rgba_shorthand_calc
    assert_equal "rgba(255, 0, 0, calc(0.1 + 0.5))",
      resolve("rgba(red, calc(0.1 + 0.5))")
  end

  def test_hsl_calc
    assert_equal "hsl(calc(360 * 5 / 6), 50%, 50%)", resolve("hsl(calc(360 * 5 / 6), 50%, 50%)")
  end

  def test_hsla_calc
    assert_equal "hsla(calc(360 * 5 / 6), 50%, 50%, 0.1)",
      resolve("hsla(calc(360 * 5 / 6), 50%, 50%, 0.1)")
    assert_equal "hsla(270, 50%, 50%, calc(0.1 + 0.1))",
      resolve("hsla(270, 50%, 50%, calc(0.1 + 0.1))")
  end

  def test_compressed_colors
    assert_equal "#123456", resolve("#123456", :style => :compressed)
    assert_equal "rgba(1,2,3,0.5)", resolve("rgba(1, 2, 3, 0.5)", :style => :compressed)
    assert_equal "#123", resolve("#112233", :style => :compressed)
    assert_equal "#000", resolve("black", :style => :compressed)
    assert_equal "red", resolve("#f00", :style => :compressed)
    assert_equal "blue", resolve("blue", :style => :compressed)
    assert_equal "navy", resolve("#000080", :style => :compressed)
    assert_equal "navy #fff", resolve("#000080 white", :style => :compressed)
    assert_equal "This color is #fff", resolve('"This color is #{ white }"', :style => :compressed)
    assert_equal "transparent", resolve("rgba(0, 0, 0, 0)", :style => :compressed)
  end

  def test_compressed_comma
    # assert_equal "foo,bar,baz", resolve("foo, bar, baz", :style => :compressed)
    # assert_equal "foo,#baf,baz", resolve("foo, #baf, baz", :style => :compressed)
    assert_equal "foo,#baf,red", resolve("foo, #baf, #f00", :style => :compressed)
  end

  def test_implicit_strings
    assert_equal Sass::Script::Value::String.new("foo"), eval("foo")
    assert_equal Sass::Script::Value::String.new("foo/bar"), eval("foo/bar")
  end

  def test_basic_interpolation
    assert_equal "foo3bar", resolve("foo\#{1 + 2}bar")
    assert_equal "foo3 bar", resolve("foo\#{1 + 2} bar")
    assert_equal "foo 3bar", resolve("foo \#{1 + 2}bar")
    assert_equal "foo 3 bar", resolve("foo \#{1 + 2} bar")
    assert_equal "foo 35 bar", resolve("foo \#{1 + 2}\#{2 + 3} bar")
    assert_equal "foo 3 5 bar", resolve("foo \#{1 + 2} \#{2 + 3} bar")
    assert_equal "3bar", resolve("\#{1 + 2}bar")
    assert_equal "foo3", resolve("foo\#{1 + 2}")
    assert_equal "3", resolve("\#{1 + 2}")
  end

  def test_interpolation_in_function
    assert_equal 'flabnabbit(1foo)', resolve('flabnabbit(#{1 + "foo"})')
    assert_equal 'flabnabbit(foo 1foobaz)', resolve('flabnabbit(foo #{1 + "foo"}baz)')
    assert_equal('flabnabbit(foo 1foo2bar baz)',
      resolve('flabnabbit(foo #{1 + "foo"}#{2 + "bar"} baz)'))
  end

  def test_interpolation_near_operators
    silence_warnings do
      assert_equal '3 , 7', resolve('#{1 + 2} , #{3 + 4}')
      assert_equal '3, 7', resolve('#{1 + 2}, #{3 + 4}')
      assert_equal '3 ,7', resolve('#{1 + 2} ,#{3 + 4}')
      assert_equal '3,7', resolve('#{1 + 2},#{3 + 4}')
      assert_equal '3, 7, 11', resolve('#{1 + 2}, #{3 + 4}, #{5 + 6}')
      assert_equal '3, 7, 11', resolve('3, #{3 + 4}, 11')
      assert_equal '3, 7, 11', resolve('3, 7, #{5 + 6}')

      assert_equal '3 / 7', resolve('3 / #{3 + 4}')
      assert_equal '3 /7', resolve('3 /#{3 + 4}')
      assert_equal '3/ 7', resolve('3/ #{3 + 4}')
      assert_equal '3/7', resolve('3/#{3 + 4}')

      assert_equal '3 * 7', resolve('#{1 + 2} * 7')
      assert_equal '3* 7', resolve('#{1 + 2}* 7')
      assert_equal '3 *7', resolve('#{1 + 2} *7')
      assert_equal '3*7', resolve('#{1 + 2}*7')

      assert_equal '-3', resolve('-#{1 + 2}')
      assert_equal '- 3', resolve('- #{1 + 2}')

      assert_equal '5 + 3 * 7', resolve('5 + #{1 + 2} * #{3 + 4}')
      assert_equal '5 +3 * 7', resolve('5 +#{1 + 2} * #{3 + 4}')
      assert_equal '5+3 * 7', resolve('5+#{1 + 2} * #{3 + 4}')
      assert_equal '3 * 7 + 5', resolve('#{1 + 2} * #{3 + 4} + 5')
      assert_equal '3 * 7+ 5', resolve('#{1 + 2} * #{3 + 4}+ 5')
      assert_equal '3 * 7+5', resolve('#{1 + 2} * #{3 + 4}+5')

      assert_equal '5/3 + 7', resolve('5 / (#{1 + 2} + #{3 + 4})')
      assert_equal '5/3 + 7', resolve('5 /(#{1 + 2} + #{3 + 4})')
      assert_equal '5/3 + 7', resolve('5 /( #{1 + 2} + #{3 + 4} )')
      assert_equal '3 + 7/5', resolve('(#{1 + 2} + #{3 + 4}) / 5')
      assert_equal '3 + 7/5', resolve('(#{1 + 2} + #{3 + 4})/ 5')
      assert_equal '3 + 7/5', resolve('( #{1 + 2} + #{3 + 4} )/ 5')

      assert_equal '3 + 5', resolve('#{1 + 2} + 2 + 3')
      assert_equal '3 +5', resolve('#{1 + 2} +2 + 3')
    end
  end

  def test_string_interpolation
    assert_equal "foo bar, baz bang", resolve('"foo #{"bar"}, #{"baz"} bang"')
    assert_equal "foo bar baz bang", resolve('"foo #{"#{"ba" + "r"} baz"} bang"')
    assert_equal 'foo #{bar baz} bang', resolve('"foo \#{#{"ba" + "r"} baz} bang"')
    assert_equal 'foo #{baz bang', resolve('"foo #{"\#{" + "baz"} bang"')
    assert_equal "foo2bar", resolve('\'foo#{1 + 1}bar\'')
    assert_equal "foo2bar", resolve('"foo#{1 + 1}bar"')
    assert_equal "foo1bar5baz4bang", resolve('\'foo#{1 + "bar#{2 + 3}baz" + 4}bang\'')
  end

  def test_interpolation_in_interpolation
    assert_equal 'foo', resolve('#{#{foo}}')
    assert_equal 'foo', resolve('"#{#{foo}}"')
    assert_equal 'foo', resolve('#{"#{foo}"}')
    assert_equal 'foo', resolve('"#{"#{foo}"}"')
  end

  def test_interpolation_with_newline
    assert_equal "\nbang", resolve('"#{"\a "}bang"')
    assert_equal "\n\nbang", resolve('"#{"\a "}\a bang"')
  end

  def test_rule_interpolation
    assert_equal(<<CSS, render(<<SASS))
foo bar baz bang {
  a: b; }
CSS
foo \#{"\#{"ba" + "r"} baz"} bang
  a: b
SASS
    assert_equal(<<CSS, render(<<SASS))
foo [bar="\#{bar baz}"] bang {
  a: b; }
CSS
foo [bar="\\\#{\#{"ba" + "r"} baz}"] bang
  a: b
SASS
    assert_equal(<<CSS, render(<<SASS))
foo [bar="\#{baz"] bang {
  a: b; }
CSS
foo [bar="\#{"\\\#{" + "baz"}"] bang
  a: b
SASS
  end

  def test_inaccessible_functions
    assert_equal "send(to_s)", resolve("send(to_s)", :line => 2)
    assert_equal "public_instance_methods()", resolve("public_instance_methods()")
  end

  def test_adding_functions_directly_to_functions_module
    assert !Functions.callable?('nonexistent')
    Functions.class_eval { def nonexistent; end }
    assert Functions.callable?('nonexistent')
    Functions.send :remove_method, :nonexistent
  end

  def test_default_functions
    assert_equal "url(12)", resolve("url(12)")
    assert_equal 'blam("foo")', resolve('blam("foo")')
  end

  def test_function_results_have_options
    assert_equal "Options defined!", resolve("assert_options(abs(1))")
    assert_equal "Options defined!", resolve("assert_options(round(1.2))")
  end

  def test_funcall_requires_no_whitespace_before_lparen
    assert_equal "no-repeat 15px", resolve("no-repeat (7px + 8px)")
    assert_equal "no-repeat(15px)", resolve("no-repeat(7px + 8px)")
  end

  def test_dynamic_url
    assert_equal "url(foo-bar)", resolve("url($foo)", {}, env('foo' => Sass::Script::Value::String.new("foo-bar")))
    assert_equal "url(foo-bar baz)", resolve("url($foo $bar)", {}, env('foo' => Sass::Script::Value::String.new("foo-bar"), 'bar' => Sass::Script::Value::String.new("baz")))
    assert_equal "url(foo baz)", resolve("url(foo $bar)", {}, env('bar' => Sass::Script::Value::String.new("baz")))
    assert_equal "url(foo bar)", resolve("url(foo    bar)")
  end

  def test_url_with_interpolation
    assert_equal "url(https://sass-lang.com/images/foo-bar)", resolve("url(https://sass-lang.com/images/\#{foo-bar})")
    assert_equal 'url("https://sass-lang.com/images/foo-bar")', resolve("url('https://sass-lang.com/images/\#{foo-bar}')")
    assert_equal 'url("https://sass-lang.com/images/foo-bar")', resolve('url("https://sass-lang.com/images/#{foo-bar}")')
    assert_unquoted "url(https://sass-lang.com/images/\#{foo-bar})"
  end

  def test_hyphenated_variables
    assert_equal("a-b", resolve("$a-b", {}, env("a-b" => Sass::Script::Value::String.new("a-b"))))
  end

  def test_ruby_equality
    assert_equal eval('"foo"'), eval('"foo"')
    assert_equal eval('1'), eval('1.0')
    assert_equal eval('1 2 3.0'), eval('1 2 3')
    assert_equal eval('1, 2, 3.0'), eval('1, 2, 3')
    assert_equal eval('(1 2), (3, 4), (5 6)'), eval('(1 2), (3, 4), (5 6)')
    refute_equal eval('1, 2, 3'), eval('1 2 3')
    refute_equal eval('1'), eval('"1"')
  end

  def test_booleans
    assert_equal "true", resolve("true")
    assert_equal "false", resolve("false")
  end

  def test_null
    assert_equal "", resolve("null")
  end

  def test_boolean_ops
    assert_equal "true", resolve("true and true")
    assert_equal "true", resolve("false or true")
    assert_equal "true", resolve("true or false")
    assert_equal "true", resolve("true or true")
    assert_equal "false", resolve("false or false")
    assert_equal "false", resolve("false and true")
    assert_equal "false", resolve("true and false")
    assert_equal "false", resolve("false and false")

    assert_equal "true", resolve("not false")
    assert_equal "false", resolve("not true")
    assert_equal "true", resolve("not not true")

    assert_equal "1", resolve("false or 1")
    assert_equal "false", resolve("false and 1")
    assert_equal "2", resolve("2 or 3")
    assert_equal "3", resolve("2 and 3")

    assert_equal "true", resolve("null or true")
    assert_equal "true", resolve("true or null")
    assert_equal "", resolve("null or null")
    assert_equal "", resolve("null and true")
    assert_equal "", resolve("true and null")
    assert_equal "", resolve("null and null")

    assert_equal "true", resolve("not null")

    assert_equal "1", resolve("null or 1")
    assert_equal "", resolve("null and 1")
  end

  def test_arithmetic_ops
    assert_equal "2", resolve("1 + 1")
    assert_equal "0", resolve("1 - 1")
    assert_equal "8", resolve("2 * 4")
    assert_equal "0.5", resolve("(2 / 4)")
    assert_equal "2", resolve("(4 / 2)")

    assert_equal "-1", resolve("-1")
  end

  def test_subtraction_vs_minus_vs_identifier
    assert_equal "0.25em", resolve("1em-.75")
    assert_equal "0.25em", resolve("1em-0.75")
    assert_equal "1em -0.75", resolve("1em -.75")
    assert_equal "1em -0.75", resolve("1em -0.75")
    assert_equal "1em- 0.75", resolve("1em- .75")
    assert_equal "1em- 0.75", resolve("1em- 0.75")
    assert_equal "0.25em", resolve("1em - .75")
    assert_equal "0.25em", resolve("1em - 0.75")
  end

  def test_string_ops
    assert_equal '"foo" "bar"', resolve('"foo" "bar"')
    assert_equal "true 1", resolve('true 1')
    assert_equal '"foo", "bar"', resolve("'foo' , 'bar'")
    assert_equal "true, 1", resolve('true , 1')
    assert_equal "foobar", resolve('"foo" + "bar"')
    assert_equal "\nfoo\nxyz", resolve('"\a foo" + "\axyz"')
    assert_equal "true1", resolve('true + 1')
    assert_equal '"foo"-"bar"', resolve("'foo' - 'bar'")
    assert_equal "true-1", resolve('true - 1')
    assert_equal '"foo"/"bar"', resolve('"foo" / "bar"')
    assert_equal "true/1", resolve('true / 1')

    assert_equal '-"bar"', resolve("- 'bar'")
    assert_equal "-true", resolve('- true')
    assert_equal '/"bar"', resolve('/ "bar"')
    assert_equal "/true", resolve('/ true')
  end

  def test_relational_ops
    assert_equal "false", resolve("1 > 2")
    assert_equal "false", resolve("2 > 2")
    assert_equal "true", resolve("3 > 2")
    assert_equal "false", resolve("1 >= 2")
    assert_equal "true", resolve("2 >= 2")
    assert_equal "true", resolve("3 >= 2")
    assert_equal "true", resolve("1 < 2")
    assert_equal "false", resolve("2 < 2")
    assert_equal "false", resolve("3 < 2")
    assert_equal "true", resolve("1 <= 2")
    assert_equal "true", resolve("2 <= 2")
    assert_equal "false", resolve("3 <= 2")
  end

  def test_null_ops
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null plus 1".') {eval("null + 1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null minus 1".') {eval("null - 1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null times 1".') {eval("null * 1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null div 1".') {eval("null / 1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null mod 1".') {eval("null % 1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "1 plus null".') {eval("1 + null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "1 minus null".') {eval("1 - null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "1 times null".') {eval("1 * null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "1 div null".') {eval("1 / null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "1 mod null".') {eval("1 % null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "1 gt null".') {eval("1 > null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null lt 1".') {eval("null < 1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: "null plus null".') {eval("null + null")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid null operation: ""foo" plus null".') {eval("foo + null")}
  end

  def test_equals
    assert_equal("true", resolve('"foo" == $foo', {},
        env("foo" => Sass::Script::Value::String.new("foo"))))
    assert_equal "true", resolve("1 == 1.0")
    assert_equal "true", resolve("false != true")
    assert_equal "false", resolve("1em == 1px")
    assert_equal "false", resolve("12 != 12")
    assert_equal "true", resolve("(foo bar baz) == (foo bar baz)")
    assert_equal "true", resolve("(foo, bar, baz) == (foo, bar, baz)")
    assert_equal "true", resolve('((1 2), (3, 4), (5 6)) == ((1 2), (3, 4), (5 6))')
    assert_equal "true", resolve('((1 2), (3 4)) == (1 2, 3 4)')
    assert_equal "false", resolve('((1 2) 3) == (1 2 3)')
    assert_equal "false", resolve('(1 (2 3)) == (1 2 3)')
    assert_equal "false", resolve('((1, 2) (3, 4)) == (1, 2 3, 4)')
    assert_equal "false", resolve('(1 2 3) == (1, 2, 3)')

    assert_equal "true", resolve('null == null')
    assert_equal "false", resolve('"null" == null')
    assert_equal "false", resolve('0 == null')
    assert_equal "false", resolve('() == null')

    assert_equal "false", resolve('null != null')
    assert_equal "true", resolve('"null" != null')
    assert_equal "true", resolve('0 != null')
    assert_equal "true", resolve('() != null')
  end

  def test_mod
    assert_equal "5", resolve("29 % 12")
    assert_equal "5px", resolve("29px % 12")
    assert_equal "5px", resolve("29px % 12px")
  end

  def test_operation_precedence
    assert_equal "false true", resolve("true and false false or true")
    assert_equal "true", resolve("false and true or true and true")
    assert_equal "true", resolve("1 == 2 or 3 == 3")
    assert_equal "true", resolve("1 < 2 == 3 >= 3")
    assert_equal "true", resolve("1 + 3 > 4 - 2")
    assert_equal "11", resolve("1 + 2 * 3 + 4")
  end

  def test_functions
    assert_equal "#80ff80", resolve("hsl(120, 100%, 75%)")
    silence_warnings {assert_equal "#81ff81", resolve("hsl(120, 100%, 75%) + #010001")}
  end

  def test_operator_unit_conversion
    assert_equal "1.1cm", resolve("1cm + 1mm")
    assert_equal "8q", resolve("4q + 1mm")
    assert_equal "40.025cm", resolve("40cm + 1q")
    assert_equal "2in", resolve("1in + 96px")
    assert_equal "true", resolve("2mm < 1cm")
    assert_equal "true", resolve("10mm == 1cm")
    assert_equal "true", resolve("1.1cm == 11mm")
    assert_equal "true", resolve("2mm == 8q")
    assert_equal "false", resolve("2px > 3q")

    Sass::Deprecation.allow_double_warnings do
      assert_warning(<<WARNING) {assert_equal "true", resolve("1 == 1cm")}
DEPRECATION WARNING on line 1 of test_operator_unit_conversion_inline.sass:
The result of `1 == 1cm` will be `false` in future releases of Sass.
Unitless numbers will no longer be equal to the same numbers with units.
WARNING

      assert_warning(<<WARNING) {assert_equal "false", resolve("1 != 1cm")}
DEPRECATION WARNING on line 1 of test_operator_unit_conversion_inline.sass:
The result of `1 != 1cm` will be `true` in future releases of Sass.
Unitless numbers will no longer be equal to the same numbers with units.
WARNING
    end
  end

  def test_length_units
    assert_equal "2.54", resolve("(1in/1cm)")
    assert_equal "2.3622047244", resolve("(1cm/1pc)")
    assert_equal "4.2333333333", resolve("(1pc/1mm)")
    assert_equal "2.8346456693", resolve("(1mm/1pt)")
    assert_equal "1.3333333333", resolve("(1pt/1px)")
    assert_equal "0.0104166667", resolve("(1px/1in)")
    assert_equal "1.0583333333", resolve("(1px/1q)")
    assert_equal "0.0590551181", resolve("(1q/1pc)")
  end

  def test_angle_units
    assert_equal "1.1111111111", resolve("(1deg/1grad)")
    assert_equal "0.0157079633", resolve("(1grad/1rad)")
    assert_equal "0.1591549431", resolve("(1rad/1turn)")
    assert_equal "360", resolve("(1turn/1deg)")
  end

  def test_time_units
    assert_equal "1000", resolve("(1s/1ms)")
  end

  def test_frequency_units
    assert_equal "0.001", resolve("(1Hz/1kHz)")
  end

  def test_resolution_units
    assert_equal "0.3937007874", resolve("(1dpi/1dpcm)")
    assert_equal "0.0264583333", resolve("(1dpcm/1dppx)")
    assert_equal "96", resolve("(1dppx/1dpi)")
  end

  def test_operations_have_options
    assert_equal "Options defined!", resolve("assert_options(1 + 1)")
    assert_equal "Options defined!", resolve("assert_options('bar' + 'baz')")
  end

  def test_slash_compiles_literally_when_left_alone
    assert_equal "1px/2px", resolve("1px/2px")
    assert_equal "1px/2px/3px/4px", resolve("1px/2px/3px/4px")

    assert_equal "1px/2px redpx bluepx", resolve("1px/2px redpx bluepx")
    assert_equal "foo 1px/2px/3px bar", resolve("foo 1px/2px/3px bar")
  end

  def test_slash_divides_with_parens
    assert_equal "0.5", resolve("(1px/2px)")
    assert_equal "0.5", resolve("(1px)/2px")
    assert_equal "0.5", resolve("1px/(2px)")
  end

  def test_slash_divides_with_other_arithmetic
    assert_equal "0.5px", resolve("1px*1px/2px")
    assert_equal "0.5px", resolve("1px/2px*1px")
    assert_equal "0.5", resolve("0+1px/2px")
    assert_equal "0.5", resolve("1px/2px+0")
  end

  def test_slash_divides_with_variable
    assert_equal "0.5", resolve("$var/2px", {}, env("var" => eval("1px")))
    assert_equal "0.5", resolve("1px/$var", {}, env("var" => eval("2px")))
    assert_equal "0.5", resolve("$var", {}, env("var" => eval("1px/2px")))
  end

  # Regression test for issue 1786.
  def test_slash_division_within_list
    assert_equal "1 1/2 1/2", resolve("(1 1/2 1/2)")
    assert_equal "1/2 1/2", resolve("(1/2 1/2)")
    assert_equal "1/2", resolve("(1/2,)")
  end

  def test_non_ident_colors_with_wrong_number_of_digits
    assert_raise_message(Sass::SyntaxError,
      'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#1"') {eval("#1")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#12"') {eval("#12")}
    assert_raise_message(Sass::SyntaxError,
      'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#12345"') {eval("#12345")}
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "": expected expression (e.g. ' \
      '1px, bold), was "#1234567"') {eval("#1234567")}
  end

  def test_case_insensitive_color_names
    assert_equal "BLUE", resolve("BLUE")
    assert_equal "rEd", resolve("rEd")
    assert_equal "#804000", resolve("mix(GrEeN, ReD)")
  end

  def test_empty_list
    assert_equal "1 2 3", resolve("1 2 () 3")
    assert_equal "1 2 3", resolve("1 2 3 ()")
    assert_equal "1 2 3", resolve("() 1 2 3")
    assert_raise_message(Sass::SyntaxError, "() isn't a valid CSS value.") {resolve("()")}
    assert_raise_message(Sass::SyntaxError, "() isn't a valid CSS value.") {resolve("nth(append((), ()), 1)")}
  end

  def test_list_with_nulls
    assert_equal "1, 2, 3", resolve("1, 2, null, 3")
    assert_equal "1 2 3", resolve("1 2 null 3")
    assert_equal "1, 2, 3", resolve("1, 2, 3, null")
    assert_equal "1 2 3", resolve("1 2 3 null")
    assert_equal "1, 2, 3", resolve("null, 1, 2, 3")
    assert_equal "1 2 3", resolve("null 1 2 3")
  end

  def test_map_can_have_trailing_comma
    assert_equal("(foo: 1, bar: 2)", eval("(foo: 1, bar: 2,)").to_sass)
  end

  def test_list_can_have_trailing_comma
    assert_equal("1, 2, 3", resolve("1, 2, 3,"))
  end

  def test_trailing_comma_defines_singleton_list
    assert_equal("1 2 3", resolve("nth((1 2 3,), 1)"))
  end

  def test_map_cannot_have_duplicate_keys
    assert_raise_message(Sass::SyntaxError, 'Duplicate key "foo" in map (foo: bar, foo: baz).') do
      eval("(foo: bar, foo: baz)")
    end
    assert_raise_message(Sass::SyntaxError, 'Duplicate key "foo" in map (foo: bar, fo + o: baz).') do
      eval("(foo: bar, fo + o: baz)")
    end
    assert_raise_message(Sass::SyntaxError, 'Duplicate key "foo" in map (foo: bar, "foo": baz).') do
      eval("(foo: bar, 'foo': baz)")
    end
    assert_raise_message(Sass::SyntaxError, 'Duplicate key 2px in map (2px: bar, 1px + 1px: baz).') do
      eval("(2px: bar, 1px + 1px: baz)")
    end
    assert_raise_message(Sass::SyntaxError, 'Duplicate key #0000ff in map (blue: bar, #00f: baz).') do
      eval("(blue: bar, #00f: baz)")
    end
  end

  def test_non_duplicate_map_keys
    # These shouldn't throw errors
    eval("(foo: foo, bar: bar)")
    eval("(2px: foo, 2: bar)")
    eval("(2px: foo, 2em: bar)")
    eval("('2px': foo, 2px: bar)")
  end

  def test_map_syntax_errors
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "(foo:": expected expression (e.g. 1px, bold), was ")"') do
      eval("(foo:)")
    end
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "(": expected ")", was ":bar)"') do
      eval("(:bar)")
    end
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "(foo, bar": expected ")", was ": baz)"') do
      eval("(foo, bar: baz)")
    end
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "(foo: bar, baz": expected ":", was ")"') do
      eval("(foo: bar, baz)")
    end
  end

  def test_deep_argument_error_not_unwrapped
    # JRuby (as of 1.6.7.2) offers no way of distinguishing between
    # argument errors caused by programming errors in a function and
    # argument errors explicitly thrown within that function.
    return if RUBY_PLATFORM =~ /java/

    # Don't validate the message; it's different on Rubinius.
    assert_raises(ArgumentError) {resolve("arg-error()")}
  end

  def test_shallow_argument_error_unwrapped
    assert_raise_message(Sass::SyntaxError, "wrong number of arguments (1 for 0) for `arg-error'") {resolve("arg-error(1)")}
  end

  def test_boolean_ops_short_circuit
    assert_equal "false", resolve("$ie and $ie <= 7", {}, env('ie' => Sass::Script::Value::Bool.new(false)))
    assert_equal "true", resolve("$ie or $undef", {}, env('ie' => Sass::Script::Value::Bool.new(true)))
  end

  def test_selector
    env = Sass::Environment.new
    assert_equal "true", resolve("& == null", {}, env)

    env.selector = selector('.foo.bar .baz.bang, .bip.bop')
    assert_equal ".foo.bar .baz.bang, .bip.bop", resolve("&", {}, env)
    assert_equal ".foo.bar .baz.bang", resolve("nth(&, 1)", {}, env)
    assert_equal ".bip.bop", resolve("nth(&, 2)", {}, env)
    assert_equal ".foo.bar", resolve("nth(nth(&, 1), 1)", {}, env)
    assert_equal ".baz.bang", resolve("nth(nth(&, 1), 2)", {}, env)
    assert_equal ".bip.bop", resolve("nth(nth(&, 2), 1)", {}, env)
    assert_equal "string", resolve("type-of(nth(nth(&, 1), 1))", {}, env)

    env.selector = selector('.foo > .bar')
    assert_equal ".foo > .bar", resolve("&", {}, env)
    assert_equal ".foo > .bar", resolve("nth(&, 1)", {}, env)
    assert_equal ".foo", resolve("nth(nth(&, 1), 1)", {}, env)
    assert_equal ">", resolve("nth(nth(&, 1), 2)", {}, env)
    assert_equal ".bar", resolve("nth(nth(&, 1), 3)", {}, env)
  end

  def test_selector_with_newlines
    env = Sass::Environment.new
    env.selector = selector(".foo.bar\n.baz.bang,\n\n.bip.bop")
    assert_equal ".foo.bar .baz.bang, .bip.bop", resolve("&", {}, env)
    assert_equal ".foo.bar .baz.bang", resolve("nth(&, 1)", {}, env)
    assert_equal ".bip.bop", resolve("nth(&, 2)", {}, env)
    assert_equal ".foo.bar", resolve("nth(nth(&, 1), 1)", {}, env)
    assert_equal ".baz.bang", resolve("nth(nth(&, 1), 2)", {}, env)
    assert_equal ".bip.bop", resolve("nth(nth(&, 2), 1)", {}, env)
    assert_equal "string", resolve("type-of(nth(nth(&, 1), 1))", {}, env)
  end

  def test_setting_global_variable_globally
    assert_no_warning {assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))}
.foo {
  a: 1; }

.bar {
  b: 2; }
CSS
$var: 1;

.foo {
  a: $var;
}

$var: 2;

.bar {
  b: $var;
}
SCSS
  end

  def test_setting_global_variable_locally
    assert_no_warning {assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))}
.bar {
  a: x;
  b: y;
  c: z; }
CSS
$var1: 1;
$var3: 3;

.foo {
  $var1: x !global;
  $var2: y !global;
  @each $var3 in _ {
    $var3: z !global;
  }
}

.bar {
  a: $var1;
  b: $var2;
  c: $var3;
}
SCSS
  end

  def test_setting_global_variable_locally_with_default
    assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))
.bar {
  a: 1;
  b: y;
  c: z; }
CSS
$var1: 1;

.foo {
  $var1: x !global !default;
  $var2: y !global !default;
  @each $var3 in _ {
    $var3: z !global !default;
  }
}

.bar {
  a: $var1;
  b: $var2;
  c: $var3;
}
SCSS
  end

  def test_setting_local_variable
    assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))
.a {
  value: inside; }

.b {
  value: outside; }
CSS
$var: outside;

.a {
  $var: inside;
  value: $var;
}

.b {
  value: $var;
}
SCSS
  end

  def test_setting_local_variable_from_inner_scope
    assert_equal(<<CSS, render(<<SCSS, :syntax => :scss))
.a .b {
  value: inside; }
.a .c {
  value: inside; }
CSS
.a {
  $var: outside;

  .b {
    $var: inside;
    value: $var;
  }

  .c {
    value: $var;
  }
}
SCSS
  end

  def test_if_can_assign_to_global_variables
    assert_equal <<CSS, render(<<SCSS, :syntax => :scss)
.a {
  b: 2; }
CSS
$var: 1;
@if true {$var: 2}
.a {b: $var}
SCSS
  end

  def test_else_can_assign_to_global_variables
    assert_equal <<CSS, render(<<SCSS, :syntax => :scss)
.a {
  b: 2; }
CSS
$var: 1;
@if false {}
@else {$var: 2}
.a {b: $var}
SCSS
  end

  def test_for_can_assign_to_global_variables
    assert_equal <<CSS, render(<<SCSS, :syntax => :scss)
.a {
  b: 2; }
CSS
$var: 1;
@for $i from 1 to 2 {$var: 2}
.a {b: $var}
SCSS
  end

  def test_each_can_assign_to_global_variables
    assert_equal <<CSS, render(<<SCSS, :syntax => :scss)
.a {
  b: 2; }
CSS
$var: 1;
@each $a in 1 {$var: 2}
.a {b: $var}
SCSS
  end

  def test_while_can_assign_to_global_variables
    assert_equal <<CSS, render(<<SCSS, :syntax => :scss)
.a {
  b: 2; }
CSS
$var: 1;
@while $var != 2 {$var: 2}
.a {b: $var}
SCSS
  end

  def test_if_doesnt_leak_local_variables
    assert_raise_message(Sass::SyntaxError, 'Undefined variable: "$var".') do
      render(<<SCSS, :syntax => :scss)
@if true {$var: 1}
.a {b: $var}
SCSS
    end
  end

  def test_else_doesnt_leak_local_variables
    assert_raise_message(Sass::SyntaxError, 'Undefined variable: "$var".') do
      render(<<SCSS, :syntax => :scss)
@if false {}
@else {$var: 1}
.a {b: $var}
SCSS
    end
  end

  def test_for_doesnt_leak_local_variables
    assert_raise_message(Sass::SyntaxError, 'Undefined variable: "$var".') do
      render(<<SCSS, :syntax => :scss)
@for $i from 1 to 2 {$var: 1}
.a {b: $var}
SCSS
    end
  end

  def test_each_doesnt_leak_local_variables
    assert_raise_message(Sass::SyntaxError, 'Undefined variable: "$var".') do
      render(<<SCSS, :syntax => :scss)
@each $a in 1 {$var: 1}
.a {b: $var}
SCSS
    end
  end

  def test_while_doesnt_leak_local_variables
    assert_raise_message(Sass::SyntaxError, 'Undefined variable: "$var".') do
      render(<<SCSS, :syntax => :scss)
$iter: true;
@while $iter {
  $var: 1;
  $iter: false;
}
.a {b: $var}
SCSS
    end
  end

  def test_color_format_is_preserved_by_default
    assert_equal "blue", resolve("blue")
    assert_equal "bLuE", resolve("bLuE")
    assert_equal "#00f", resolve("#00f")
    assert_equal "blue #00F", resolve("blue #00F")
    assert_equal "blue", resolve("nth(blue #00F, 1)")
    assert_equal "#00F", resolve("nth(blue #00F, 2)")
  end

  def test_color_format_isnt_always_preserved_in_compressed_style
    assert_equal "red", resolve("red", :style => :compressed)
    assert_equal "red", resolve("#f00", :style => :compressed)
    assert_equal "red red", resolve("red #f00", :style => :compressed)
    assert_equal "red", resolve("nth(red #f00, 2)", :style => :compressed)
  end

  def test_color_format_is_sometimes_preserved_in_compressed_style
    assert_equal "ReD", resolve("ReD", :style => :compressed)
    assert_equal "blue", resolve("blue", :style => :compressed)
    assert_equal "#00f", resolve("#00f", :style => :compressed)
  end

  def test_color_format_isnt_preserved_when_modified
    assert_equal "magenta", resolve("change-color(#f00, $blue: 255)")
  end

  def test_ids
    assert_equal "#foo", resolve("#foo")
    silence_warnings {assert_equal "#abcd", resolve("#abcd")}
    assert_equal "#abc-def", resolve("#abc-def")
    assert_equal "#abc_def", resolve("#abc_def")
    assert_equal "#uvw-xyz", resolve("#uvw-xyz")
    assert_equal "#uvw_xyz", resolve("#uvw_xyz")
    assert_equal "#uvwxyz", resolve("#uvw + xyz")
  end

  def test_scientific_notation
    assert_equal "2000", resolve("2e3")
    assert_equal "2000", resolve("2E3")
    assert_equal "2000", resolve("2e+3")
    assert_equal "2000em", resolve("2e3em")
    assert_equal "25000000000", resolve("2.5e10")
    assert_equal "0.1234", resolve("1234e-4")
    assert_equal "12.34", resolve("1.234e1")
  end

  def test_identifier_units
    assert_equal "5-foo", resolve("2-foo + 3-foo")
    assert_equal "5-foo-", resolve("2-foo- + 3-foo-")
    assert_equal "5-u2603", resolve("2-\\u2603 + 3-\\u2603")
  end

  def test_backslash_newline_in_string
    assert_equal 'foobar', resolve("\"foo\\\nbar\"")
    assert_equal 'foobar', resolve("'foo\\\nbar'")
  end

  def test_unclosed_special_fun
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "calc(foo()": expected ")", was ""') do
      resolve("calc(foo()")
    end
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "calc(#{\')\'}": expected ")", was ""') do
      resolve("calc(\#{')'}")
    end
    assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "calc(#{foo": expected "}", was ""') do
      resolve("calc(\#{foo")
    end
  end

  def test_special_fun_with_interpolation
    assert_equal "calc())", resolve("calc(\#{')'})")
    assert_equal "calc(# {foo})", resolve("calc(# {foo})")
  end

  # Regression Tests

  def test_interpolation_after_string
    assert_equal '"foobar" 2', resolve('"foobar" #{2}')
    assert_equal "calc(1 + 2) 3", resolve('calc(1 + 2) #{3}')
  end

  def test_repeatedly_modified_color
    assert_equal(<<CSS, render(<<SASS))
a {
  link-color: #161C14;
  link-color-hover: black;
  link-color-tap: rgba(22, 28, 20, 0.3); }
CSS
$green: #161C14
$link-color: $green
$link-color-hover: darken($link-color, 10%)
$link-color-tap: rgba($green, 0.3)

a
  link-color: $link-color
  link-color-hover: $link-color-hover
  link-color-tap: $link-color-tap
SASS
  end

  def test_inspect_divided_numbers
    assert_equal "1px/2px", resolve("inspect(1px/2px)")
    assert_equal "0.5", resolve("inspect((1px/2px))")
  end

  def test_minus_without_whitespace
    assert_equal "5px", resolve("15px-10px")
    assert_equal "5px-", resolve("15px--10px-")
  end

  def test_minus_preceded_by_comment
    assert_equal "15px -10px", resolve("15px/**/-10px")
  end

  def test_user_defined_function_forces_division
    assert_equal(<<CSS, render(<<SASS))
a {
  b: 10px; }
CSS
@function foo()
  @return 20px

a
  b: (foo() / 2)
SASS

    assert_equal(<<CSS, render(<<SASS))
a {
  b: 10px; }
CSS
@function foo()
  @return 20px

a
  b: foo() / 2
SASS
  end

  def test_funcall_has_higher_precedence_than_color_name
    assert_equal "teal(12)", resolve("teal(12)")
    assert_equal "tealbang(12)", resolve("tealbang(12)")
    assert_equal "teal-bang(12)", resolve("teal-bang(12)")
    assert_equal "teal\\+bang(12)", resolve("teal\\+bang(12)")
  end

  def test_funcall_has_higher_precedence_than_true_false_null
    assert_equal "teal(12)", resolve("teal(12)")
    assert_equal "tealbang(12)", resolve("tealbang(12)")
    assert_equal "teal-bang(12)", resolve("teal-bang(12)")
    assert_equal "teal\\+bang(12)", resolve("teal\\+bang(12)")
  end

  def test_and_or_not_disallowed_as_function_names
    %w[and or not].each do |name|
      assert_raise_message(Sass::SyntaxError, "Invalid function name \"#{name}\".") do
        render(<<SASS)
@function #{name}()
  @return null
SASS
      end
    end
  end

  def test_interpolation_after_hash
    assert_equal "#2", resolve('"##{1 + 1}"')
  end

  def test_func_call_arglist_trailing_comma
    assert_equal eval('foo(bar)'), eval('foo(bar, )')
  end

  def test_color_prefixed_identifier
    assert_equal "tealbang", resolve("tealbang")
    assert_equal "teal-bang", resolve("teal-bang")
  end

  def test_op_prefixed_identifier
    assert_equal "notbang", resolve("notbang")
    assert_equal "not-bang", resolve("not-bang")
    assert_equal "or-bang", resolve("or-bang")
    assert_equal "and-bang", resolve("and-bang")
  end

  def test_number_initialization
    assert_equal Sass::Script::Value::Number.new(10, ["px"]), Sass::Script::Value::Number.new(10, "px")
    assert_equal Sass::Script::Value::Number.new(10, ["px"], ["em"]), Sass::Script::Value::Number.new(10, "px", "em")
  end

  def test_is_unit
    assert Sass::Script::Value::Number.new(10, "px").is_unit?("px")
    assert Sass::Script::Value::Number.new(10).is_unit?(nil)
    assert !Sass::Script::Value::Number.new(10, "px", "em").is_unit?("px")
    assert !Sass::Script::Value::Number.new(10, [], "em").is_unit?("em")
    assert !Sass::Script::Value::Number.new(10, ["px", "em"]).is_unit?("px")
  end

  def test_rename_redirect
    assert_no_warning do
      assert_equal Sass::Script::Value::Base, Sass::Script::Literal
      assert_equal Sass::Script::Tree::Node, Sass::Script::Node
      assert_equal Sass::Script::Tree::Operation, Sass::Script::Operation
      assert_equal Sass::Script::Value::String, Sass::Script::String
    end
  end

  def test_number_printing
    assert_equal "1", resolve("1")
    assert_equal "1", resolve("1.0")
    assert_equal "1000000000", resolve("1000000000")
    assert_equal "0.00001", resolve("0.00001")
    assert_equal "1.1212121212", resolve("1.12121212124")
    assert_equal "1.1212121213", resolve("1.12121212125")
    assert_equal "Infinity", resolve("(1.0/0.0)")
    assert_equal "-Infinity", resolve("(-1.0/0.0)")
    assert_equal "NaN", resolve("(0.0/0.0)")
  end

  def test_equality_uses_an_epsilon
    # At least on my machine, this calculation introduces a floating point error:
    # 29.0 / 7 * 7
    # => 29.000000000000004
    assert_equal "true", resolve("29 == (29 / 7 * 7)")
  end

  def test_compressed_output_of_numbers_with_leading_zeros
    assert_equal "1.5", resolve("1.5", :style => :compressed)
    assert_equal ".5", resolve("0.5", :style => :compressed)
    assert_equal "-.5", resolve("-0.5", :style => :compressed)
    assert_equal "0.5", resolve("0.5", :style => :compact)
  end

  def test_interpolation_without_deprecation_warning
    assert_no_warning {assert_equal "a", resolve('#{a}')}
    assert_no_warning {assert_equal "abc", resolve('a#{b}c')}
    assert_no_warning {assert_equal "+ a", resolve('+ #{a}')}
    assert_no_warning {assert_equal "/ a", resolve('/ #{a}')}
    assert_no_warning {assert_equal "1 / a", resolve('1 / #{a}')}
    assert_no_warning {assert_equal "a / b", resolve('#{a} / #{b}')}
    assert_no_warning {assert_equal "foo(1 = a)", resolve('foo(1 = #{a})')}
    assert_no_warning {assert_equal "foo(a = b)", resolve('foo(#{a} = #{b})')}
    assert_no_warning {assert_equal "-a", resolve('-#{a}')}
    assert_no_warning {assert_equal "1-a", resolve('1-#{a}')}
    assert_no_warning {assert_equal "a- 1", resolve('#{a}- 1')}
    assert_no_warning {assert_equal "a-1", resolve('#{a}-1')}
    assert_no_warning {assert_equal "a-b", resolve('#{a}-#{b}')}
    assert_no_warning {assert_equal "a1", resolve('#{a}1')}
    assert_no_warning {assert_equal "ab", resolve('#{a}b')}
    assert_no_warning {assert_equal "1a", resolve('1#{a}')}
    assert_no_warning {assert_equal "ba", resolve('b#{a}')}
  end

  def test_leading_interpolation_with_deprecation_warning
    assert_equal "ab == 1", resolve_with_interp_warning('#{a + b} == 1')
    assert_equal "ab != 1", resolve_with_interp_warning('#{a + b} != 1')
    assert_equal "ab > 1", resolve_with_interp_warning('#{a + b} > 1')
    assert_equal "ab >= 1", resolve_with_interp_warning('#{a + b} >= 1')
    assert_equal "ab < 1", resolve_with_interp_warning('#{a + b} < 1')
    assert_equal "ab <= 1", resolve_with_interp_warning('#{a + b} <= 1')
    assert_equal "ab + 1", resolve_with_interp_warning('#{a + b} + 1')
    assert_equal "ab * 1", resolve_with_interp_warning('#{a + b} * 1')
    assert_equal "ab - 1", resolve_with_interp_warning('#{a + b} - 1')
    assert_equal "ab % 1", resolve_with_interp_warning('#{a + b} % 1')
    assert_equal(
      "abvar",
      resolve_with_interp_warning(
        '#{a + b}$var', '"#{a + b}#{$var}"',
        env('var' => Sass::Script::Value::String.new("var"))))
    assert_equal(
      "varab",
      resolve_with_interp_warning(
        '$var#{a + b}', '"#{$var}#{a + b}"',
        env('var' => Sass::Script::Value::String.new("var"))))
    assert_equal "ab1", resolve_with_interp_warning('#{a + b}(1)', '"#{a + b}1"')
    assert_equal "1ab", resolve_with_interp_warning('(1)#{a + b}', '"1#{a + b}"')
  end

  def test_trailing_interpolation_with_deprecation_warning
    assert_equal "not ab", resolve_with_interp_warning('not #{a + b}')
    assert_equal "1 and ab", resolve_with_interp_warning('1 and #{a + b}')
    assert_equal "1 or ab", resolve_with_interp_warning('1 or #{a + b}')
    assert_equal "1 == ab", resolve_with_interp_warning('1 == #{a + b}')
    assert_equal "1 != ab", resolve_with_interp_warning('1 != #{a + b}')
    assert_equal "1 > ab", resolve_with_interp_warning('1 > #{a + b}')
    assert_equal "1 >= ab", resolve_with_interp_warning('1 >= #{a + b}')
    assert_equal "1 < ab", resolve_with_interp_warning('1 < #{a + b}')
    assert_equal "1 <= ab", resolve_with_interp_warning('1 <= #{a + b}')
    assert_equal "1 + ab", resolve_with_interp_warning('1 + #{a + b}')
    assert_equal "1 * ab", resolve_with_interp_warning('1 * #{a + b}')
    assert_equal "1 - ab", resolve_with_interp_warning('1 - #{a + b}')
    assert_equal "1 % ab", resolve_with_interp_warning('1 % #{a + b}')
    assert_equal "- ab", resolve_with_interp_warning('- #{a + b}')
    assert_equal "1- ab", resolve_with_interp_warning('1- #{a + b}')
    assert_equal "- ab 2 3", resolve_with_interp_warning('- #{a + b} 2 3', '"- #{a + b} #{2 3}"')
  end

  def test_brackteing_interpolation_with_deprecation_warning
    assert_equal "ab == cd", resolve_with_interp_warning('#{a + b} == #{c + d}')
    assert_equal "ab != cd", resolve_with_interp_warning('#{a + b} != #{c + d}')
    assert_equal "ab > cd", resolve_with_interp_warning('#{a + b} > #{c + d}')
    assert_equal "ab >= cd", resolve_with_interp_warning('#{a + b} >= #{c + d}')
    assert_equal "ab < cd", resolve_with_interp_warning('#{a + b} < #{c + d}')
    assert_equal "ab <= cd", resolve_with_interp_warning('#{a + b} <= #{c + d}')
    assert_equal "ab + cd", resolve_with_interp_warning('#{a + b} + #{c + d}')
    assert_equal "ab * cd", resolve_with_interp_warning('#{a + b} * #{c + d}')
    assert_equal "ab - cd", resolve_with_interp_warning('#{a + b} - #{c + d}')
    assert_equal "ab % cd", resolve_with_interp_warning('#{a + b} % #{c + d}')
  end

  def test_interp_warning_formatting
    resolve_with_interp_warning('#{1} + 1', '"1 + 1"')
    resolve_with_interp_warning('#{1} + "foo"', '\'1 + "foo"\'')
    resolve_with_interp_warning('#{1} + \'foo\'', '\'1 + "foo"\'')

    resolve_with_interp_warning('#{1} + "#{a + b}"', '\'1 + "#{a + b}"\'')
    resolve_with_interp_warning('"#{a + b}" + #{1}', '\'"#{a + b}" + 1\'')
    resolve_with_interp_warning('"#{a + b}" + #{1} + "#{c + d}"', '\'"#{a + b}" + 1 + "#{c + d}"\'')

    resolve_with_interp_warning('#{1} + "\'"', '"1 + \\"\'\\""')
    resolve_with_interp_warning('#{1} + \'"\'', '"1 + \'\\"\'"')
    resolve_with_interp_warning('#{1} + "\'\\""', '"1 + \\"\'\\\\\\"\\""')
  end

  def test_inactive_lazy_interpolation_deprecation_warning
    assert_equal '1, 2, 3', assert_no_warning {resolve('1, #{2}, 3')}
    assert_equal '1, 2, 3', assert_no_warning {resolve('1, 2, #{3}')}
    assert_equal '1,2,3', assert_no_warning {resolve('1,#{2},3')}
    assert_equal '1 2 3', assert_no_warning {resolve('#{1} 2 3')}
    assert_equal '1 2 3', assert_no_warning {resolve('1 #{2} 3')}
    assert_equal '1 2 3', assert_no_warning {resolve('1 2 #{3}')}

    assert_equal '+1 2 3', assert_no_warning {resolve('+#{1} 2 3')}
    assert_equal '-1 2 3', assert_no_warning {resolve('-#{1} 2 3')}
    assert_equal '/1 2 3', assert_no_warning {resolve('/#{1} 2 3')}

    assert_equal '1, 2, 31', assert_no_warning {resolve('(1, #{2}, 3) + 1')}
    assert_equal '11, 2, 3', assert_no_warning {resolve('1 + (1, #{2}, 3)')}

    assert_equal 'a, b, c', assert_no_warning {resolve('selector-parse((a, #{b}, c))')}
  end

  def test_active_lazy_interpolation_deprecation_warning
    Sass::Deprecation.allow_double_warnings do
      assert_equal "1, 2, 3", resolve_with_lazy_interp_warning('quote((1, #{2}, 3))', '"1, 2, 3"')
      assert_equal "1", resolve_with_lazy_interp_warning('length((1, #{2}, 3))', '"1, 2, 3"')
      assert_equal "1, 2, 3", resolve_with_lazy_interp_warning('inspect((1, #{2}, 3))', '"1, 2, 3"')
      assert_equal "string", resolve_with_lazy_interp_warning('type-of((1, #{2}, 3))', '"1, 2, 3"')

      assert_equal "+1 2 3", resolve_with_lazy_interp_warning('quote((+#{1} 2 3))', '"+1 #{2 3}"')
      assert_equal "/1 2 3", resolve_with_lazy_interp_warning('quote((/#{1} 2 3))', '"/1 #{2 3}"')
      assert_equal "-1 2 3", resolve_with_lazy_interp_warning('quote((-#{1} 2 3))', '"-1 #{2 3}"')
    end
  end

  def test_comparison_of_complex_units
    # Tests for issue #1960
    Sass::Deprecation.allow_double_warnings do
      assert_warning(<<WARNING) do
DEPRECATION WARNING on line 1 of test_comparison_of_complex_units_inline.sass:
The result of `10 == 10px` will be `false` in future releases of Sass.
Unitless numbers will no longer be equal to the same numbers with units.
WARNING
        assert_equal "true", resolve("10 == 2 * 5px")
      end
      assert_warning(<<WARNING) do
DEPRECATION WARNING on line 1 of test_comparison_of_complex_units_inline.sass:
The result of `10 == 10px*px` will be `false` in future releases of Sass.
Unitless numbers will no longer be equal to the same numbers with units.
WARNING
        assert_equal "true", resolve("10 == 2px * 5px")
      end
    end

    assert_equal "true", resolve("10px * 1px == 2px * 5px")
    assert_equal "true", resolve("5px * 1px < 2px * 5px")
  end

  private

  def resolve_with_lazy_interp_warning(str, contents = nil, environment = env)
    contents ||= "\"#{str}\""
    result = assert_warning(<<WARNING) {resolve(str, {}, environment)}
DEPRECATION WARNING on line 1 of #{filename_for_test}:
\#{} interpolation near operators will be simplified in a future version of Sass.
To preserve the current behavior, use quotes:

  unquote(#{contents})
WARNING
    $_sass_deprecated_interp_warnings = nil
    result
  end

  def resolve_with_interp_warning(str, contents = nil, environment = env)
    contents ||= "\"#{str}\""
    assert_warning(<<WARNING) {resolve(str, {}, environment)}
DEPRECATION WARNING on line 1 of #{filename_for_test}:
\#{} interpolation near operators will be simplified in a future version of Sass.
To preserve the current behavior, use quotes:

  unquote(#{contents})

You can use the sass-convert command to automatically fix most cases.
WARNING
  end

  def resolve(str, opts = {}, environment = env)
    munge_filename opts
    val = eval(str, opts, environment)
    assert_kind_of Sass::Script::Value::Base, val
    val.options = opts
    val.is_a?(Sass::Script::Value::String) ? val.value : val.to_s
  end

  def resolve_quoted(str, opts = {}, environment = env)
    munge_filename opts
    val = eval(str, opts, environment)
    assert_kind_of Sass::Script::Value::Base, val
    val.to_s
  end

  def assert_unquoted(str, opts = {}, environment = env)
    munge_filename opts
    val = eval(str, opts, environment)
    assert_kind_of Sass::Script::Value::String, val
    assert_equal :identifier, val.type
  end

  def assert_quoted(str, opts = {}, environment = env)
    munge_filename opts
    val = eval(str, opts, environment)
    assert_kind_of Sass::Script::Value::String, val
    assert_equal :string, val.type
  end

  def eval(str, opts = {}, environment = env)
    munge_filename opts
    Sass::Script.parse(str, opts.delete(:line) || 1,
      opts.delete(:offset) || 0, opts).
      perform(Sass::Environment.new(environment, opts))
  end

  def render(sass, options = {})
    munge_filename options
    Sass::Engine.new(sass, options).render
  end

  def env(hash = {})
    env = Sass::Environment.new
    hash.each {|k, v| env.set_var(k, v)}
    env
  end

  def selector(str)
    parser = Sass::SCSS::StaticParser.new(
      str, filename_for_test, Sass::Importers::Filesystem.new('.'))
    parser.parse_selector
  end

  def test_null_is_a_singleton
    assert_same Sass::Script::Value::Null.new, Sass::Script::Value::Null.new
  end
end