From 797bb553284013f127e1f58fa027e76fab40144a Mon Sep 17 00:00:00 2001 From: Aleksandra Cynk Date: Wed, 22 May 2024 13:20:45 +0200 Subject: [PATCH] Delete old color tests --- __tests__/convertColors.test.tsx | 175 ------------- __tests__/normalizeColor.test.tsx | 315 +++++++++++++++++++++++ src/reanimated2/__tests__/Colors.test.ts | 145 ----------- 3 files changed, 315 insertions(+), 320 deletions(-) delete mode 100644 __tests__/convertColors.test.tsx create mode 100644 __tests__/normalizeColor.test.tsx delete mode 100644 src/reanimated2/__tests__/Colors.test.ts diff --git a/__tests__/convertColors.test.tsx b/__tests__/convertColors.test.tsx deleted file mode 100644 index 0c15cf9cbf5..00000000000 --- a/__tests__/convertColors.test.tsx +++ /dev/null @@ -1,175 +0,0 @@ -import { normalizeColor } from '../src/reanimated2/Colors'; - -describe('Test `normalizeColor` function', () => { - describe('Test colors being an invalid type ', () => { - test.each([ - [null, null], - [undefined, null], - [[12, 34, 56], null], - [{ r: 12, g: 55, b: 156 }, null], - ])('normalizeColor(%p) = null', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a number ', () => { - test.each([ - [0x1, 0x1], - [0x12, 0x12], - [0x123, 0x123], - [0x1234, 0x1234], - [0x12345, 0x12345], - [0x123456, 0x123456], - [0x1234567, 0x1234567], - [0x12345678, 0x12345678], - [0x123456789, null], - [11, 11], - [158, 158], - [300.78, null], - [-300, null], - [0, 0], - [NaN, null], - [Infinity, null], - [-Infinity, null], - ])('normalizeColor(%d) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a number as string', () => { - test.each([ - ['0x1', null], - ['0x12', null], - ['0x123', null], - ['0x1234', null], - ['0x12345', null], - ['0x123456', null], - ['0x1234567', null], - ['0x12345678', null], - ['0x123456789', null], - ['11', null], - ['158', null], - ['300.78', null], - ['-300', null], - ['0', null], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a hex string', () => { - test.each([ - ['#123', 0x112233ff], - ['#1234', 0x11223344], - ['#12345', null], - ['#123456', 0x123456ff], - ['#1234567', null], - ['#12345678', 0x12345678], - ['#abc', 0xaabbccff], - ['#abcd', 0xaabbccdd], - ['#abcde', null], - ['#abcdef', 0xabcdefff], - ['#abcdeff', null], - ['#abcdefff', 0xabcdefff], - ['#abcdef32', 0xabcdef32], - ['#ABC', 0xaabbccff], - ['#ABCD', 0xaabbccdd], - ['#abcde', null], - ['#ABCDEF', 0xabcdefff], - ['#abcdeff', null], - ['#ABCDEFFF', 0xabcdefff], - ['#AbC', 0xaabbccff], - ['#AbcD', 0xaabbccdd], - ['#abcde', null], - ['#AbCdEf', 0xabcdefff], - ['#abcdeff', null], - ['#AbcDEfFF', 0xabcdefff], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - describe('Test colors being a rgb string', () => { - // HEX 65 = DEC 101 - // HEX 64 = DEC 100 - // HEX 63 = DEC 99 - - test.each([ - ['rgb (0,0,0)', null], - ['rgb(50,200,150, 45)', null], - ['RGB(50,200,150)', null], - ['rgb(50,200,150, 0.45)', null], - - ['rgb(0,0,0)', 0x000000ff], - ['rgb(0 ,0 ,0 )', 0x000000ff], - ['rgb( 0,0,0 )', 0x000000ff], - ['rgb(101,255,50)', 0x65ff32ff], - ['rgb(100.99999,255,50)', 0x64ff32ff], // Should be 0x65ff00ff - ['rgb(100.75,255,50)', 0x64ff32ff], // Should be 0x65ff00ff - ['rgb(100.5,255,50)', 0x64ff32ff], // Should be 0x65ff00ff - ['rgb(100.25,255,50)', 0x64ff32ff], - ['rgb(100,255,50)', 0x64ff32ff], - ['rgb(99,255,50)', 0x63ff32ff], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a rgba string', () => { - test.each([ - ['RGBA(100 ,255 ,50 ,50 )', null], - ['rgba (100,255,50,.5)', null], - [' rgba(100,255,50, 50)', 0x64ff32ff], - ['rgba(100 ,255 ,50 ,50 )', 0x64ff32ff], - ['rgba(100,255,50,0.5)', 0x64ff3280], - ['rgba(100,255,50,.5)', 0x64ff3280], - ['rgba(50,50,50,.5)', 0x32323280], - ['rgba(50,50,50,1)', 0x323232ff], - ['rgba(50,50,50,0)', 0x32323200], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a hsl string', () => { - test.each([ - ['HSL(0,100%,50%)', null], - ['hsl(120 ,0.99, 0.1 )', null], - ['hsl(0,100,50)', null], - ['hsl(0,100%,50%, 0.5)', null], - ['hsl(0,100%,50%)', 0xff0000ff], - ['hsl(0,100%,50%)', 0xff0000ff], - ['hsl(120,100%,50%)', 0x00ff00ff], - ['hsl(120.5,100%,50%)', 0x00ff02ff], - ['hsl(120.999,100%,50%)', 0x00ff04ff], - ['hsl(120,50%,50%)', 0x40bf40ff], - ['hsl(120 ,50%, 50% )', 0x40bf40ff], - ['hsl(130 ,13.33%, 100% )', 0xffffffff], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a hsla string', () => { - test.each([ - ['HSLA(0,100%,50%,0.5)', null], - ['hsla(0,100%,50%,0.5)', 0xff000080], - ['hsla(120,100%,50%, 0.5)', 0x00ff0080], - ['hsla(120,100%,50%, 1)', 0x00ff00ff], - ['hsla(120,100%,50%, 0)', 0x00ff0000], - [' hsla( 120 , 100% , 50%, 0.5 ) ', 0x00ff0080], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); - - describe('Test colors being a hwb string', () => { - test.each([ - ['HWB(0,100%,50%)', null], - ['hwb(0,67%, 33%)', 0xabababff], - ['hwb(0,67% , 33%)', 0xabababff], - ['hwb(48, 38%, 6%)', 0xf0d361ff], - ])('normalizeColor(%s) = %p', (color, expectedColor) => { - expect(normalizeColor(color)).toBe(expectedColor); - }); - }); -}); diff --git a/__tests__/normalizeColor.test.tsx b/__tests__/normalizeColor.test.tsx new file mode 100644 index 00000000000..b41a377b8de --- /dev/null +++ b/__tests__/normalizeColor.test.tsx @@ -0,0 +1,315 @@ +import { normalizeColor } from '../src/reanimated2/Colors'; + +describe('Test `normalizeColor` function', () => { + describe('Only compliant color are accepted', () => { + test('test invalid colors', () => { + [ + null, + undefined, + [12, 34, 56], + { r: 12, g: 55, b: 156 }, + 0x01234567 + 0.5, + -1, + 0xffffffff + 1, + '#00gg00', + 'rgb(1, 2, 3,)', + 'rgb(1, 2, 3', + ].forEach((color) => { + expect(normalizeColor(color)).toBe(null); + }); + }); + + test('test invalid colors (format was previously accepted)', () => { + [ + 'abc', + ' #abc ', + '##abc', + 'rgb 255 0 0', + 'RGBA(0, 1, 2)', + 'rgb (0, 1, 2)', + 'rgba(0 0 0 0.0)', + 'hsv(0, 1, 2)', + { r: 10, g: 10, b: 10 }, + 'hsl(1%, 2, 3)', + 'rg b( 1%, 2%, 3%)', + ].forEach((color) => { + expect(normalizeColor(color)).toBe(null); + }); + }); + + test('test valid colors', () => { + [ + '#abc', + '#abcd', + '#abcdef', + '#abcdef01', + 'rgb(1,2,3)', + 'rgb(100 200 3)', + 'rgb(1, 2, 3)', + 'rgb( 1 , 2 , 3 )', + 'rgb(-1, -2, -3)', + 'rgba(0, 0, 0, 1)', + ].forEach((color) => { + expect(normalizeColor(color)).not.toBe(null); + }); + }); + }); + + describe('Test colors being a number ', () => { + test.each([ + [0x1, 0x1], + [0x12, 0x12], + [0x123, 0x123], + [0x1234, 0x1234], + [0x12345, 0x12345], + [0x123456, 0x123456], + [0x1234567, 0x1234567], + [0x12345678, 0x12345678], + [0x123456789, null], + [11, 11], + [158, 158], + [300.78, null], + [-300, null], + [0, 0], + [NaN, null], + [Infinity, null], + [-Infinity, null], + ])('normalizeColor(%d) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors being a number as string', () => { + test.each([ + ['0x1', null], + ['0x12', null], + ['0x123', null], + ['0x1234', null], + ['0x12345', null], + ['0x123456', null], + ['0x1234567', null], + ['0x12345678', null], + ['0x123456789', null], + ['11', null], + ['158', null], + ['300.78', null], + ['-300', null], + ['0', null], + ])('normalizeColor("%s") = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors being a hex string', () => { + describe('Test hex3', () => { + test.each([ + ['#123', 0x112233ff], + ['#abc', 0xaabbccff], + ['#ABC', 0xaabbccff], + ['#AbC', 0xaabbccff], + ['#000', 0x000000ff], + ['#fff', 0xffffffff], + ['#f0f', 0xff00ffff], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test hex4', () => { + test.each([ + ['#1234', 0x11223344], + ['#abcd', 0xaabbccdd], + ['#ABCD', 0xaabbccdd], + ['#AbcD', 0xaabbccdd], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test hex6', () => { + test.each([ + ['#000000', 0x000000ff], + ['#ffffff', 0xffffffff], + ['#ff00ff', 0xff00ffff], + ['#abcdef', 0xabcdefff], + ['#012345', 0x012345ff], + ['#123456', 0x123456ff], + ['#abcdef', 0xabcdefff], + ['#ABCDEF', 0xabcdefff], + ['#AbCdEf', 0xabcdefff], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test hex8', () => { + test.each([ + ['#00000000', 0x00000000], + ['#ffffffff', 0xffffffff], + ['#ffff00ff', 0xffff00ff], + ['#abcdef01', 0xabcdef01], + ['#01234567', 0x01234567], + ['#12345678', 0x12345678], + ['#abcdefff', 0xabcdefff], + ['#ABCDEFFF', 0xabcdefff], + ['#AbcDEfFF', 0xabcdefff], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test invalid hex', () => { + test.each([ + ['#12345', null], + ['#12345g', null], + ['#1234567', null], + ['#abcde', null], + ['#abcdeff', null], + ['#abcde', null], + ['#abcdeff', null], + ['#abcde', null], + ['#abcdeff', null], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + }); + describe('Test colors being a rgb string', () => { + test.each([ + ['rgb (0,0,0)', null], + ['rgb(50,200,150, 45)', null], + ['RGB(50,200,150)', null], + ['rgb(50,200,150, 0.45)', null], + ['rgb(0, 0, 255)', 0x0000ffff], + ['rgb(0 0 255)', 0x0000ffff], + ['rgb(100, 15, 69)', 0x640f45ff], + ['rgb(255, 255, 255)', 0xffffffff], + ['rgb(256, 256, 256)', 0xffffffff], + ['rgb(-1, -2, -3)', 0x000000ff], + ['rgb(0, 0, 0)', 0x000000ff], + ['rgb(0 0 0)', 0x000000ff], + ['rgb(0,0,0)', 0x000000ff], + ['rgb(0 ,0 ,0 )', 0x000000ff], + ['rgb( 0,0,0 )', 0x000000ff], + ['rgb(101,255,50)', 0x65ff32ff], + ['rgb(100.99999,255,50)', 0x64ff32ff], + ['rgb(100.75,255,50)', 0x64ff32ff], + ['rgb(100.5,255,50)', 0x64ff32ff], + ['rgb(100.25,255,50)', 0x64ff32ff], + ['rgb(100,255,50)', 0x64ff32ff], + ['rgb(99,255,50)', 0x63ff32ff], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors being a rgba string', () => { + test.each([ + ['RGBA(100 ,255 ,50 ,50 )', null], + ['rgba (100,255,50,.5)', null], + ['rgba(0, 0, 0, .5)', 0x00000080], + ['rgba(0, 0, 0, 0.0)', 0x00000000], + ['rgba(0, 0, 0, 0)', 0x00000000], + ['rgba(0, 0, 0, -0.5)', 0x00000000], + ['rgba(0, 0, 0, 1.0)', 0x000000ff], + ['rgba(0, 0, 0, 1)', 0x000000ff], + ['rgba(0, 0, 0, 1.5)', 0x000000ff], + ['rgba(0 0 0 / 0.0)', 0x00000000], + ['rgba(0 0 0 / 1)', 0x000000ff], + ['rgba(100, 15, 69, 0.5)', 0x640f4580], + ['rgba(100 15 69 / 0.5)', 0x640f4580], + [' rgba(100,255,50, 50)', 0x64ff32ff], + ['rgba(100 ,255 ,50 ,50 )', 0x64ff32ff], + ['rgba(100,255,50,0.5)', 0x64ff3280], + ['rgba(100,255,50,.5)', 0x64ff3280], + ['rgba(50,50,50,.5)', 0x32323280], + ['rgba(50,50,50,1)', 0x323232ff], + ['rgba(50,50,50,0)', 0x32323200], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors being a hsl string', () => { + test.each([ + ['HSL(0,100%,50%)', null], + ['hsl(120 ,0.99, 0.1 )', null], + ['hsl(0,100,50)', null], + ['hsl(0,100%,50%, 0.5)', null], + ['hsl(0, 0%, 0%)', 0x000000ff], + ['hsl(360, 100%, 100%)', 0xffffffff], + ['hsl(180, 50%, 50%)', 0x40bfbfff], + ['hsl(540, 50%, 50%)', 0x40bfbfff], + ['hsl(70, 25%, 75%)', 0xcacfafff], + ['hsl(70, 100%, 75%)', 0xeaff80ff], + ['hsl(70, 110%, 75%)', 0xeaff80ff], + ['hsl(70, 0%, 75%)', 0xbfbfbfff], + ['hsl(70, -10%, 75%)', 0xbfbfbfff], + ['hsl(0 0% 0%)', 0x000000ff], + ['hsl(360 100% 100%)', 0xffffffff], + ['hsl(180 50% 50%)', 0x40bfbfff], + ['hsl(0,100%,50%)', 0xff0000ff], + ['hsl(0,100%,50%)', 0xff0000ff], + ['hsl(120,100%,50%)', 0x00ff00ff], + ['hsl(120.5,100%,50%)', 0x00ff02ff], + ['hsl(120.999,100%,50%)', 0x00ff04ff], + ['hsl(120,50%,50%)', 0x40bf40ff], + ['hsl(120 ,50%, 50% )', 0x40bf40ff], + ['hsl(130 ,13.33%, 100% )', 0xffffffff], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors being a hsla string', () => { + test.each([ + ['hsla(0, 0%, 0%, 0)', 0x00000000], + ['hsla(360, 100%, 100%, 1)', 0xffffffff], + ['hsla(360, 100%, 100%, 0)', 0xffffff00], + ['hsla(180, 50%, 50%, 0.2)', 0x40bfbf33], + ['hsla(0 0% 0% / 0)', 0x00000000], + ['hsla(360 100% 100% / 1)', 0xffffffff], + ['hsla(360 100% 100% / 0)', 0xffffff00], + ['hsla(180 50% 50% / 0.2)', 0x40bfbf33], + ['HSLA(0,100%,50%,0.5)', null], + ['hsla(0,100%,50%,0.5)', 0xff000080], + ['hsla(120,100%,50%, 0.5)', 0x00ff0080], + ['hsla(120,100%,50%, 1)', 0x00ff00ff], + ['hsla(120,100%,50%, 0)', 0x00ff0000], + [' hsla( 120 , 100% , 50%, 0.5 ) ', 0x00ff0080], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors being a hwb string', () => { + test.each([ + ['hwb(0, 0%, 100%)', 0x000000ff], + ['hwb(0, 100%, 0%)', 0xffffffff], + ['hwb(0, 0%, 0%)', 0xff0000ff], + ['hwb(70, 50%, 0%)', 0xeaff80ff], + ['hwb(0, 50%, 50%)', 0x808080ff], + ['hwb(360, 100%, 100%)', 0x808080ff], + ['hwb(0 0% 0%)', 0xff0000ff], + ['hwb(70 50% 0%)', 0xeaff80ff], + ['HWB(0,100%,50%)', null], + ['hwb(0,67%, 33%)', 0xabababff], + ['hwb(0,67% , 33%)', 0xabababff], + ['hwb(48, 38%, 6%)', 0xf0d361ff], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); + + describe('Test colors a colorName string', () => { + test.each([ + ['red', 0xff0000ff], + ['transparent', 0x00000000], + ['peachpuff', 0xffdab9ff], + ['peachPuff', null], + ['PeachPuff', null], + ])('normalizeColor(%s) = %p', (color, expectedColor) => { + expect(normalizeColor(color)).toBe(expectedColor); + }); + }); +}); diff --git a/src/reanimated2/__tests__/Colors.test.ts b/src/reanimated2/__tests__/Colors.test.ts deleted file mode 100644 index 9ee08b667c3..00000000000 --- a/src/reanimated2/__tests__/Colors.test.ts +++ /dev/null @@ -1,145 +0,0 @@ -'use strict'; -import { normalizeColor } from '../Colors'; - -it('accepts only spec compliant colors', () => { - expect(normalizeColor('#abc')).not.toBe(null); - expect(normalizeColor('#abcd')).not.toBe(null); - expect(normalizeColor('#abcdef')).not.toBe(null); - expect(normalizeColor('#abcdef01')).not.toBe(null); - expect(normalizeColor('rgb(1,2,3)')).not.toBe(null); - expect(normalizeColor('rgb(1 2 3)')).not.toBe(null); - expect(normalizeColor('rgb(1, 2, 3)')).not.toBe(null); - expect(normalizeColor('rgb( 1 , 2 , 3 )')).not.toBe(null); - expect(normalizeColor('rgb(-1, -2, -3)')).not.toBe(null); - expect(normalizeColor('rgba(0, 0, 0, 1)')).not.toBe(null); - expect(normalizeColor(0x01234567 + 0.5)).toBe(null); - expect(normalizeColor(-1)).toBe(null); - expect(normalizeColor(0xffffffff + 1)).toBe(null); -}); - -it('temporarilys accept floating point values for rgb', () => { - expect(normalizeColor('rgb(1.1, 2.1, 3.1)')).toBe(0x010203ff); - expect(normalizeColor('rgba(1.1, 2.1, 3.1, 1.0)')).toBe(0x010203ff); -}); - -it('refuses non-spec compliant colors', () => { - expect(normalizeColor('#00gg00')).toBe(null); - expect(normalizeColor('rgb(1, 2, 3,)')).toBe(null); - expect(normalizeColor('rgb(1, 2, 3')).toBe(null); - - // Used to be accepted by normalizeColor - expect(normalizeColor('abc')).toBe(null); - expect(normalizeColor(' #abc ')).toBe(null); - expect(normalizeColor('##abc')).toBe(null); - expect(normalizeColor('rgb 255 0 0')).toBe(null); - expect(normalizeColor('RGBA(0, 1, 2)')).toBe(null); - expect(normalizeColor('rgb (0, 1, 2)')).toBe(null); - expect(normalizeColor('rgba(0 0 0 0.0)')).toBe(null); - expect(normalizeColor('hsv(0, 1, 2)')).toBe(null); - // $FlowExpectedError - Intentionally malformed argument. - expect(normalizeColor({ r: 10, g: 10, b: 10 })).toBe(null); - expect(normalizeColor('hsl(1%, 2, 3)')).toBe(null); - expect(normalizeColor('rgb(1%, 2%, 3%)')).toBe(null); -}); - -it('handles hex6 properly', () => { - expect(normalizeColor('#000000')).toBe(0x000000ff); - expect(normalizeColor('#ffffff')).toBe(0xffffffff); - expect(normalizeColor('#ff00ff')).toBe(0xff00ffff); - expect(normalizeColor('#abcdef')).toBe(0xabcdefff); - expect(normalizeColor('#012345')).toBe(0x012345ff); -}); - -it('handles hex3 properly', () => { - expect(normalizeColor('#000')).toBe(0x000000ff); - expect(normalizeColor('#fff')).toBe(0xffffffff); - expect(normalizeColor('#f0f')).toBe(0xff00ffff); -}); - -it('handles hex8 properly', () => { - expect(normalizeColor('#00000000')).toBe(0x00000000); - expect(normalizeColor('#ffffffff')).toBe(0xffffffff); - expect(normalizeColor('#ffff00ff')).toBe(0xffff00ff); - expect(normalizeColor('#abcdef01')).toBe(0xabcdef01); - expect(normalizeColor('#01234567')).toBe(0x01234567); -}); - -it('handles rgb properly', () => { - expect(normalizeColor('rgb(0, 0, 0)')).toBe(0x000000ff); - expect(normalizeColor('rgb(-1, -2, -3)')).toBe(0x000000ff); - expect(normalizeColor('rgb(0, 0, 255)')).toBe(0x0000ffff); - expect(normalizeColor('rgb(100, 15, 69)')).toBe(0x640f45ff); - expect(normalizeColor('rgb(255, 255, 255)')).toBe(0xffffffff); - expect(normalizeColor('rgb(256, 256, 256)')).toBe(0xffffffff); - expect(normalizeColor('rgb(0 0 0)')).toBe(0x000000ff); - expect(normalizeColor('rgb(0 0 255)')).toBe(0x0000ffff); -}); - -it('handles rgba properly', () => { - expect(normalizeColor('rgba(0, 0, 0, .5)')).toBe(0x00000080); - expect(normalizeColor('rgba(0, 0, 0, 0.0)')).toBe(0x00000000); - expect(normalizeColor('rgba(0, 0, 0, 0)')).toBe(0x00000000); - expect(normalizeColor('rgba(0, 0, 0, -0.5)')).toBe(0x00000000); - expect(normalizeColor('rgba(0, 0, 0, 1.0)')).toBe(0x000000ff); - expect(normalizeColor('rgba(0, 0, 0, 1)')).toBe(0x000000ff); - expect(normalizeColor('rgba(0, 0, 0, 1.5)')).toBe(0x000000ff); - expect(normalizeColor('rgba(100, 15, 69, 0.5)')).toBe(0x640f4580); - expect(normalizeColor('rgba(0 0 0 / 0.0)')).toBe(0x00000000); - expect(normalizeColor('rgba(0 0 0 / 1)')).toBe(0x000000ff); - expect(normalizeColor('rgba(100 15 69 / 0.5)')).toBe(0x640f4580); -}); - -it('handles hsl properly', () => { - expect(normalizeColor('hsl(0, 0%, 0%)')).toBe(0x000000ff); - expect(normalizeColor('hsl(360, 100%, 100%)')).toBe(0xffffffff); - expect(normalizeColor('hsl(180, 50%, 50%)')).toBe(0x40bfbfff); - expect(normalizeColor('hsl(540, 50%, 50%)')).toBe(0x40bfbfff); - expect(normalizeColor('hsl(70, 25%, 75%)')).toBe(0xcacfafff); - expect(normalizeColor('hsl(70, 100%, 75%)')).toBe(0xeaff80ff); - expect(normalizeColor('hsl(70, 110%, 75%)')).toBe(0xeaff80ff); - expect(normalizeColor('hsl(70, 0%, 75%)')).toBe(0xbfbfbfff); - expect(normalizeColor('hsl(70, -10%, 75%)')).toBe(0xbfbfbfff); - expect(normalizeColor('hsl(0 0% 0%)')).toBe(0x000000ff); - expect(normalizeColor('hsl(360 100% 100%)')).toBe(0xffffffff); - expect(normalizeColor('hsl(180 50% 50%)')).toBe(0x40bfbfff); -}); - -it('handles hsla properly', () => { - expect(normalizeColor('hsla(0, 0%, 0%, 0)')).toBe(0x00000000); - expect(normalizeColor('hsla(360, 100%, 100%, 1)')).toBe(0xffffffff); - expect(normalizeColor('hsla(360, 100%, 100%, 0)')).toBe(0xffffff00); - expect(normalizeColor('hsla(180, 50%, 50%, 0.2)')).toBe(0x40bfbf33); - expect(normalizeColor('hsla(0 0% 0% / 0)')).toBe(0x00000000); - expect(normalizeColor('hsla(360 100% 100% / 1)')).toBe(0xffffffff); - expect(normalizeColor('hsla(360 100% 100% / 0)')).toBe(0xffffff00); - expect(normalizeColor('hsla(180 50% 50% / 0.2)')).toBe(0x40bfbf33); -}); - -it('handles hwb properly', () => { - expect(normalizeColor('hwb(0, 0%, 100%)')).toBe(0x000000ff); - expect(normalizeColor('hwb(0, 100%, 0%)')).toBe(0xffffffff); - expect(normalizeColor('hwb(0, 0%, 0%)')).toBe(0xff0000ff); - expect(normalizeColor('hwb(70, 50%, 0%)')).toBe(0xeaff80ff); - expect(normalizeColor('hwb(0, 50%, 50%)')).toBe(0x808080ff); - expect(normalizeColor('hwb(360, 100%, 100%)')).toBe(0x808080ff); - expect(normalizeColor('hwb(0 0% 0%)')).toBe(0xff0000ff); - expect(normalizeColor('hwb(70 50% 0%)')).toBe(0xeaff80ff); -}); - -it('handles named colors properly', () => { - expect(normalizeColor('red')).toBe(0xff0000ff); - expect(normalizeColor('transparent')).toBe(0x00000000); - expect(normalizeColor('peachpuff')).toBe(0xffdab9ff); -}); - -it('handles number colors properly', () => { - expect(normalizeColor(0x00000000)).toBe(0x00000000); - expect(normalizeColor(0xff0000ff)).toBe(0xff0000ff); - expect(normalizeColor(0xffffffff)).toBe(0xffffffff); - expect(normalizeColor(0x01234567)).toBe(0x01234567); -}); - -it('returns the same color when it is already normalized', () => { - const normalizedColor = normalizeColor('red') || 0; - expect(normalizeColor(normalizedColor)).toBe(normalizedColor); -});