utils.js
2.21 KB
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
(function(t) {
t.comment('fileExt()');
(function() {
var testCases = {
'foo.ext': 'ext',
'FOO.EXT': 'ext',
'a.ext': 'ext',
'.ext': 'ext',
'toto.': '',
' plop.ext ': 'ext'
};
for (var testCase in testCases) {
t.assertEquals(fileExt(testCase), testCases[testCase], 'fileExt() extract file extension');
}
})();
t.comment('fillBlanks()');
(function() {
testCases = {
'foo': 'foo ',
' foo bar ': ' foo bar ',
' foo bar ': ' foo bar '
};
for (var testCase in testCases) {
t.assertEquals(fillBlanks(testCase, 10), testCases[testCase], 'fillBlanks() fills blanks');
}
})();
t.comment('isJsFile()');
(function() {
testCases = {
'': false,
'toto.png': false,
'plop': false,
'gniii.coffee': true,
'script.js': true
};
for (var testCase in testCases) {
t.assertEquals(isJsFile(testCase), testCases[testCase], 'isJsFile() checks for js file');
}
})();
t.comment('mergeObjects()');
(function() {
testCases = [
{
obj1: {a: 1}, obj2: {b: 2}, merged: {a: 1, b: 2}
},
{
obj1: {}, obj2: {a: 1}, merged: {a: 1}
},
{
obj1: {a: 1}, obj2: {}, merged: {a: 1}
},
{
obj1: {a: 1}, obj2: {a: 2}, merged: {a: 2}
},
{
obj1: {x: 0, double: function(){return this.x*2;}},
obj2: {triple: function(){return this.x*3;}},
merged: {
x: 0,
double: function(){return this.x*2;},
triple: function(){return this.x*3;}
}
}
];
testCases.forEach(function(testCase) {
t.assertEquals(mergeObjects(testCase.obj1, testCase.obj2), testCase.merged, 'mergeObjects() can merge objects');
});
})();
t.done();
})(casper.test);