2
2
// MIT-style license that can be found in the LICENSE file or at
3
3
// https://opensource.org/licenses/MIT.
4
4
5
- @Skip ("TODO(nweiz): Update these for the new Color API" )
6
5
@TestOn ('vm' )
7
6
library ;
8
7
@@ -39,14 +38,116 @@ void main() {
39
38
expect (value.alpha, equals (1 ));
40
39
});
41
40
41
+ test ("has a named alpha channel" , () {
42
+ expect (value.channel ("alpha" ), equals (1 ));
43
+ });
44
+
45
+ group ("channel()" , () {
46
+ test ("returns RGB channels" , () {
47
+ expect (value.channel ("red" ), equals (0x12 ));
48
+ expect (value.channel ("green" ), equals (0x34 ));
49
+ expect (value.channel ("blue" ), equals (0x56 ));
50
+ });
51
+
52
+ test ("returns alpha" , () {
53
+ expect (value.channel ("alpha" ), equals (1 ));
54
+ });
55
+
56
+ test ("throws for a channel not in this space" , () {
57
+ expect (() => value.channel ("hue" ), throwsSassScriptException);
58
+ });
59
+ });
60
+
61
+ test ("isChannelMissing() throws for a channel not in this space" , () {
62
+ expect (() => value.channel ("hue" ), throwsSassScriptException);
63
+ });
64
+
65
+ test ("isChannelPowerless() throws for a channel not in this space" , () {
66
+ expect (() => value.channel ("hue" ), throwsSassScriptException);
67
+ });
68
+
69
+ test ("has a space" , () {
70
+ expect (value.space, equals (ColorSpace .rgb));
71
+ });
72
+
73
+ test ("is a legacy color" , () {
74
+ expect (value.isLegacy, isTrue);
75
+ });
76
+
42
77
test ("equals the same color" , () {
43
78
expect (value, equalsWithHash (SassColor .rgb (0x12 , 0x34 , 0x56 )));
79
+ });
80
+
81
+ test ("equals an equivalent legacy color" , () {
44
82
expect (
45
83
value,
46
84
equalsWithHash (
47
85
SassColor .hsl (210 , 65.3846153846154 , 20.392156862745097 )));
48
86
});
49
87
88
+ test ("does not equal an equivalent non-legacy color" , () {
89
+ expect (value, isNot (equals (SassColor .srgb (0x12 , 0x34 , 0x56 ))));
90
+ });
91
+
92
+ group ("isInGamut" , () {
93
+ test ("returns true if the color is in the RGB gamut" , () {
94
+ expect (value.isInGamut, isTrue);
95
+ });
96
+
97
+ test ("returns false if the color is outside the RGB gamut" , () {
98
+ expect (value.changeChannels ({"red" : 0x100 }).isInGamut, isFalse);
99
+ });
100
+ });
101
+
102
+ group ("toSpace" , () {
103
+ test ("converts the color to a given space" , () {
104
+ expect (
105
+ value.toSpace (ColorSpace .lab),
106
+ equals (SassColor .lab (
107
+ 20.675469453386192 , - 2.276792630515417 , - 24.59314874484676 )));
108
+ });
109
+
110
+ test ("with legacyMissing: true, makes a powerless channel missing" , () {
111
+ expect (
112
+ SassColor .rgb (0 , 0 , 0 )
113
+ .toSpace (ColorSpace .hsl)
114
+ .isChannelMissing ("hue" ),
115
+ isTrue);
116
+ });
117
+
118
+ test ("with legacyMissing: false, makes a powerless channel zero" , () {
119
+ var result = SassColor .rgb (0 , 0 , 0 )
120
+ .toSpace (ColorSpace .hsl, legacyMissing: false );
121
+ expect (result.isChannelMissing ("hue" ), isFalse);
122
+ expect (result.channel ("hue" ), equals (0 ));
123
+ });
124
+
125
+ test (
126
+ "even with legacyMissing: false, preserves missing channels for same "
127
+ "space" , () {
128
+ expect (
129
+ SassColor .rgb (0 , null , 0 )
130
+ .toSpace (ColorSpace .rgb, legacyMissing: false )
131
+ .isChannelMissing ("green" ),
132
+ isTrue);
133
+ });
134
+ });
135
+
136
+ group ("toGamut() brings the color into its gamut" , () {
137
+ setUp (() => value = parseValue ("rgb(300 200 100)" ) as SassColor );
138
+
139
+ test ("with clip" , () {
140
+ expect (value.toGamut (GamutMapMethod .clip),
141
+ equals (SassColor .rgb (255 , 200 , 100 )));
142
+ });
143
+
144
+ test ("with localMinde" , () {
145
+ // TODO: update
146
+ expect (value.toGamut (GamutMapMethod .localMinde),
147
+ equals (SassColor .rgb (255 , 200 , 100 )));
148
+ });
149
+ });
150
+
50
151
group ("changeRgb()" , () {
51
152
test ("changes RGB values" , () {
52
153
expect (value.changeRgb (red: 0xAA ),
@@ -61,102 +162,85 @@ void main() {
61
162
equals (SassColor .rgb (0xAA , 0xAA , 0xAA , 0.5 )));
62
163
});
63
164
64
- test ("allows valid values" , () {
65
- expect (value.changeRgb (red: 0 ).red, equals (0 ));
66
- expect (value.changeRgb (red: 0xFF ).red, equals (0xFF ));
67
- expect (value.changeRgb (green: 0 ).green, equals (0 ));
68
- expect (value.changeRgb (green: 0xFF ).green, equals (0xFF ));
69
- expect (value.changeRgb (blue: 0 ).blue, equals (0 ));
70
- expect (value.changeRgb (blue: 0xFF ).blue, equals (0xFF ));
71
- expect (value.changeRgb (alpha: 0 ).alpha, equals (0 ));
165
+ test ("allows in-gamut alpha" , () {
72
166
expect (value.changeRgb (alpha: 1 ).alpha, equals (1 ));
167
+ expect (value.changeRgb (alpha: 0 ).alpha, equals (0 ));
168
+ });
169
+
170
+ test ("allows out-of-gamut values" , () {
171
+ expect (value.changeRgb (red: - 1 ).red, equals (- 1 ));
172
+ expect (value.changeRgb (red: 0x100 ).red, equals (0x100 ));
73
173
});
74
174
75
- test ("disallows invalid values" , () {
76
- expect (() => value.changeRgb (red: - 1 ), throwsRangeError);
77
- expect (() => value.changeRgb (red: 0x100 ), throwsRangeError);
78
- expect (() => value.changeRgb (green: - 1 ), throwsRangeError);
79
- expect (() => value.changeRgb (green: 0x100 ), throwsRangeError);
80
- expect (() => value.changeRgb (blue: - 1 ), throwsRangeError);
81
- expect (() => value.changeRgb (blue: 0x100 ), throwsRangeError);
175
+ test ("disallows out-of-gamut alpha" , () {
82
176
expect (() => value.changeRgb (alpha: - 0.1 ), throwsRangeError);
83
177
expect (() => value.changeRgb (alpha: 1.1 ), throwsRangeError);
84
178
});
85
179
});
86
180
87
- group ("changeHsl()" , () {
88
- test ("changes HSL values" , () {
89
- expect (value.changeHsl (hue: 120 ),
90
- equals (SassColor .hsl (120 , 65.3846153846154 , 20.392156862745097 )));
91
- expect (value.changeHsl (saturation: 42 ),
92
- equals (SassColor .hsl (210 , 42 , 20.392156862745097 )));
93
- expect (value.changeHsl (lightness: 42 ),
94
- equals (SassColor .hsl (210 , 65.3846153846154 , 42 )));
95
- expect (
96
- value.changeHsl (alpha: 0.5 ),
97
- equals (
98
- SassColor .hsl (210 , 65.3846153846154 , 20.392156862745097 , 0.5 )));
99
- expect (
100
- value.changeHsl (
101
- hue: 120 , saturation: 42 , lightness: 42 , alpha: 0.5 ),
102
- equals (SassColor .hsl (120 , 42 , 42 , 0.5 )));
103
- });
104
-
105
- test ("allows valid values" , () {
106
- expect (value.changeHsl (saturation: 0 ).saturation, equals (0 ));
107
- expect (value.changeHsl (saturation: 100 ).saturation, equals (100 ));
108
- expect (value.changeHsl (lightness: 0 ).lightness, equals (0 ));
109
- expect (value.changeHsl (lightness: 100 ).lightness, equals (100 ));
110
- expect (value.changeHsl (alpha: 0 ).alpha, equals (0 ));
111
- expect (value.changeHsl (alpha: 1 ).alpha, equals (1 ));
112
- });
181
+ test ("changeHsl() changes HSL values" , () {
182
+ expect (value.changeHsl (hue: 120 ),
183
+ equals (SassColor .hsl (120 , 65.3846153846154 , 20.392156862745097 )));
184
+ expect (value.changeHsl (saturation: 42 ),
185
+ equals (SassColor .hsl (210 , 42 , 20.392156862745097 )));
186
+ expect (value.changeHsl (lightness: 42 ),
187
+ equals (SassColor .hsl (210 , 65.3846153846154 , 42 )));
188
+ expect (
189
+ value.changeHsl (alpha: 0.5 ),
190
+ equals (
191
+ SassColor .hsl (210 , 65.3846153846154 , 20.392156862745097 , 0.5 )));
192
+ expect (
193
+ value.changeHsl (hue: 120 , saturation: 42 , lightness: 42 , alpha: 0.5 ),
194
+ equals (SassColor .hsl (120 , 42 , 42 , 0.5 )));
195
+ });
113
196
114
- test ("disallows invalid values" , () {
115
- expect (() => value.changeHsl (saturation: - 0.1 ), throwsRangeError);
116
- expect (() => value.changeHsl (saturation: 100.1 ), throwsRangeError);
117
- expect (() => value.changeHsl (lightness: - 0.1 ), throwsRangeError);
118
- expect (() => value.changeHsl (lightness: 100.1 ), throwsRangeError);
119
- expect (() => value.changeHsl (alpha: - 0.1 ), throwsRangeError);
120
- expect (() => value.changeHsl (alpha: 1.1 ), throwsRangeError);
121
- });
197
+ test ("changeHwb() changes HWB values" , () {
198
+ expect (value.changeHwb (hue: 120 ),
199
+ equals (SassColor .hwb (120 , 7.0588235294117645 , 66.27450980392157 )));
200
+ expect (value.changeHwb (whiteness: 20 ),
201
+ equals (SassColor .hwb (210 , 20 , 66.27450980392157 )));
202
+ expect (value.changeHwb (blackness: 42 ),
203
+ equals (SassColor .hwb (210 , 7.0588235294117645 , 42 )));
204
+ expect (
205
+ value.changeHwb (alpha: 0.5 ),
206
+ equals (
207
+ SassColor .hwb (210 , 7.0588235294117645 , 66.27450980392157 , 0.5 )));
208
+ expect (
209
+ value.changeHwb (hue: 120 , whiteness: 42 , blackness: 42 , alpha: 0.5 ),
210
+ equals (SassColor .hwb (120 , 42 , 42 , 0.5 )));
211
+ expect (value.changeHwb (whiteness: 50 ),
212
+ equals (SassColor .hwb (210 , 43.0016863406408 , 56.9983136593592 )));
122
213
});
123
214
124
- group ("changeHwb()" , () {
125
- test ("changes HWB values" , () {
126
- expect (value.changeHwb (hue: 120 ),
127
- equals (SassColor .hwb (120 , 7.0588235294117645 , 66.27450980392157 )));
128
- expect (value.changeHwb (whiteness: 20 ),
129
- equals (SassColor .hwb (210 , 20 , 66.27450980392157 )));
130
- expect (value.changeHwb (blackness: 42 ),
131
- equals (SassColor .hwb (210 , 7.0588235294117645 , 42 )));
132
- expect (
133
- value.changeHwb (alpha: 0.5 ),
134
- equals (SassColor .hwb (
135
- 210 , 7.0588235294117645 , 66.27450980392157 , 0.5 )));
136
- expect (
137
- value.changeHwb (hue: 120 , whiteness: 42 , blackness: 42 , alpha: 0.5 ),
138
- equals (SassColor .hwb (120 , 42 , 42 , 0.5 )));
215
+ group ("changeChannels()" , () {
216
+ test ("changes RGB values" , () {
217
+ expect (value.changeChannels ({"red" : 0xAA }),
218
+ equals (SassColor .rgb (0xAA , 0x34 , 0x56 )));
219
+ expect (value.changeChannels ({"green" : 0xAA }),
220
+ equals (SassColor .rgb (0x12 , 0xAA , 0x56 )));
221
+ expect (value.changeChannels ({"blue" : 0xAA }),
222
+ equals (SassColor .rgb (0x12 , 0x34 , 0xAA )));
223
+ expect (value.changeChannels ({"alpha" : 0.5 }),
224
+ equals (SassColor .rgb (0x12 , 0x34 , 0x56 , 0.5 )));
139
225
expect (
140
- value.changeHwb (whiteness: 50 ), equals (SassColor .hwb (210 , 43 , 57 )));
226
+ value.changeChannels (
227
+ {"red" : 0xAA , "green" : 0xAA , "blue" : 0xAA , "alpha" : 0.5 }),
228
+ equals (SassColor .rgb (0xAA , 0xAA , 0xAA , 0.5 )));
141
229
});
142
230
143
- test ("allows valid values" , () {
144
- expect (value.changeHwb (whiteness: 0 ).whiteness, equals (0 ));
145
- expect (value.changeHwb (whiteness: 100 ).whiteness, equals (60.0 ));
146
- expect (value.changeHwb (blackness: 0 ).blackness, equals (0 ));
147
- expect (value.changeHwb (blackness: 100 ).blackness,
148
- equals (93.33333333333333 ));
149
- expect (value.changeHwb (alpha: 0 ).alpha, equals (0 ));
150
- expect (value.changeHwb (alpha: 1 ).alpha, equals (1 ));
231
+ test ("allows in-gamut alpha" , () {
232
+ expect (value.changeChannels ({"alpha" : 1 }).alpha, equals (1 ));
233
+ expect (value.changeChannels ({"alpha" : 0 }).alpha, equals (0 ));
151
234
});
152
235
153
- test ("disallows invalid values" , () {
154
- expect (() => value.changeHwb (whiteness: - 0.1 ), throwsRangeError);
155
- expect (() => value.changeHwb (whiteness: 100.1 ), throwsRangeError);
156
- expect (() => value.changeHwb (blackness: - 0.1 ), throwsRangeError);
157
- expect (() => value.changeHwb (blackness: 100.1 ), throwsRangeError);
158
- expect (() => value.changeHwb (alpha: - 0.1 ), throwsRangeError);
159
- expect (() => value.changeHwb (alpha: 1.1 ), throwsRangeError);
236
+ test ("allows out-of-gamut values" , () {
237
+ expect (value.changeChannels ({"red" : - 1 }).red, equals (- 1 ));
238
+ expect (value.changeChannels ({"red" : 0x100 }).red, equals (0x100 ));
239
+ });
240
+
241
+ test ("disallows out-of-gamut alpha" , () {
242
+ expect (() => value.changeChannels ({"alpha" : - 0.1 }), throwsRangeError);
243
+ expect (() => value.changeChannels ({"alpha" : 1.1 }), throwsRangeError);
160
244
});
161
245
});
162
246
@@ -192,126 +276,133 @@ void main() {
192
276
});
193
277
});
194
278
195
- group ("an HSL color" , () {
279
+ group ("a color with a missing channel " , () {
196
280
late SassColor value;
197
- setUp (() => value = parseValue ("hsl(120, 42%, 42%)" ) as SassColor );
281
+ setUp (() =>
282
+ value = parseValue ("color(display-p3 0.3 0.4 none)" ) as SassColor );
198
283
199
- test ("has RGB channels" , () {
200
- expect (value.red, equals ( 0x3E ) );
201
- expect (value.green, equals ( 0x98 ) );
202
- expect (value.blue, equals ( 0x3E ) );
284
+ test ("reports present channels as present " , () {
285
+ expect (value.isChannelMissing ( " red" ), isFalse );
286
+ expect (value.isChannelMissing ( " green" ), isFalse );
287
+ expect (value.isChannelMissing ( "alpha" ), isFalse );
203
288
});
204
289
205
- test ("has HSL channels" , () {
206
- expect (value.hue, equals (120 ));
207
- expect (value.saturation, equals (42 ));
208
- expect (value.lightness, equals (42 ));
290
+ test ("reports the missing channel as missing" , () {
291
+ expect (value.isChannelMissing ("blue" ), isTrue);
209
292
});
210
293
211
- test ("has HWB channels" , () {
212
- expect (value.whiteness, equals (24.313725490196077 ));
213
- expect (value.blackness, equals (40.3921568627451 ));
214
- });
215
-
216
- test ("has an alpha channel" , () {
217
- expect (value.alpha, equals (1 ));
294
+ test ("reports the missing channel's value as 0" , () {
295
+ expect (value.channel ("blue" ), equals (0 ));
218
296
});
219
297
220
- test ("equals the same color" , () {
221
- expect (value, equalsWithHash (SassColor .rgb (0x3E , 0x98 , 0x3E )));
222
- expect (value, equalsWithHash (SassColor .hsl (120 , 42 , 42 )));
223
- expect (
224
- value,
225
- equalsWithHash (
226
- SassColor .hwb (120 , 24.313725490196077 , 40.3921568627451 )));
298
+ test ("does not report the missing channel as powerless" , () {
299
+ expect (value.isChannelPowerless ("blue" ), isFalse);
227
300
});
228
301
});
229
302
230
- test ("an RGBA color has an alpha channel" , () {
231
- var color = parseValue ("rgba(10, 20, 30, 0.7)" ) as SassColor ;
232
- expect (color.alpha, closeTo (0.7 , 1e-11 ));
233
- });
303
+ group ("a color with a powerless channel" , () {
304
+ late SassColor value;
305
+ setUp (() => value = parseValue ("hsl(120 0% 50%)" ) as SassColor );
234
306
235
- group ( "new SassColor.rgb() " , () {
236
- test ( "allows valid values" , () {
237
- expect (SassColor . rgb ( 0 , 0 , 0 , 0 ), equals ( parseValue ( "rgba(0, 0, 0, 0)" )) );
238
- expect (SassColor . rgb ( 0xFF , 0xFF , 0xFF , 1 ), equals ( parseValue ( "#fff" )) );
307
+ test ( "reports powerful channels as powerful " , () {
308
+ expect (value. isChannelPowerless ( "saturation" ), isFalse);
309
+ expect (value. isChannelPowerless ( "lightness" ), isFalse );
310
+ expect (value. isChannelPowerless ( "alpha" ), isFalse );
239
311
});
240
312
241
- test ("disallows invalid values" , () {
242
- expect (() => SassColor .rgb (- 1 , 0 , 0 , 0 ), throwsRangeError);
243
- expect (() => SassColor .rgb (0 , - 1 , 0 , 0 ), throwsRangeError);
244
- expect (() => SassColor .rgb (0 , 0 , - 1 , 0 ), throwsRangeError);
245
- expect (() => SassColor .rgb (0 , 0 , 0 , - 0.1 ), throwsRangeError);
246
- expect (() => SassColor .rgb (0x100 , 0 , 0 , 0 ), throwsRangeError);
247
- expect (() => SassColor .rgb (0 , 0x100 , 0 , 0 ), throwsRangeError);
248
- expect (() => SassColor .rgb (0 , 0 , 0x100 , 0 ), throwsRangeError);
249
- expect (() => SassColor .rgb (0 , 0 , 0 , 1.1 ), throwsRangeError);
313
+ test ("reports the powerless channel as powerless" , () {
314
+ expect (value.isChannelPowerless ("hue" ), isTrue);
250
315
});
251
- });
252
316
253
- group ("new SassColor.hsl()" , () {
254
- test ("allows valid values" , () {
255
- expect (
256
- SassColor .hsl (0 , 0 , 0 , 0 ), equals (parseValue ("hsla(0, 0%, 0%, 0)" )));
257
- expect (SassColor .hsl (4320 , 100 , 100 , 1 ),
258
- equals (parseValue ("hsl(4320, 100%, 100%)" )));
317
+ test ("reports the powerless channel's value" , () {
318
+ expect (value.channel ("hue" ), 120 );
259
319
});
260
320
261
- test ("disallows invalid values" , () {
262
- expect (() => SassColor .hsl (0 , - 0.1 , 0 , 0 ), throwsRangeError);
263
- expect (() => SassColor .hsl (0 , 0 , - 0.1 , 0 ), throwsRangeError);
264
- expect (() => SassColor .hsl (0 , 0 , 0 , - 0.1 ), throwsRangeError);
265
- expect (() => SassColor .hsl (0 , 100.1 , 0 , 0 ), throwsRangeError);
266
- expect (() => SassColor .hsl (0 , 0 , 100.1 , 0 ), throwsRangeError);
267
- expect (() => SassColor .hsl (0 , 0 , 0 , 1.1 ), throwsRangeError);
321
+ test ("does not report the powerless channel as missing" , () {
322
+ expect (value.isChannelMissing ("hue" ), isFalse);
268
323
});
269
324
});
270
325
271
- group ("new SassColor.hwb() " , () {
326
+ group ("an LCH color " , () {
272
327
late SassColor value;
273
- setUp (() => value = SassColor .hwb (120 , 42 , 42 ));
274
-
275
- test ("has RGB channels" , () {
276
- expect (value.red, equals (0x6B ));
277
- expect (value.green, equals (0x94 ));
278
- expect (value.blue, equals (0x6B ));
328
+ setUp (() => value = parseValue ("lch(42% 42% 120)" ) as SassColor );
329
+
330
+ test ("throws for legacy channels" , () {
331
+ expect (() => value.red, throwsSassScriptException);
332
+ expect (() => value.green, throwsSassScriptException);
333
+ expect (() => value.blue, throwsSassScriptException);
334
+ expect (() => value.hue, throwsSassScriptException);
335
+ expect (() => value.saturation, throwsSassScriptException);
336
+ expect (() => value.lightness, throwsSassScriptException);
337
+ expect (() => value.whiteness, throwsSassScriptException);
338
+ expect (() => value.blackness, throwsSassScriptException);
279
339
});
280
340
281
- test ("has HSL channels" , () {
282
- expect (value.hue, equals (120 ));
283
- expect (value.saturation, equals (16.078431372549026 ));
284
- expect (value.lightness, equals (50 ));
341
+ test ("has an alpha channel" , () {
342
+ expect (value.alpha, equals (1 ));
285
343
});
286
344
287
- test ("has HWB channels" , () {
288
- expect (value.whiteness, equals (41.96078431372549 ));
289
- expect (value.blackness, equals (41.96078431372548 ));
345
+ group ("channel()" , () {
346
+ test ("returns LCH channels" , () {
347
+ expect (value.channel ("lightness" ), equals (42 ));
348
+ expect (value.channel ("chroma" ), equals (63 ));
349
+ expect (value.channel ("hue" ), equals (120 ));
350
+ });
351
+
352
+ test ("returns alpha" , () {
353
+ expect (value.channel ("alpha" ), equals (1 ));
354
+ });
355
+
356
+ test ("throws for a channel not in this space" , () {
357
+ expect (() => value.channel ("red" ), throwsSassScriptException);
358
+ });
290
359
});
291
360
292
- test ("has an alpha channel " , () {
293
- expect (value.alpha, equals ( 1 ) );
361
+ test ("is not a legacy color " , () {
362
+ expect (value.isLegacy, isFalse );
294
363
});
295
364
296
365
test ("equals the same color" , () {
297
- expect (value, equalsWithHash (SassColor .rgb (0x6B , 0x94 , 0x6B )));
298
- expect (value, equalsWithHash (SassColor .hsl (120 , 16 , 50 )));
299
- expect (value, equalsWithHash (SassColor .hwb (120 , 42 , 42 )));
366
+ expect (value, equalsWithHash (SassColor .lch (42 , 63 , 120 )));
300
367
});
301
368
302
- test ("allows valid values " , () {
369
+ test ("doesn't equal an equivalent color " , () {
303
370
expect (
304
- SassColor .hwb (0 , 0 , 0 , 0 ), equals (parseValue ("rgba(255, 0, 0, 0)" )));
305
- expect (SassColor .hwb (4320 , 100 , 100 , 1 ), equals (parseValue ("grey" )));
371
+ value,
372
+ isNot (equals (SassColor .xyzD65 (0.07461544022446227 ,
373
+ 0.12417002656711021 , 0.011301590030256693 ))));
306
374
});
307
375
308
- test ("disallows invalid values" , () {
309
- expect (() => SassColor .hwb (0 , - 0.1 , 0 , 0 ), throwsRangeError);
310
- expect (() => SassColor .hwb (0 , 0 , - 0.1 , 0 ), throwsRangeError);
311
- expect (() => SassColor .hwb (0 , 0 , 0 , - 0.1 ), throwsRangeError);
312
- expect (() => SassColor .hwb (0 , 100.1 , 0 , 0 ), throwsRangeError);
313
- expect (() => SassColor .hwb (0 , 0 , 100.1 , 0 ), throwsRangeError);
314
- expect (() => SassColor .hwb (0 , 0 , 0 , 1.1 ), throwsRangeError);
376
+ test ("changeChannels() changes LCH values" , () {
377
+ expect (value.changeChannels ({"lightness" : 30 }),
378
+ equals (SassColor .lch (30 , 63 , 120 )));
379
+ expect (value.changeChannels ({"chroma" : 30 }),
380
+ equals (SassColor .lch (42 , 30 , 120 )));
381
+ expect (
382
+ value.changeChannels ({"hue" : 80 }), equals (SassColor .lch (42 , 63 , 80 )));
383
+ expect (value.changeChannels ({"alpha" : 0.5 }),
384
+ equals (SassColor .lch (42 , 63 , 120 , 0.5 )));
385
+ expect (
386
+ value.changeChannels (
387
+ {"lightness" : 30 , "chroma" : 30 , "hue" : 30 , "alpha" : 0.5 }),
388
+ equals (SassColor .lch (30 , 30 , 30 , 0.5 )));
389
+ });
390
+ });
391
+
392
+ test ("an RGBA color has an alpha channel" , () {
393
+ var color = parseValue ("rgba(10, 20, 30, 0.7)" ) as SassColor ;
394
+ expect (color.alpha, closeTo (0.7 , 1e-11 ));
395
+ });
396
+
397
+ group ("new SassColor.rgb()" , () {
398
+ test ("allows out-of-gamut values" , () {
399
+ expect (SassColor .rgb (- 1 , 0 , 0 , 0 ).channel ("red" ), equals (- 1 ));
400
+ expect (SassColor .rgb (0 , 100 , 0 , 0 ).channel ("green" ), equals (100 ));
401
+ });
402
+
403
+ test ("disallows out-of-gamut alpha values" , () {
404
+ expect (() => SassColor .rgb (0 , 0 , 0 , - 0.1 ), throwsRangeError);
405
+ expect (() => SassColor .rgb (0 , 0 , 0 , 1.1 ), throwsRangeError);
315
406
});
316
407
});
317
408
}
0 commit comments