-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathxyb.test.js
63 lines (57 loc) · 1.43 KB
/
xyb.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import test from 'node:test';
import assert from 'node:assert';
import { xyb, rgb, formatRgb, formatCss } from '../src/index.js';
test('rgb -> xyb', t => {
assert.deepEqual(xyb('purple'), {
mode: 'xyb',
x: 0.013838974535428816,
y: 0.27055837298918495,
b: 0.1333134464452821
});
});
test('rgb -> xyb -> rgb', t => {
assert.deepEqual(
formatRgb(xyb('rgb(255, 255, 255)')),
'rgb(255, 255, 255)',
'white'
);
assert.deepEqual(formatRgb(xyb('rgb(0, 0, 0)')), 'rgb(0, 0, 0)', 'black');
assert.deepEqual(formatRgb(xyb('rgb(100, 0, 0)')), 'rgb(100, 0, 0)', 'red');
assert.deepEqual(
formatRgb(xyb('rgb(0, 120, 0)')),
'rgb(0, 120, 0)',
'blue'
);
assert.deepEqual(formatRgb(xyb('rgb(0, 0, 89)')), 'rgb(0, 0, 89)', 'green');
});
test('color(--xyb)', t => {
assert.deepEqual(xyb('color(--xyb 1 0 0 / 0.25)'), {
x: 1,
y: 0,
b: 0,
alpha: 0.25,
mode: 'xyb'
});
assert.deepEqual(xyb('color(--xyb 0% 50% 0.5 / 25%)'), {
x: 0,
y: 0.5,
b: 0.5,
alpha: 0.25,
mode: 'xyb'
});
});
test('formatCss', t => {
assert.equal(
formatCss('color(--xyb 0% 50% 0.5 / 25%)'),
'color(--xyb 0 0.5 0.5 / 0.25)'
);
});
test('missing components', t => {
assert.ok(rgb('color(--xyb none 0.5 none)'), 'xyb to rgb is ok');
assert.deepEqual(
rgb('color(--xyb none 0.5 none)'),
rgb('color(--xyb 0 0.5 0')
);
assert.ok(xyb('rgb(none 100 20)'), 'rgb to xyb is ok');
assert.deepEqual(xyb('rgb(none 100 20)'), xyb('rgb(0 100 20)'));
});