Skip to content

Commit

Permalink
[Color 4] Add tests for lab() (#1928)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Sep 28, 2023
1 parent 380093f commit b03c91e
Show file tree
Hide file tree
Showing 10 changed files with 1,373 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spec/core_functions/color/hsl/error/one_arg.hrx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Error: $channels: Expected lightness "var(--foo) / 0.4" to be a number.
a {b: hsl(append((), 0 100% 100%, $separator: slash))}

<===> slash_list/too_few_elements/error
Error: Only 2 slash-separated elements allowed, but 1 was passed.
Error: $channels: Only 2 slash-separated elements allowed, but 1 was passed.
,
1 | a {b: hsl(append((), 0 100% 100%, $separator: slash))}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -173,7 +173,7 @@ Error: Only 2 slash-separated elements allowed, but 1 was passed.
a {b: hsl(list.slash(0 100% 100%, 0.4, 1))}

<===> slash_list/too_many_elements/error
Error: Only 2 slash-separated elements allowed, but 3 were passed.
Error: $channels: Only 2 slash-separated elements allowed, but 3 were passed.
,
2 | a {b: hsl(list.slash(0 100% 100%, 0.4, 1))}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
27 changes: 27 additions & 0 deletions spec/core_functions/color/lab/_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')
);
}
}
}
145 changes: 145 additions & 0 deletions spec/core_functions/color/lab/alpha.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<===> transparent/input.scss
@use 'core_functions/color/lab/utils';
@include utils.inspect(lab(0 255 127 / 0));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit b03c91e

Please sign in to comment.