UNPKG

1.71 kBJavaScriptView Raw
1"use strict";
2
3var Color = require("tfw.color");
4
5
6describe('tfw.color', function() {
7 describe('parse()', function() {
8 var cases = [
9 ["#fff", 1, 1, 1, 1],
10 ["#ffff", 1, 1, 1, 1],
11 ["#ffffff", 1, 1, 1, 1],
12 ["#ffffffff", 1, 1, 1, 1],
13 ["#000", 0, 0, 0, 1],
14 ["#0000", 0, 0, 0, 0],
15 ["#000000", 0, 0, 0, 1],
16 ["#00000000", 0, 0, 0, 0],
17 ["#CD9", .8, .8667, .6, 1],
18 ["#B4440129", 0xB4/255, 0x44/255, 0x01/255, 0x29/255],
19 ["#B44401", 0xB4/255, 0x44/255, 0x01/255, 1],
20 ["rgb(127, 240, 44)", 127/255, 240/255, 44/255, 1],
21 ["rgb (17, 240, 44)", 17/255, 240/255, 44/255, 1],
22 ["rgb ( 127, 20, 44)", 127/255, 20/255, 44/255, 1],
23 ["rgb(27,240,44)", 27/255, 240/255, 44/255, 1],
24 ["rgb (127, 240, 144", 127/255, 240/255, 144/255, 1],
25 ["rgba(100,200,50,0.33)", 100/255, 200/255, 50/255, 0.33]
26 ];
27 cases.forEach(function (singleCase) {
28 var text = singleCase[0];
29 var R = singleCase[1].toFixed( 4 );
30 var G = singleCase[2].toFixed( 4 );
31 var B = singleCase[3].toFixed( 4 );
32 var A = singleCase[4].toFixed( 4 );
33 it(`should return true for ${text}`, function() {
34 var color = new Color();
35 expect( color.parse( text ) ).toBe( true );
36 });
37 it(`should find (${R}, ${G}, ${B}) from ${text}`, function() {
38 var color = new Color();
39 color.parse( text );
40 var rr = color.R.toFixed( 4 );
41 var gg = color.G.toFixed( 4 );
42 var bb = color.B.toFixed( 4 );
43 var aa = color.A.toFixed( 4 );
44 expect([ rr, gg, bb, aa ]).toEqual([ R, G, B, A ]);
45 });
46 });
47 });
48});