@@ -274,88 +274,94 @@ describe("string representation methods", () => {
274274describe("color modification tests" , () => {
275275 let red = TinyColor . makeFromString("red" );
276276
277- test("lighten(int, t)" , () => {
278- let a = TinyColor . lighten(~value= 10 , red);
279- expect(Option . map(a, TinyColor . toHexString))
280- |> toEqual(Some ("#ff3333" ));
281- });
277+ let optionMapTwo = (color, fn1, fn2) =>
278+ Option . flatMap(color, fn1)-> Option . map(fn2);
282279
283- test("lighten(int, t) does not change original instance" , () => {
284- let a = TinyColor . lighten(~value= 10 , red);
280+ test("lighten(int, t)" , () =>
281+ optionMapTwo(red, TinyColor . lighten(~value= 10 ), TinyColor . toHexString)
282+ |> expect
283+ |> toEqual(Some ("#ff3333" ))
284+ );
285285
286- expect(Option . map(a, TinyColor . toHex8String))
286+ test("lighten(int, t) does not change original instance" , () =>
287+ optionMapTwo(red, TinyColor . lighten(~value= 10 ), TinyColor . toHex8String)
288+ |> expect
287289 |> not
288- |> toEqual(Option . map(red, TinyColor . toHex8String));
289- });
290-
291- test("brighten(int, t)" , () => {
292- let a = TinyColor . brighten(~value= 10 , red);
293- expect(Option . map(a, TinyColor . toHexString))
294- |> toEqual(Some ("#ff1919" ));
295- });
290+ |> toEqual(Option . map(red, TinyColor . toHex8String))
291+ );
296292
297- test("brighten(int, t) dose not change original instance" , () => {
298- let a = TinyColor . brighten(~value= 10 , red);
293+ test("brighten(int, t)" , () =>
294+ optionMapTwo(red, TinyColor . brighten(~value= 10 ), TinyColor . toHexString)
295+ |> expect
296+ |> toEqual(Some ("#ff1919" ))
297+ );
299298
300- expect(Option . map(a, TinyColor . toString))
299+ test("brighten(int, t) dose not change original instance" , () =>
300+ optionMapTwo(red, TinyColor . brighten(~value= 10 ), TinyColor . toString)
301+ |> expect
301302 |> not
302- |> toEqual(Option . map(red, TinyColor . toString));
303- } );
303+ |> toEqual(Option . map(red, TinyColor . toString))
304+ );
304305
305- test("darken(int, t)" , () => {
306- let a = TinyColor . darken(~value= 10 , red) ;
307- expect( Option . map(a , TinyColor . toHexString))
308- |> toEqual(Some ("#cc0000" ));
309- } );
306+ test("darken(int, t)" , () =>
307+ optionMapTwo(red , TinyColor . darken(~value= 10 ) , TinyColor . toHexString)
308+ |> expect
309+ |> toEqual(Some ("#cc0000" ))
310+ );
310311
311- test("tint(int, t)" , () => {
312- let a = TinyColor . tint(~value= 10 , red) ;
313- expect( Option . map(a , TinyColor . toHexString))
314- |> toEqual(Some ("#ff1a1a" ));
315- } );
312+ test("tint(int, t)" , () =>
313+ optionMapTwo(red , TinyColor . tint(~value= 10 ) , TinyColor . toHexString)
314+ |> expect
315+ |> toEqual(Some ("#ff1a1a" ))
316+ );
316317
317- test("shade(int, t)" , () => {
318- let a = TinyColor . shade(~value= 10 , red) ;
319- expect( Option . map(a , TinyColor . toHexString))
320- |> toEqual(Some ("#e60000" ));
321- } );
318+ test("shade(int, t)" , () =>
319+ optionMapTwo(red , TinyColor . shade(~value= 10 ) , TinyColor . toHexString)
320+ |> expect
321+ |> toEqual(Some ("#e60000" ))
322+ );
322323
323- test("desaturate(int, t)" , () => {
324- let a = TinyColor . desaturate(~value= 10 , red) ;
325- expect( Option . map(a , TinyColor . toHexString))
326- |> toEqual(Some ("#f20d0d" ));
327- } );
324+ test("desaturate(int, t)" , () =>
325+ optionMapTwo(red , TinyColor . desaturate(~value= 10 ) , TinyColor . toHexString)
326+ |> expect
327+ |> toEqual(Some ("#f20d0d" ))
328+ );
328329
329- test("saturate(int, t)" , () => {
330- let a = TinyColor . saturate(~value= 10 , red) ;
331- expect( Option . map(a , TinyColor . toHexString))
332- |> toEqual(Some ("#ff0000" ));
333- } );
330+ test("saturate(int, t)" , () =>
331+ optionMapTwo(red , TinyColor . saturate(~value= 10 ) , TinyColor . toHexString)
332+ |> expect
333+ |> toEqual(Some ("#ff0000" ))
334+ );
334335
335- test("spin(int, t)" , () => {
336- let a = TinyColor . spin(~value= 180 , red);
337- expect(Option . map(a, TinyColor . toHex8String)) === Some ("#00ffffff" );
338- });
336+ test("spin(int, t)" , () =>
337+ Option . map(red, TinyColor . spin(~value= 180 ))
338+ -> Option . map(TinyColor . toHex8String)
339+ |> expect === Some ("#00ffffff" )
340+ );
339341
340- test("spin(int, t) with value 360 does not change" , () => {
341- let a = TinyColor . spin(~value= 360 , red) ;
342- expect( Option . map(a , TinyColor . toHex8String) )
343- === Option . map(red, TinyColor . toHex8String);
344- } );
342+ test("spin(int, t) with value 360 does not change" , () =>
343+ Option . map(red , TinyColor . spin(~value= 360 ))
344+ -> Option . map(TinyColor . toHex8String)
345+ |> expect === Option . map(red, TinyColor . toHex8String)
346+ );
345347
346348 test("mix(int, t)" , () => {
347349 let color1 = TinyColor . makeFromString("#f0f" );
348350 let color2 = TinyColor . makeFromString("#0f0" );
349351
350- let a = TinyColor . mix(~value= 50 , color1, color2);
351- expect(Option . map(a, TinyColor . toHexString))
352- |> toEqual(Some ("#808080" ));
352+ switch (color1, color2) {
353+ | (Some (c1 ), Some (c2 )) =>
354+ TinyColor . mix(~value= 50 , c1, c2)-> Option . map(TinyColor . toHexString)
355+ |> expect
356+ |> toEqual(Some ("#808080" ))
357+ | _ => expect(false ) === true
358+ };
353359 });
354360
355- test("greyscale(t)" , () => {
356- let a = TinyColor . greyscale(red) ;
357- expect( Option . map(a , TinyColor . toHex8String)) === Some ("#808080ff" );
358- } );
361+ test("greyscale(t)" , () =>
362+ Option . map(red , TinyColor . greyscale) -> Option . map( TinyColor . toHex8String)
363+ |> expect === Some ("#808080ff" )
364+ );
359365});
360366
361367describe("color combinations" , () => {
0 commit comments