完善测试框架;新增部分测试文件
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const { parseColor } = require('./parseColor');
|
||||
|
||||
describe('parseColor', () => {
|
||||
it('should parse hex color', () => {
|
||||
expect(parseColor('#FF0000')).toEqual({ r: 255, g: 0, b: 0 });
|
||||
expect(parseColor('00FF00')).toEqual({ r: 0, g: 255, b: 0 });
|
||||
});
|
||||
|
||||
it('should parse rgb color', () => {
|
||||
expect(parseColor('rgb(0, 0, 255)')).toEqual({ r: 0, g: 0, b: 255, a: 1 });
|
||||
});
|
||||
|
||||
it('should parse rgba color', () => {
|
||||
expect(parseColor('rgba(0, 0, 255, 0.5)')).toEqual({ r: 0, g: 0, b: 255, a: 0.5 });
|
||||
});
|
||||
|
||||
it('should default alpha to 1 if not provided in rgba-like pattern', () => {
|
||||
// The regex supports optional alpha
|
||||
expect(parseColor('rgba(0, 0, 255)')).toEqual({ r: 0, g: 0, b: 255, a: 1 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user