-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): add alpha support for color decompose tests
Updated the decompose color tests to handle alpha values for HEX and HSL color formats. Also, parser functions have been updated to handle alpha values correctly during color decomposition. Additional tests for RGBA have been added to verify this functionality.
- Loading branch information
1 parent
2c6b7eb
commit efb4c15
Showing
2 changed files
with
37 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,48 @@ | ||
import { decomposeColor } from '@/parser/decomposeColor'; | ||
|
||
describe('decomposeColor', () => { | ||
test('converts hex to rgb', () => { | ||
test('decomposes HEX color', () => { | ||
expect(decomposeColor('#ff0000')).toEqual({ r: 255, g: 0, b: 0 }); | ||
expect(decomposeColor('#00ff00')).toEqual({ r: 0, g: 255, b: 0 }); | ||
}); | ||
|
||
test('converts hsl to rgb', () => { | ||
test('decomposes HEX-ALPHA color', () => { | ||
expect(decomposeColor('#ff000080')).toEqual({ r: 255, g: 0, b: 0, a: 0.502 }); | ||
}); | ||
|
||
test('decomposes HSL color', () => { | ||
expect(decomposeColor('hsl(0, 100%, 50%)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
expect(decomposeColor('hsl(120, 100%, 50%)')).toEqual({ r: 0, g: 255, b: 0 }); | ||
}); | ||
|
||
test('converts lab to rgb', () => { | ||
expect(decomposeColor('lab(53.23 80.09 67.2)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
test('decomposes HSLA color', () => { | ||
expect(decomposeColor('hsla(0, 100%, 50%, 0.5)')).toEqual({ r: 255, g: 0, b: 0, a: 0.5 }); | ||
}); | ||
|
||
test('converts lch to rgb', () => { | ||
expect(decomposeColor('lch(53.23 104.55 40.00)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
test('decomposes LAB color', () => { | ||
expect(decomposeColor('lab(53.23288 80.10933 67.2201)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
}); | ||
|
||
test('converts xyz to rgb', () => { | ||
test('decomposes LCH color', () => { | ||
expect(decomposeColor('lch(53.23288 104.551 40.0)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
}); | ||
|
||
test('decomposes XYZ color', () => { | ||
expect(decomposeColor('xyz(41.24, 21.26, 1.93)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
}); | ||
|
||
test('converts named color to rgb', () => { | ||
test('decomposes RGB color', () => { | ||
expect(decomposeColor('rgb(255, 0, 0)')).toEqual({ r: 255, g: 0, b: 0 }); | ||
}); | ||
|
||
test('decomposes RGBA color', () => { | ||
expect(decomposeColor('rgba(255, 0, 0, 0.5)')).toEqual({ r: 255, g: 0, b: 0, a: 0.5 }); | ||
}); | ||
|
||
test('decomposes named color', () => { | ||
expect(decomposeColor('red')).toEqual({ r: 255, g: 0, b: 0 }); | ||
}); | ||
|
||
test('throws error for invalid color format', () => { | ||
expect(() => decomposeColor('invalid-color')).toThrow('Invalid color format invalid-color'); | ||
}); | ||
}); | ||
|