forked from websanova/rgbHex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
108 lines (99 loc) · 4.63 KB
/
tests.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(function() {
module('rgbHex');
test('rgb to hex - valid', function() {
equal( window.rgbHex( 'rgb(255,255,255)' ), '#FFFFFF' );
equal( window.rgbHex( 'rgb(255, 255, 255) ' ), '#FFFFFF' );
equal( window.rgbHex( 'rgb(255, 255, 255, 0.4) ' ), '#FFFFFF' );
equal( window.rgbHex( 'rgba(255,255,255)' ), '#FFFFFF' );
equal( window.rgbHex( 'rgba(255,255,255, 0) ' ), '#FFFFFF' );
equal( window.rgbHex( ' rgba(255,255,255, 0.0)' ), '#FFFFFF' );
equal( window.rgbHex( '255,255,255' ), '#FFFFFF' );
equal( window.rgbHex( '255, 255, 255' ), '#FFFFFF' );
equal( window.rgbHex( '255,255,255,0' ), '#FFFFFF' );
equal( window.rgbHex( ' 255,255, 255, 0' ), '#FFFFFF' );
equal( window.rgbHex( '255, 255,255, 0.5 ' ), '#FFFFFF' );
equal( window.rgbHex( 'rgb(255,255,255);' ), '#FFFFFF' );
});
test('rgb to hex - invalid', function() {
equal( window.rgbHex( 'rgb(255,255);' ), null );
equal( window.rgbHex( 'rgb(255,255,255' ), null );
equal( window.rgbHex( 'rgba(255,255,255,0.4' ), null );
equal( window.rgbHex( 'rgb(255,2 55,255);' ), null );
equal( window.rgbHex( 'rgb(255,);' ), null );
equal( window.rgbHex( 'rgba(255, 255,);' ), null );
equal( window.rgbHex( 'rgba(255,);' ), null );
equal( window.rgbHex( '7 rgba(255,255,255)' ), null );
equal( window.rgbHex( '7 rgba(255,255,255) j' ), null );
equal( window.rgbHex( '7 255,255,255' ), null );
equal( window.rgbHex( '255, 255, 255 9 ' ), null );
equal( window.rgbHex( '255,255,255,0 9' ), null );
equal( window.rgbHex( 'a 255,255, 255, 0' ), null );
equal( window.rgbHex( 'a 255,255,' ), null );
equal( window.rgbHex( 'a 255,255' ), null );
equal( window.rgbHex( '255,255' ), null );
equal( window.rgbHex( '255,255,256' ), null );
equal( window.rgbHex( 'rgb(255,255,256)' ), null );
equal( window.rgbHex( 'rgba(255,255,256,0)' ), null );
equal( window.rgbHex( ' rgb(255, 255, 255) ;' ), null );
equal( window.rgbHex( 'rgb(a, b, c)' ), null );
equal( window.rgbHex( 'rgb(255, 23, a)' ), null );
});
test('rgb to hex - colours', function() {
equal( window.rgbHex( 'rgb(255,255,255)' ), '#FFFFFF' );
equal( window.rgbHex( 'rgb(0, 0, 0)' ), '#000000' );
equal( window.rgbHex( 'rgb(1, 2, 3)' ), '#010203' );
equal( window.rgbHex( 'rgb(8, 9, 10)' ), '#08090A' );
equal( window.rgbHex( 'rgb(14, 15, 16)' ), '#0E0F10' );
equal( window.rgbHex( 'rgb(00, 0, 000)' ), '#000000' );
equal( window.rgbHex( 'rgba(127,255,0)' ), '#7FFF00' );
equal( window.rgbHex( 'rgba(64,224,208)' ), '#40E0D0' );
equal( window.rgbHex( 'rgba(255,165,0)' ), '#FFA500' );
equal( window.rgbHex( 'rgba(230,230,250)' ), '#E6E6FA' );
equal( window.rgbHex( ' 65,105,225 ' ), '#4169E1' );
equal( window.rgbHex( '119, 136, 153' ), '#778899' );
equal( window.rgbHex( '47,79,79, 0' ), '#2F4F4F' );
equal( window.rgbHex( ' 255,0, 255, 0' ), '#FF00FF' );
equal( window.rgbHex( '152, 251,152, 0.5 ' ), '#98FB98' );
});
test('hex to rgb - valid', function() {
equal( window.rgbHex( '255' ), 'rgb(37,82,85)' );
equal( window.rgbHex( '#255' ), 'rgb(37,82,85)' );
equal( window.rgbHex( '255255' ), 'rgb(37,82,85)' );
equal( window.rgbHex( '#255255' ), 'rgb(37,82,85)' );
equal( window.rgbHex( ' #255255 ' ), 'rgb(37,82,85)' );
equal( window.rgbHex( 255255 ), 'rgb(37,82,85)' );
equal( window.rgbHex( 255 ), 'rgb(37,82,85)' );
});
test('hex to rgb - invalid', function() {
equal( window.rgbHex( ',255' ), null );
equal( window.rgbHex( '2 55' ), null );
equal( window.rgbHex( ',2555' ), null );
equal( window.rgbHex( '2555' ), null );
equal( window.rgbHex( '25' ), null );
equal( window.rgbHex( ',#255' ), null );
equal( window.rgbHex( '#255#' ), null );
equal( window.rgbHex( '#25555' ), null);
equal( window.rgbHex( '25555' ), null);
equal( window.rgbHex( '34Z' ), null);
equal( window.rgbHex( 'ABT' ), null);
equal( window.rgbHex( '255255, ' ), null );
equal( window.rgbHex( ' ,255255 ' ), null );
});
test('hex to rgb - colours', function() {
equal( window.rgbHex( '#FFF' ), 'rgb(255,255,255)' );
equal( window.rgbHex( '#000' ), 'rgb(0,0,0)' );
equal( window.rgbHex( '#010203' ), 'rgb(1,2,3)' );
equal( window.rgbHex( ' 08090A' ), 'rgb(8,9,10)' );
equal( window.rgbHex( ' 0E0F10 ' ), 'rgb(14,15,16)' );
equal( window.rgbHex( '4169E1 ' ), 'rgb(65,105,225)' );
equal( window.rgbHex( '778899' ), 'rgb(119,136,153)' );
equal( window.rgbHex( ' #2f4f4F' ), 'rgb(47,79,79)' );
equal( window.rgbHex( ' #FF00FF ' ), 'rgb(255,0,255)' );
equal( window.rgbHex( '#98FB98 ' ), 'rgb(152,251,152)' );
});
test('jQuery', function() {
equal( $.rgbHex( '#FFF' ), 'rgb(255,255,255)' );
equal( $.rgbHex( '000' ), 'rgb(0,0,0)' );
equal( $.rgbHex( 'rgb(255,255,255)' ), '#FFFFFF' );
});
}());