forked from gka/chroma.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrgb2css.test.js
49 lines (44 loc) · 2.03 KB
/
rgb2css.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
const vows = require('vows')
const assert = require('assert');
require('es6-shim');
const rgb2css = require('../src/io/css/rgb2css');
const tests = {
black: { rgb: [0,0,0], css: 'rgb(0,0,0)' },
red: { rgb: [255,0,0], css: 'rgb(255,0,0)' },
auto_rgba: { rgb: [255,0,0,0.25], css: 'rgba(255,0,0,0.25)' },
force_rgba: { rgb: [255,0,0], mode:'rgba', css: 'rgba(255,0,0,1)' },
hsl: { rgb: [255,0,0], mode:'hsl', css: 'hsl(0,100%,50%)' },
auto_hsla: { rgb: [255,0,0,0.5], mode:'hsl', css: 'hsla(0,100%,50%,0.5)' },
force_hsla: { rgb: [255,255,0,0.75], mode:'hsl', css: 'hsla(60,100%,50%,0.75)' },
lab: { rgb: [255,255,0], mode:'lab', css: 'lab(97.14% -21.55% 94.48%)' },
lch: { rgb: [255,255,0], mode:'lch', css: 'lch(97.14% 96.91% 102.85)' },
oklab: { rgb: [255,255,0], mode:'oklab', css: 'oklab(96.8% -7.14% 19.86%)' },
oklch: { rgb: [255,255,0], mode:'oklch', css: 'oklch(96.8% 52.75% 109.77)' },
oklch2: { rgb: [207,66,0], mode:'oklch', css: 'oklch(57.61% 46.72% 38.41)' },
laba: { rgb: [255,255,0,0.75], mode:'lab', css: 'lab(97.14% -21.55% 94.48% / 0.75)' },
lcha: { rgb: [255,255,0,0.75], mode:'lch', css: 'lch(97.14% 96.91% 102.85)' },
oklaba: { rgb: [255,255,0,0.75], mode:'oklab', css: 'oklab(96.8% -7.14% 19.86% / 0.75)' },
oklcha: { rgb: [255,255,0,0.75], mode:'oklch', css: 'oklch(96.8% 52.75% 109.77 / 0.75)' },
};
const batch = {};
Object.keys(tests).forEach(key => {
batch[key] = {
topic: tests[key],
array(topic) {
assert.equal(rgb2css(topic.rgb, topic.mode || 'rgb'), topic.css);
},
obj(topic) {
let [r,g,b] = topic.rgb;
let obj = {r,g,b,...(topic.rgb.length>3 ? {a:topic.rgb[3]}:{})};
assert.equal(rgb2css(obj, topic.mode), topic.css);
},
args(topic) {
if (topic.mode != 'rgb') return;
assert.deepStrictEqual(rgb2css.apply(null, topic.rgb), topic.hex);
}
}
});
vows
.describe('Testing rgb2css color conversions')
.addBatch(batch)
.export(module);