-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
41 lines (30 loc) · 1.75 KB
/
Copy pathtest.js
File metadata and controls
41 lines (30 loc) · 1.75 KB
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
import assert from 'assert';
import stringify from './index.js';
import parse from 'color-parse';
assert.equal(stringify([255, 10, 35], 'hex'), "#ff0a23");
assert.equal(stringify([255, 10, 35]), "rgb(255, 10, 35)");
assert.equal(stringify([255, 10, 35, 0.3]), "rgba(255, 10, 35, 0.3)");
assert.equal(stringify([255, 10, 35, 1.0]), "rgb(255, 10, 35)");
assert.equal(stringify([255, 10, 35, 0]), "rgba(255, 10, 35, 0)");
assert.equal(stringify([280, 40, 60], 'hsl'), "hsl(280, 40%, 60%)");
assert.equal(stringify([280, 40, 60, 0.3], 'hsl'), "hsla(280, 40%, 60%, 0.3)");
assert.equal(stringify([280, 40, 60, 0], 'hsl'), "hsla(280, 40%, 60%, 0)");
assert.equal(stringify([280, 40, 60], 'hwb'), "hwb(280, 40%, 60%)");
assert.equal(stringify([280, 40, 60, 0.3], 'hwb'), "hwb(280, 40%, 60%, 0.3)");
assert.equal(stringify([280, 40, 60, 0], 'hwb'), "hwb(280, 40%, 60%, 0)");
assert.equal(stringify([255, 255, 0], 'keyword'), "yellow");
assert.equal(stringify([100, 255, 0], 'keyword'), undefined);
//short hex
assert.equal(stringify([0, 255, 255], 'hex'), '#0ff');
//fractional channels round, not corrupt the hex
assert.equal(stringify([127.5, 0, 255], 'hex'), '#8000ff');
//adobe1,2
assert.equal(stringify([0, 255, 255], 'adobe1'), 'R:0, G:255, B:255');
assert.equal(stringify([0, 255, 255], 'adobe2'), '(R0 / G255 / B255)');
//percent string
assert.equal(stringify([10, 30, 25], 'percent'), "rgb(4%, 12%, 10%)");
assert.equal(stringify([10, 30, 25, 0.3], 'percent'), "rgba(4%, 12%, 10%, 0.3)");
assert.equal(stringify(parse('rgb(180, 15, 0)')), 'rgb(180, 15, 0)');
assert.equal(stringify(parse('rgba(120, 0, 177, 0.5)')), 'rgba(120, 0, 177, 0.5)');
assert.equal(stringify(parse('hsla(170, 100%, 30%, 0.8)')), 'hsla(170, 100%, 30%, 0.8)');
console.log('color-stringify: all tests pass');