2017-12-03 12:07:10 +03:00
|
|
|
const Color = require('../../dist/npm/Color').default;
|
|
|
|
const assert = require('assert');
|
2015-02-03 22:34:05 +03:00
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
describe('Colors', () => {
|
|
|
|
describe('named colors', () => {
|
|
|
|
it('bisque', () => {
|
|
|
|
const c = new Color('bisque');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 255, 228, 196, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('BLUE', () => {
|
|
|
|
const c = new Color('BLUE');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 0, 0, 255, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
describe('rgb()', () => {
|
|
|
|
it('rgb(1,3,5)', () => {
|
|
|
|
const c = new Color('rgb(1,3,5)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 1, 3, 5, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('rgb(222, 111, 50)', () => {
|
|
|
|
const c = new Color('rgb(222, 111, 50)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 222, 111, 50, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('rgb( 222, 111 , 50)', () => {
|
|
|
|
const c = new Color('rgb(222 , 111 , 50)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 222, 111, 50, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
describe('rgba()', () => {
|
|
|
|
it('rgba(200,3,5,1)', () => {
|
|
|
|
const c = new Color('rgba(200,3,5,1)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 200, 3, 5, 1);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('rgba(222, 111, 50, 0.22)', () => {
|
|
|
|
const c = new Color('rgba(222, 111, 50, 0.22)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 222, 111, 50, 0.22);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('rgba( 222, 111 , 50, 0.123 )', () => {
|
|
|
|
const c = new Color('rgba(222 , 111 , 50, 0.123)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 222, 111, 50, 0.123);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
describe('hex', () => {
|
|
|
|
it('#7FFFD4', () => {
|
|
|
|
const c = new Color('#7FFFD4');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 127, 255, 212, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('#f0ffff', () => {
|
|
|
|
const c = new Color('#f0ffff');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 240, 255, 255, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('#fff', () => {
|
|
|
|
const c = new Color('#fff');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 255, 255, 255, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
describe('from array', () => {
|
|
|
|
it('[1,2,3]', () => {
|
|
|
|
const c = new Color([1, 2, 3]);
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 1, 2, 3, null);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('[5,6,7,1]', () => {
|
|
|
|
const c = new Color([5, 6, 7, 1]);
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 5, 6, 7, 1);
|
|
|
|
assert.equal(c.isTransparent(), false);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('[5,6,7,0]', () => {
|
|
|
|
const c = new Color([5, 6, 7, 0]);
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 5, 6, 7, 0);
|
|
|
|
assert.equal(c.isTransparent(), true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
describe('transparency', () => {
|
|
|
|
it('transparent', () => {
|
|
|
|
const c = new Color('transparent');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 0, 0, 0, 0);
|
|
|
|
assert.equal(c.isTransparent(), true);
|
|
|
|
});
|
|
|
|
|
2017-12-03 12:07:10 +03:00
|
|
|
it('rgba(255,255,255,0)', () => {
|
|
|
|
const c = new Color('rgba(255,255,255,0)');
|
2015-02-03 22:34:05 +03:00
|
|
|
assertColor(c, 255, 255, 255, 0);
|
|
|
|
assert.equal(c.isTransparent(), true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function assertColor(c, r, g, b, a) {
|
|
|
|
assert.equal(c.r, r);
|
|
|
|
assert.equal(c.g, g);
|
|
|
|
assert.equal(c.b, b);
|
|
|
|
assert.equal(c.a, a);
|
|
|
|
}
|