Commit a3e8620a a3e8620ab998d6963ae753059e23d1db8c2d3bde by Nicolas Perriault

added tests for utils' fillBlanks()

1 parent 7d23991a
1 (function(t) { 1 (function(t) {
2 t.comment('fileExt()'); 2 t.comment('fileExt()');
3 3
4 var testCases = { 4 (function() {
5 'foo.ext': 'ext', 5 var testCases = {
6 'FOO.EXT': 'ext', 6 'foo.ext': 'ext',
7 'a.ext': 'ext', 7 'FOO.EXT': 'ext',
8 '.ext': 'ext', 8 'a.ext': 'ext',
9 'toto.': '', 9 '.ext': 'ext',
10 ' plop.ext ': 'ext' 10 'toto.': '',
11 }; 11 ' plop.ext ': 'ext'
12 12 };
13 for (var testCase in testCases) { 13
14 t.assertEquals(fileExt(testCase), testCases[testCase], 'fileExt() extract file extension'); 14 for (var testCase in testCases) {
15 } 15 t.assertEquals(fileExt(testCase), testCases[testCase], 'fileExt() extract file extension');
16 }
17 })();
18
19 t.comment('fillBlanks()');
20
21 (function() {
22 testCases = {
23 'foo': 'foo ',
24 ' foo bar ': ' foo bar ',
25 ' foo bar ': ' foo bar '
26 };
27
28 for (var testCase in testCases) {
29 t.assertEquals(fillBlanks(testCase, 10), testCases[testCase], 'fillBlanks() fills blanks');
30 }
31 })();
16 32
17 t.comment('mergeObjects()'); 33 t.comment('mergeObjects()');
18 34
19 testCases = [ 35 (function() {
20 { 36 testCases = [
21 obj1: {a: 1}, obj2: {b: 2}, merged: {a: 1, b: 2} 37 {
22 }, 38 obj1: {a: 1}, obj2: {b: 2}, merged: {a: 1, b: 2}
23 { 39 },
24 obj1: {}, obj2: {a: 1}, merged: {a: 1} 40 {
25 }, 41 obj1: {}, obj2: {a: 1}, merged: {a: 1}
26 { 42 },
27 obj1: {a: 1}, obj2: {}, merged: {a: 1} 43 {
28 }, 44 obj1: {a: 1}, obj2: {}, merged: {a: 1}
29 { 45 },
30 obj1: {a: 1}, obj2: {a: 2}, merged: {a: 2} 46 {
31 }, 47 obj1: {a: 1}, obj2: {a: 2}, merged: {a: 2}
32 { 48 },
33 obj1: {x: 0, double: function(){return this.x*2;}}, 49 {
34 obj2: {triple: function(){return this.x*3;}}, 50 obj1: {x: 0, double: function(){return this.x*2;}},
35 merged: { 51 obj2: {triple: function(){return this.x*3;}},
36 x: 0, 52 merged: {
37 double: function(){return this.x*2;}, 53 x: 0,
38 triple: function(){return this.x*3;} 54 double: function(){return this.x*2;},
55 triple: function(){return this.x*3;}
56 }
39 } 57 }
40 } 58 ];
41 ];
42 59
43 testCases.forEach(function(testCase) { 60 testCases.forEach(function(testCase) {
44 t.assertEquals(mergeObjects(testCase.obj1, testCase.obj2), testCase.merged, 'mergeObjects() can merge objects'); 61 t.assertEquals(mergeObjects(testCase.obj1, testCase.obj2), testCase.merged, 'mergeObjects() can merge objects');
45 }); 62 });
63 })();
46 64
47 t.done(); 65 t.done();
48 })(casper.test); 66 })(casper.test);
......