Skip to content

Commit

Permalink
[Color 4] Add tests for oklab()
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Oct 6, 2023
1 parent 3f05b29 commit a23a92f
Show file tree
Hide file tree
Showing 13 changed files with 763 additions and 21 deletions.
8 changes: 4 additions & 4 deletions spec/core_functions/color/hsl/error/one_arg.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ a {
}

<===> type/hue/error
Error: $channels: Expected hue "foo" to be a number.
Error: $channels: Expected hue channel to be a number, was "foo".
,
2 | b: hsl("foo" 100% 50%);
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -116,7 +116,7 @@ a {
}

<===> type/saturation/error
Error: $channels: Expected saturation "foo" to be a number.
Error: $channels: Expected saturation channel to be a number, was "foo".
,
2 | b: hsl(0 "foo" 50%);
| ^^^^^^^^^^^^^^^^
Expand All @@ -131,7 +131,7 @@ a {
}

<===> type/lightness/error
Error: $channels: Expected lightness "foo" to be a number.
Error: $channels: Expected lightness channel to be a number, was "foo".
,
2 | b: hsl(0 100% "foo");
| ^^^^^^^^^^^^^^^^^
Expand All @@ -146,7 +146,7 @@ a {
}

<===> quoted_var_slash/error
Error: $channels: Expected lightness "var(--foo) / 0.4" to be a number.
Error: $channels: Expected lightness channel to be a number, was "var(--foo) / 0.4".
,
2 | b: hsl(0 100% "var(--foo) / 0.4");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions spec/core_functions/color/hwb/error/four_args.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
a {b: color.hwb("foo", 30%, 40%, 0.5)}

<===> hue/type/error
Error: Expected hue "foo" to be a number.
Error: Expected hue channel to be a number, was "foo".
,
2 | a {b: color.hwb("foo", 30%, 40%, 0.5)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -36,7 +36,7 @@ Error: $hue: var(--c) is not a number.
a {b: color.hwb(0, "foo", 40%, 0.5)}

<===> whiteness/type/error
Error: Expected whiteness "foo" to be a number.
Error: Expected whiteness channel to be a number, was "foo".
,
2 | a {b: color.hwb(0, "foo", 40%, 0.5)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -135,7 +135,7 @@ Error: $whiteness: var(--c) is not a number.
a {b: color.hwb(0, 30%, "foo", 0.5)}

<===> blackness/type/error
Error: Expected blackness "foo" to be a number.
Error: Expected blackness channel to be a number, was "foo".
,
2 | a {b: color.hwb(0, 30%, "foo", 0.5)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions spec/core_functions/color/hwb/error/one_arg.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Error: $channels: The hwb color space has 3 channels but (0 30% 40% 0.4) has 4.
a {b: color.hwb("foo" 30% 40%)}

<===> hue/type/error
Error: $channels: Expected hue "foo" to be a number.
Error: $channels: Expected hue channel to be a number, was "foo".
,
2 | a {b: color.hwb("foo" 30% 40%)}
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -120,7 +120,7 @@ Error: $hue: var(--c) is not a number.
a {b: color.hwb(0 "foo" 40%)}

<===> whiteness/type/error
Error: $channels: Expected whiteness "foo" to be a number.
Error: $channels: Expected whiteness channel to be a number, was "foo".
,
2 | a {b: color.hwb(0 "foo" 40%)}
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -219,7 +219,7 @@ Error: $whiteness: var(--c) is not a number.
a {b: color.hwb(0 30% "foo")}

<===> blackness/type/error
Error: $channels: Expected blackness "foo" to be a number.
Error: $channels: Expected blackness channel to be a number, was "foo".
,
2 | a {b: color.hwb(0 30% "foo")}
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -367,7 +367,7 @@ Error: Expected numeric channels, got "hwb(0 0 0/var(--c))".
a {b: color.hwb(0 30% "var(--foo) / 0.4")}

<===> quoted_var_slash/error
Error: $channels: Expected blackness "var(--foo) / 0.4" to be a number.
Error: $channels: Expected blackness channel to be a number, was "var(--foo) / 0.4".
,
2 | a {b: color.hwb(0 30% "var(--foo) / 0.4")}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions spec/core_functions/color/hwb/error/three_args.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
a {b: color.hwb("foo", 100%, 50%)}

<===> hue/type/error
Error: Expected hue "foo" to be a number.
Error: Expected hue channel to be a number, was "foo".
,
2 | a {b: color.hwb("foo", 100%, 50%)}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -25,7 +25,7 @@ Error: argument `$hue` of `hwb($hue, $whiteness, $blackness)` must be a number
a {b: color.hwb(0, "foo", 50%)}

<===> whiteness/type/error
Error: Expected whiteness "foo" to be a number.
Error: Expected whiteness channel to be a number, was "foo".
,
2 | a {b: color.hwb(0, "foo", 50%)}
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -47,7 +47,7 @@ Error: argument `$whiteness` of `hwb($hue, $whiteness, $blackness)` must be a nu
a {b: color.hwb(0, 100%, "foo")}

<===> blackness/type/error
Error: Expected blackness "foo" to be a number.
Error: Expected blackness channel to be a number, was "foo".
,
2 | a {b: color.hwb(0, 100%, "foo")}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions spec/core_functions/color/lab/error.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Error: $alpha: Expected 0.4px to have unit "%" or no units.
a {b: lab(c 2 3)}

<===> type/lightness/error
Error: $channels: Expected lightness c to be a number.
Error: $channels: Expected lightness channel to be a number, was c.
,
1 | a {b: lab(c 2 3)}
| ^^^^^^^^^^
Expand All @@ -81,7 +81,7 @@ Error: $channels: Expected lightness c to be a number.
a {b: lab(1% c 3)}

<===> type/a/error
Error: $channels: Expected a c to be a number.
Error: $channels: Expected a channel to be a number, was c.
,
1 | a {b: lab(1% c 3)}
| ^^^^^^^^^^^
Expand All @@ -94,7 +94,7 @@ Error: $channels: Expected a c to be a number.
a {b: lab(1% 2 c)}

<===> type/b/error
Error: $channels: Expected b c to be a number.
Error: $channels: Expected b channel to be a number, was c.
,
1 | a {b: lab(1% 2 c)}
| ^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions spec/core_functions/color/oklab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Some of the same behavior tested for `lab()` applies to this function as well,
but for terseness' sake isn't tested explicitly.
27 changes: 27 additions & 0 deletions spec/core_functions/color/oklab/_utils.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@use 'sass:color';
@use 'sass:list';
@use 'sass:meta';

@function -real-channel($color, $channel) {
@if color.is-missing($color, $channel) {
@return none;
} @else {
@return color.channel($color, $channel);
}
}

@mixin inspect($color) {
a {
value: $color;
@if meta.type-of($color) == string {
type: string;
} @else {
channels: list.slash(
-real-channel($color, 'lightness')
-real-channel($color, 'a')
-real-channel($color, 'b'),
-real-channel($color, 'alpha')
);
}
}
}
120 changes: 120 additions & 0 deletions spec/core_functions/color/oklab/alpha.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<===> transparent/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(0 255 127 / 0));

<===> transparent/output.css
a {
value: oklab(0% 255 127 / 0);
channels: 0% 255 127 / 0;
}

<===>
================================================================================
<===> opaque/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(1% 2 3 / 1));

<===> opaque/output.css
a {
value: oklab(1% 2 3);
channels: 1% 2 3 / 1;
}

<===>
================================================================================
<===> partial/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(1% 2 3 / 0.4));

<===> partial/output.css
a {
value: oklab(1% 2 3 / 0.4);
channels: 1% 2 3 / 0.4;
}

<===>
================================================================================
<===> percent/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(1% 2 3 / 40%));

<===> percent/output.css
a {
value: oklab(1% 2 3 / 0.4);
channels: 1% 2 3 / 0.4;
}

<===>
================================================================================
<===> named/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab($channels: 1% 2 3 / 0.4));

<===> named/output.css
a {
value: oklab(1% 2 3 / 0.4);
channels: 1% 2 3 / 0.4;
}

<===>
================================================================================
<===> slash_list/input.scss
@use "sass:list";
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(list.slash(1% 2 3, 0.4)));

<===> slash_list/output.css
a {
value: oklab(1% 2 3 / 0.4);
channels: 1% 2 3 / 0.4;
}

<===>
================================================================================
<===> none/slash/b/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(1% 2 none / 0.4));

<===> none/slash/b/output.css
a {
value: oklab(1% 2 none / 0.4);
channels: 1% 2 none / 0.4;
}

<===>
================================================================================
<===> none/slash/alpha/input.scss
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(1% 2 3 / none));

<===> none/slash/alpha/output.css
a {
value: oklab(1% 2 3 / none);
channels: 1% 2 3 / none;
}

<===>
================================================================================
<===> none/slash_list/b/input.scss
@use 'sass:list';
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(list.slash(1% 2 none, 0.4)));

<===> none/slash_list/b/output.css
a {
value: oklab(1% 2 none / 0.4);
channels: 1% 2 none / 0.4;
}

<===>
================================================================================
<===> none/slash_list/alpha/input.scss
@use 'sass:list';
@use 'core_functions/color/oklab/utils';
@include utils.inspect(oklab(list.slash(1% 2 3, none)));

<===> none/slash_list/alpha/output.css
a {
value: oklab(1% 2 3 / none);
channels: 1% 2 3 / none;
}
Loading

0 comments on commit a23a92f

Please sign in to comment.