forked from mapnik/node-mapnik
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor.test.js
More file actions
56 lines (49 loc) · 1.73 KB
/
color.test.js
File metadata and controls
56 lines (49 loc) · 1.73 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
var mapnik = require('../');
var assert = require('assert');
describe('mapnik.Color', function() {
it('should throw with invalid usage', function() {
// no 'new' keyword
assert.throws(function() { mapnik.Color(); });
// invalid args
assert.throws(function() { new mapnik.Color(); });
assert.throws(function() { new mapnik.Color(1); });
assert.throws(function() { new mapnik.Color('foo'); });
});
it('should be green via keyword', function() {
var c = new mapnik.Color('green');
assert.equal(c.r, 0);
assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});
it('should be gray via rgb', function() {
var c = new mapnik.Color(0, 128, 0);
assert.equal(c.r, 0);
assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});
it('should be gray via rgba', function() {
var c = new mapnik.Color(0, 128, 0, 255);
assert.equal(c.r, 0);
assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});
it('should be gray via rgba %', function() {
var c = new mapnik.Color('rgba(0%,50%,0%,1)');
assert.equal(c.r, 0);
assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});
});