@@ -30,95 +30,61 @@ tape('gamma transfer function', t => {
3030 t . end ( ) ;
3131} ) ;
3232
33- tape ( 'when mode is null and color is rgb string ' , t => {
33+ tape ( 'mode = null' , t => {
3434 let increaser = mapper ( v => v + 0.1 , null ) ;
35-
36- // might be incorrect
37- t . throws ( ( ) => {
38- increaser ( '#cc0033' ) ;
39- } , "Cannot read properties of undefined (reading 'channels')" ) ;
40- t . end ( ) ;
41- } ) ;
42-
43- tape ( 'when mode is null and color is rgb' , t => {
44- let increaser = mapper ( v => v + 0.1 , null ) ;
45- const res = increaser ( { mode : 'rgb' , r : 0.8 , g : 0 , b : 0.2 } ) ;
46-
47- // might be incorrect
48- t . equal ( res . mode , null ) ;
49- t . end ( ) ;
50- } ) ;
51-
52- tape ( 'when mode is null and preserve_mode is true' , t => {
53- let increaser = mapper ( v => v + 1 , null , true ) ;
54-
55- // might be incorrect
56- t . throws (
57- ( ) => {
58- const res = increaser ( { mode : 'rgb' , r : 0.8 , g : 0 , b : 0.2 } ) ;
59- console . log ( res ) ;
60- } ,
61- { message : "Cannot read properties of undefined (reading 'rgb')" }
35+ t . equal ( formatHex ( increaser ( '#cc0033' ) ) , '#e61a4d' , 'color is rgb string' ) ;
36+ t . equal (
37+ increaser ( { mode : 'rgb' , r : 0.8 , g : 0 , b : 0.2 } ) . mode ,
38+ 'rgb' ,
39+ 'color is rgb'
6240 ) ;
6341 t . end ( ) ;
6442} ) ;
6543
66- tape ( 'when mode is undefined and preserve_mode is true' , t => {
67- let decreaseMapper = mapper ( v => v - 0.1 , undefined , true ) ;
68- const res = decreaseMapper ( '#cc0033' ) ;
69- t . equal ( res . mode , 'rgb' ) ;
70- t . end ( ) ;
71- } ) ;
72-
73- tape ( 'when mode is hsl and preserve_mode is true' , t => {
74- let increaser = mapper ( v => v + 0.1 , 'hsl' , true ) ;
75- const res = increaser ( '#cc0033' ) ;
76- t . equal ( res . mode , 'rgb' ) ;
77- t . end ( ) ;
78- } ) ;
79-
80- tape ( 'when mode is hsl and preserve_mode is false' , t => {
81- let increaser = mapper ( v => v + 0.1 , 'hsl' , false ) ;
82- const res = increaser ( '#cc0033' ) ;
83- t . equal ( res . mode , 'hsl' ) ;
84- t . end ( ) ;
85- } ) ;
86-
87- tape ( 'when mode is oklch and preserve_mode is false' , t => {
88- let increaser = mapper ( v => v + 0.1 , 'oklch' , false ) ;
89- const res = increaser ( '#cc0033' ) ;
90- t . equal ( res . mode , 'oklch' ) ;
44+ tape ( 'preserve_mode' , t => {
45+ const rgbColor = { mode : 'rgb' , r : 0.8 , g : 0 , b : 0.2 } ;
46+ const fn = v => v + 0.1 ;
47+ t . equal (
48+ formatHex ( mapper ( fn , null , true ) ( rgbColor ) ) ,
49+ '#e61a4d' ,
50+ 'mode = null, preserve_mode = true'
51+ ) ;
52+ t . equal (
53+ mapper ( fn , undefined , true ) ( '#cc0033' ) . mode ,
54+ 'rgb' ,
55+ 'mode = undefined, preserve_mode = true'
56+ ) ;
57+ t . equal (
58+ mapper ( fn , 'hsl' , true ) ( '#cc0033' ) . mode ,
59+ 'rgb' ,
60+ 'mode = hsl, preserve_mode = true'
61+ ) ;
62+ t . equal (
63+ mapper ( fn , 'hsl' , false ) ( '#cc0033' ) . mode ,
64+ 'hsl' ,
65+ 'mode = hsl, preserve_mode = false'
66+ ) ;
67+ t . equal (
68+ mapper ( fn , 'oklch' , false ) ( '#cc0033' ) . mode ,
69+ 'oklch' ,
70+ 'mode = oklch, preserve_mode = false'
71+ ) ;
72+ const oklchColor = {
73+ mode : 'oklch' ,
74+ alpha : 0.25 ,
75+ l : 30 ,
76+ c : 0.5 ,
77+ h : 1
78+ } ;
79+ t . equal (
80+ mapper ( fn , 'hsl' , false ) ( oklchColor ) . mode ,
81+ 'hsl' ,
82+ 'oklch color, mode = hsl, preserve_mode = false'
83+ ) ;
84+ t . equal (
85+ mapper ( fn , 'hsl' , true ) ( oklchColor ) . mode ,
86+ 'oklch' ,
87+ 'oklch color, mode = hsl, preserve_mode = true'
88+ ) ;
9189 t . end ( ) ;
9290} ) ;
93-
94- tape (
95- `when input color is oklch('color(--oklch 30 0.5 1 / 0.25)') and when mode is hsl and preserve_mode is false` ,
96- t => {
97- let increaser = mapper ( v => v + 0.1 , 'hsl' , false ) ;
98- const res = increaser ( {
99- mode : 'oklch' ,
100- alpha : 0.25 ,
101- l : 30 ,
102- c : 0.5 ,
103- h : 1
104- } ) ;
105- t . equal ( res . mode , 'hsl' ) ;
106- t . end ( ) ;
107- }
108- ) ;
109-
110- tape (
111- `when input color is oklch('color(--oklch 30 0.5 1 / 0.25)') and when mode is hsl and preserve_mode is true` ,
112- t => {
113- let increaser = mapper ( v => v + 0.1 , 'hsl' , true ) ;
114- const res = increaser ( {
115- mode : 'oklch' ,
116- alpha : 0.25 ,
117- l : 30 ,
118- c : 0.5 ,
119- h : 1
120- } ) ;
121- t . equal ( res . mode , 'oklch' ) ;
122- t . end ( ) ;
123- }
124- ) ;
0 commit comments