forked from sass/dart-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeprecations_test.dart
147 lines (121 loc) · 4.28 KB
/
deprecations_test.dart
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
// Copyright 2018 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
@TestOn('vm')
library;
import 'package:test/test.dart';
import 'package:sass/sass.dart';
void main() {
// Deprecated in all version of Dart Sass
test("callString is violated by passing a string to call", () {
_expectDeprecation("a { b: call(random)}", Deprecation.callString);
});
// Deprecated in 1.3.2
test("elseIf is violated by using @elseif instead of @else if", () {
_expectDeprecation("@if false {} @elseif false {}", Deprecation.elseif);
});
// Deprecated in 1.7.2
test("mozDocument is violated by most @-moz-document rules", () {
_expectDeprecation(
"@-moz-document url-prefix(foo) {}",
Deprecation.mozDocument,
);
});
// Deprecated in 1.17.2
test("newGlobal is violated by declaring a new variable with !global", () {
_expectDeprecation(r"a {$foo: bar !global;}", Deprecation.newGlobal);
});
// Deprecated in 1.23.0
group("colorModuleCompat is violated by", () {
var color = "@use 'sass:color'; a { b: color";
test("passing a number to color.invert", () {
_expectDeprecation("$color.invert(0)}", Deprecation.colorModuleCompat);
});
test("passing a number to color.grayscale", () {
_expectDeprecation("$color.grayscale(0)}", Deprecation.colorModuleCompat);
});
test("passing a number to color.opacity", () {
_expectDeprecation("$color.opacity(0)}", Deprecation.colorModuleCompat);
});
test("using color.alpha for a microsoft filter", () {
_expectDeprecation(
"$color.alpha(foo=bar)}",
Deprecation.colorModuleCompat,
);
});
});
// Deprecated in 1.33.0
test("slashDiv is violated by using / for division", () {
_expectDeprecation(r"a {b: (4/2)}", Deprecation.slashDiv);
});
// Deprecated in 1.54.0
group("bogusCombinators is violated by", () {
test("adjacent combinators", () {
_expectDeprecation("a > > a {b: c}", Deprecation.bogusCombinators);
});
test("leading combinators", () {
_expectDeprecation("a > {b: c}", Deprecation.bogusCombinators);
});
test("trailing combinators", () {
_expectDeprecation("> a {b: c}", Deprecation.bogusCombinators);
});
});
// Deprecated in 1.55.0
group("strictUnary is violated by", () {
test("an ambiguous + operator", () {
_expectDeprecation(r"a {b: 1 +2}", Deprecation.strictUnary);
});
test("an ambiguous - operator", () {
_expectDeprecation(r"a {$x: 2; b: 1 -$x}", Deprecation.strictUnary);
});
});
// Deprecated in various Sass versions <=1.56.0
group("functionUnits is violated by", () {
test("a hue with a non-angle unit", () {
_expectDeprecation("a {b: hsl(10px, 0%, 0%)}", Deprecation.functionUnits);
});
test("a saturation/lightness with a non-percent unit", () {
_expectDeprecation(
"a {b: hsl(10deg, 0px, 0%)}",
Deprecation.functionUnits,
);
});
test("a saturation/lightness with no unit", () {
_expectDeprecation("a {b: hsl(10deg, 0%, 0)}", Deprecation.functionUnits);
});
test("an alpha value with a non-percent unit", () {
_expectDeprecation(
r"@use 'sass:color'; a {b: color.change(red, $alpha: 1px)}",
Deprecation.functionUnits,
);
});
test("calling math.random with units", () {
_expectDeprecation(
"@use 'sass:math'; a {b: math.random(100px)}",
Deprecation.functionUnits,
);
});
test("calling list.nth with units", () {
_expectDeprecation(
"@use 'sass:list'; a {b: list.nth(1 2, 1px)}",
Deprecation.functionUnits,
);
});
test("calling list.set-nth with units", () {
_expectDeprecation(
"@use 'sass:list'; a {b: list.set-nth(1 2, 1px, 3)}",
Deprecation.functionUnits,
);
});
});
}
/// Confirms that [source] will error if [deprecation] is fatal.
void _expectDeprecation(String source, Deprecation deprecation) {
try {
compileStringToResult(source, fatalDeprecations: {deprecation});
} catch (e) {
if (e.toString().contains("$deprecation deprecation to be fatal")) return;
fail('Unexpected error: $e');
}
fail("No error for violating $deprecation.");
}