Export 0.2.1
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / node_modules / colors / test.js
1 var assert = require('assert'),
2     colors = require('./colors');
3
4 // 
5 // This is a pretty nice example on how tests shouldn't be written. However,
6 // it's more about API stability than about really testing it (although it's
7 // a pretty complete test suite).
8 //
9
10 var s = 'string';
11
12 function a(s, code) {
13   return '\033[' + code.toString() + 'm' + s + '\033[39m';
14 }
15
16 function aE(s, color, code) {
17   assert.equal(s[color], a(s, code));
18   assert.equal(colors[color](s), a(s, code));
19   assert.equal(s[color], colors[color](s));
20   assert.equal(s[color].stripColors, s);
21   assert.equal(s[color].stripColors, colors.stripColors(s));
22 }
23
24 function h(s, color) {
25   return '<span style="color:' + color + ';">' + s + '</span>';
26   // that's pretty dumb approach to testing it
27 }
28
29 var stylesColors = ['white', 'grey', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
30 var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
31
32 colors.mode = 'console';
33 assert.equal(s.bold, '\033[1m' + s + '\033[22m');
34 assert.equal(s.italic, '\033[3m' + s + '\033[23m');
35 assert.equal(s.underline, '\033[4m' + s + '\033[24m');
36 assert.equal(s.inverse, '\033[7m' + s + '\033[27m');
37 assert.ok(s.rainbow);
38 aE(s, 'white', 37);
39 aE(s, 'grey', 90);
40 aE(s, 'black', 30);
41 aE(s, 'blue', 34);
42 aE(s, 'cyan', 36);
43 aE(s, 'green', 32);
44 aE(s, 'magenta', 35);
45 aE(s, 'red', 31);
46 aE(s, 'yellow', 33);
47 assert.equal(s, 'string');
48
49 colors.mode = 'browser';
50 assert.equal(s.bold, '<b>' + s + '</b>');
51 assert.equal(s.italic, '<i>' + s + '</i>');
52 assert.equal(s.underline, '<u>' + s + '</u>');
53 assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
54 assert.ok(s.rainbow);
55 stylesColors.forEach(function (color) {
56   assert.equal(s[color], h(s, color));
57   assert.equal(colors[color](s), h(s, color));
58 });
59
60 colors.mode = 'none';
61 stylesAll.forEach(function (style) {
62   assert.equal(s[style], s);
63   assert.equal(colors[style](s), s);
64 });
65