Skip to content

Commit 22c29d1

Browse files
committed
feat: add unit test for GradientParser.processColorStops
1 parent 152d947 commit 22c29d1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

packages/vrender-core/src/common/color-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ export class GradientParser {
371371
}
372372
return c;
373373
}
374-
private static processColorStops(colorStops: any[]): { color: string; offset: number }[] {
374+
static processColorStops(
375+
colorStops: Array<{ value: string; length?: { value: string } }>
376+
): { color: string; offset: number }[] {
375377
if (!colorStops || colorStops.length === 0) {
376378
return [];
377379
}

packages/vrender-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export * from './factory';
2121

2222
/* export common */
2323
export * from './common/text';
24+
export * from './common/color-utils';
2425
export * from './common/bezier-utils';
2526
export * from './common/bounds-context';
2627
export * from './common/seg-context';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { GradientParser } from '../../src/index';
2+
3+
it('gradient-color', () => {
4+
expect(GradientParser.processColorStops([{ value: 'rgb(100, 0, 0)' }, { value: 'rgb(0, 100, 0)' }])).toEqual([
5+
{ color: 'rgb(100, 0, 0)', offset: 0 },
6+
{ color: 'rgb(0, 100, 0)', offset: 1 }
7+
]);
8+
expect(
9+
GradientParser.processColorStops([
10+
{ value: 'rgb(100, 0, 0)', length: { value: '0' } },
11+
{ value: 'rgb(0, 100, 0)', length: { value: '100' } }
12+
])
13+
).toEqual([
14+
{ color: 'rgb(100, 0, 0)', offset: 0 },
15+
{ color: 'rgb(0, 100, 0)', offset: 1 }
16+
]);
17+
expect(
18+
GradientParser.processColorStops([
19+
{ value: 'rgb(100, 0, 0)', length: { value: '0' } },
20+
{ value: 'rgb(0, 0, 100)', length: { value: '30' } },
21+
{ value: 'rgb(0, 100, 0)', length: { value: '100' } }
22+
])
23+
).toEqual([
24+
{ color: 'rgb(100, 0, 0)', offset: 0 },
25+
{ color: 'rgb(0, 0, 100)', offset: 0.3 },
26+
{ color: 'rgb(0, 100, 0)', offset: 1 }
27+
]);
28+
});

0 commit comments

Comments
 (0)