-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
36 lines (30 loc) · 2.01 KB
/
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
import assert from 'assert'
import rgba from './index.js'
assert.deepEqual(rgba('red'), [1, 0, 0, 1])
assert.deepEqual(rgba('rgb(80, 120, 160)', 'uint8'), new Uint8Array([80, 120, 160, 255]))
assert.deepEqual(rgba('rgb(255, 255, 255, .5)', 'float64'), new Float64Array([1, 1, 1, .5]))
assert.deepEqual(rgba('rgba(255, 255, 255, .5)', 'float64'), new Float64Array([1, 1, 1, .5]))
assert.deepEqual(rgba('hsla(109, 50%, 50%, .75)', 'uint8'), new Uint8Array([87, 191, 63, 191]))
assert.deepEqual(rgba(new Float32Array([0, 0.25, 0, 1]), 'uint8_clamped'), new Uint8ClampedArray([0, 63, 0, 255]))
assert.deepEqual(rgba(new Uint8Array([0, 72, 0, 255]), 'array'), [0, 0.2823529411764706, 0, 1])
assert.deepEqual(rgba(new Uint8Array([0, 72, 0, 255]), 'uint8'), new Uint8Array([0, 72, 0, 255]))
assert.deepEqual(rgba([0, 0, 0, 1]), [0, 0, 0, 1])
assert.deepEqual(rgba(0x00ff00), [0, 1, 0, 1])
assert.deepEqual(rgba(new Uint8Array([0, 72, 0]), 'uint8'), new Uint8Array([0, 72, 0, 255]))
assert.deepEqual(rgba([127.5, 127.5, 127.5, 127.5]), [.5, .5, .5, .5])
assert.deepEqual(rgba([127, 127, 127, 127], 'uint8'), new Uint8Array([127, 127, 127, 127]))
assert.deepEqual(rgba([.5, .5, .5, .5]), [.5, .5, .5, .5])
assert.deepEqual(rgba([.5, .5, .5, .5], 'uint8'), new Uint8Array([127, 127, 127, 127]))
assert.deepEqual(rgba([0, 0, 0, 0]), [0, 0, 0, 0])
assert.deepEqual(rgba([0, 0, 0, 0], 'uint'), new Uint8Array([0, 0, 0, 0]))
assert.deepEqual(rgba([0, 0, 0]), [0, 0, 0, 1])
assert.deepEqual(rgba([0, 0, 0], 'uint'), new Uint8Array([0, 0, 0, 255]))
assert.deepEqual(rgba([0, 0, 1]), [0, 0, 1, 1])
assert.deepEqual(rgba([0, 0, 1], 'uint'), new Uint8Array([0, 0, 255, 255]))
assert.deepEqual(rgba([1, 1, 1]), [1, 1, 1, 1])
assert.deepEqual(rgba([1, 1, 1], 'uint'), new Uint8Array([255, 255, 255, 255]))
assert.deepEqual(rgba([0, 0, 0]), [0, 0, 0, 1])
// assert.deepEqual(rgba([.5,.5,.5]), [.5,.5,.5,1])
assert.deepEqual(rgba([1, 1, 1]), [1, 1, 1, 1])
assert.deepEqual(rgba([127.5, 127.5, 127.5]), [.5, .5, .5, 1])
assert.deepEqual(rgba([255, 255, 255]), [1, 1, 1, 1])