/
apha-test.coffee
64 lines (49 loc) · 2.69 KB
/
apha-test.coffee
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
64
vows = require 'vows'
assert = require 'assert'
chroma = require '../chroma'
vows
.describe('Tests for the alpha channel')
.addBatch
'setting & getting alpha channel':
topic: -> chroma 'red'
'default alpha is 1': (topic) -> assert.equal topic.alpha(), 1
'setting alpha to 0.5': (topic) -> assert.equal topic.alpha(0.5), topic
'alpha is now 0.5': (topic) -> assert.equal topic.alpha(), 0.5
'interpolating alpha channel':
topic: -> chroma.mix chroma.color('white').alpha(0), chroma.color('black').alpha(1), 0.3
'color is grey': (topic) -> assert.equal topic.hex(), '#b2b2b2'
'alpha is 50%': (topic) -> assert.equal topic.alpha(), 0.3
'constructing rgba color':
topic: -> new chroma 255,0,0,0.5,'rgb'
'alpha is 50%': (topic) -> assert.equal topic.alpha(), 0.5
'constructing rgba color, rgb shorthand':
topic: -> chroma.rgb(255,0,0,0.5)
'alpha is 50%': (topic) -> assert.equal topic.alpha(), 0.5
'constructing rgba color, hsl shorthand':
topic: -> chroma.hsl 0,1,0.5,0.5
'color is red': (topic) -> assert.equal topic.name(), 'red'
'alpha is 50%': (topic) -> assert.equal topic.alpha(), 0.5
'parsing rgba colors':
topic: -> chroma.css 'rgba(255,0,0,.3)'
'color is red': (topic) -> assert.equal topic.name(), 'red'
'alpha is 30%': (topic) -> assert.equal topic.alpha(), 0.3
'rgba output': (topic) -> assert.deepEqual topic.rgba(), [255,0,0,0.3]
'parsing rgba colors (percentage)':
topic: -> chroma.css 'rgba(100%,0%,0%,0.2)'
'color is red': (topic) -> assert.equal topic.name(), 'red'
'alpha is 20%': (topic) -> assert.equal topic.alpha(), 0.2
'rgb output': (topic) -> assert.deepEqual topic.rgb(), [255,0,0]
'rgba output': (topic) -> assert.deepEqual topic.rgba(), [255,0,0,0.2]
'parsing hsla colors':
topic: -> chroma.css 'hsla(0,100%,50%,0.25)'
'color is red': (topic) -> assert.equal topic.name(), 'red'
'alpha is 25%': (topic) -> assert.equal topic.alpha(), 0.25
'rgb output': (topic) -> assert.deepEqual topic.rgb(), [255,0,0]
'rgba output': (topic) -> assert.deepEqual topic.rgba(), [255,0,0,0.25]
'gl output':
topic: -> chroma.gl 1, 0, 0, 0.25
'gloutput': (topic) -> assert.deepEqual topic.gl(), [1, 0, 0, 0.25]
'rgba css output':
topic: -> chroma.css 'hsla(0,100%,50%,0.25)'
'cssoutput': -> (topic) -> assert.equal topic.css(), 'rgba(255,0,0,0.25)'
.export(module)