newjs 1.7.2 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +13 -2
- data/Rakefile +11 -20
- data/app_generators/newjs/templates/test/assets/jsunittest.js +173 -135
- data/app_generators/newjs_iphone/templates/Html/test/assets/jsunittest.js +173 -135
- data/app_generators/newjs_screwunit/USAGE +5 -0
- data/app_generators/newjs_screwunit/newjs_screwunit_generator.rb +61 -0
- data/app_generators/newjs_screwunit/templates/Rakefile.erb +34 -0
- data/bin/newjs_screwunit +17 -0
- data/features/development.feature +5 -5
- data/features/imported_files_for_generators.feature +2 -2
- data/features/newjs_screwunit.feature +18 -0
- data/features/step_definitions/cli_steps.rb +9 -0
- data/features/{steps/common.rb → step_definitions/common_steps.rb} +39 -81
- data/features/step_definitions/file_comparison_steps.rb +10 -0
- data/features/support/common.rb +29 -0
- data/features/support/env.rb +15 -0
- data/features/support/matchers.rb +11 -0
- data/lib/newjs.rb +1 -1
- data/rack_generators/javascript_test/templates/assets/jsunittest.js +173 -135
- data/rails_generators/javascript_test/templates/assets/jsunittest.js +173 -135
- data/test/test_newjs_screwunit_generator.rb +43 -0
- data/vendor/jsunittest/History.txt +9 -0
- data/vendor/jsunittest/Rakefile +1 -1
- data/vendor/jsunittest/dist/jsunittest-0.7.3.js +1042 -0
- data/vendor/jsunittest/dist/jsunittest.js +173 -135
- data/vendor/jsunittest/src/ajax.js +2 -1
- data/vendor/jsunittest/src/assertions.js +49 -78
- data/vendor/jsunittest/src/common.js +83 -24
- data/vendor/jsunittest/src/jsunittest.js +7 -998
- data/vendor/jsunittest/src/logger.js +6 -6
- data/vendor/jsunittest/src/message_template.js +1 -1
- data/vendor/jsunittest/src/prototype/event.js +2 -2
- data/vendor/jsunittest/src/prototype/template.js +7 -6
- data/vendor/jsunittest/src/runner.js +13 -12
- data/vendor/jsunittest/src/test_case.js +11 -6
- data/vendor/jsunittest/test/unit/assertions_test.html +9 -1
- data/vendor/jsunittest/test/unit/common_test.html +9 -1
- data/vendor/jsunittest/test/unit/logger_test.html +2 -2
- data/vendor/jsunittest/test/unit/message_template_test.html +2 -2
- data/vendor/jsunittest/test/unit/runner_test.html +2 -2
- data/vendor/jsunittest/test/unit/template_test.html +2 -2
- data/vendor/jsunittest/test/unit/test_case_test.html +24 -3
- data/vendor/jsunittest/website/images/logo_bundle.png +0 -0
- data/vendor/jsunittest/website/index.html +3 -3
- data/vendor/jsunittest/website/index.txt +1 -1
- data/vendor/jsunittest/website/stylesheets/screen.css +3 -0
- data/vendor/jsunittest/website/tmbundle/JavaScript Unit Testing.tmbundle.tar.gz +0 -0
- metadata +20 -14
- data/features/steps/env.rb +0 -6
@@ -111,8 +111,9 @@ JsUnitTest.ajax = function( options ) {
|
|
111
111
|
|
112
112
|
// If the specified type is "script", execute the returned text
|
113
113
|
// response as if it was JavaScript
|
114
|
-
if ( type == "script" )
|
114
|
+
if ( type == "script" ) {
|
115
115
|
eval.call( window, data );
|
116
|
+
}
|
116
117
|
|
117
118
|
// Return the response data (either an XML Document or a text string)
|
118
119
|
return data;
|
@@ -4,172 +4,142 @@ JsUnitTest.Unit.Assertions = {
|
|
4
4
|
return (message ? message + '\n' : '') +
|
5
5
|
new JsUnitTest.Unit.MessageTemplate(template).evaluate(args);
|
6
6
|
},
|
7
|
-
|
7
|
+
|
8
8
|
flunk: function(message) {
|
9
|
-
this.assertBlock(message || 'Flunked', function() { return false });
|
9
|
+
this.assertBlock(message || 'Flunked', function() { return false; });
|
10
10
|
},
|
11
11
|
|
12
12
|
assertBlock: function(message, block) {
|
13
13
|
try {
|
14
14
|
block.call(this) ? this.pass() : this.fail(message);
|
15
|
-
} catch(e) { this.error(e) }
|
15
|
+
} catch(e) { this.error(e); }
|
16
16
|
},
|
17
17
|
|
18
18
|
assert: function(expression, message) {
|
19
19
|
message = this.buildMessage(message || 'assert', 'got <?>', expression);
|
20
|
-
this.assertBlock(message, function() { return expression });
|
20
|
+
this.assertBlock(message, function() { return expression; });
|
21
21
|
},
|
22
22
|
|
23
23
|
assertEqual: function(expected, actual, message) {
|
24
24
|
message = this.buildMessage(message || 'assertEqual', 'expected <?>, actual: <?>', expected, actual);
|
25
|
-
this.assertBlock(message, function() { return expected == actual });
|
25
|
+
this.assertBlock(message, function() { return expected == actual; });
|
26
26
|
},
|
27
27
|
|
28
28
|
assertNotEqual: function(expected, actual, message) {
|
29
29
|
message = this.buildMessage(message || 'assertNotEqual', 'expected <?>, actual: <?>', expected, actual);
|
30
|
-
this.assertBlock(message, function() { return expected != actual });
|
30
|
+
this.assertBlock(message, function() { return expected != actual; });
|
31
31
|
},
|
32
32
|
|
33
33
|
assertEnumEqual: function(expected, actual, message) {
|
34
34
|
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
|
35
|
-
|
36
|
-
var actual_array = JsUnitTest.flattenArray(actual);
|
37
|
-
this.assertBlock(message, function() {
|
38
|
-
if (expected_array.length == actual_array.length) {
|
39
|
-
for (var i=0; i < expected_array.length; i++) {
|
40
|
-
if (expected_array[i] != actual_array[i]) return false;
|
41
|
-
};
|
42
|
-
return true;
|
43
|
-
}
|
44
|
-
return false;
|
45
|
-
});
|
35
|
+
this.assertBlock(message, function() { return JsUnitTest.areArraysEqual(expected, actual); });
|
46
36
|
},
|
47
37
|
|
48
38
|
assertEnumNotEqual: function(expected, actual, message) {
|
49
39
|
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
|
50
|
-
|
51
|
-
var actual_array = JsUnitTest.flattenArray(actual);
|
52
|
-
this.assertBlock(message, function() {
|
53
|
-
if (expected_array.length == actual_array.length) {
|
54
|
-
for (var i=0; i < expected_array.length; i++) {
|
55
|
-
if (expected_array[i] != actual_array[i]) return true;
|
56
|
-
};
|
57
|
-
return false;
|
58
|
-
}
|
59
|
-
return true;
|
60
|
-
});
|
40
|
+
this.assertBlock(message, function() { return JsUnitTest.areArraysNotEqual(expected, actual); });
|
61
41
|
},
|
62
42
|
|
63
43
|
assertHashEqual: function(expected, actual, message) {
|
64
|
-
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', expected, actual);
|
65
|
-
|
66
|
-
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
67
|
-
var block = function() {
|
68
|
-
if (expected_array.length == actual_array.length) {
|
69
|
-
for (var i=0; i < expected_array.length; i++) {
|
70
|
-
if (expected_array[i] != actual_array[i]) return false;
|
71
|
-
};
|
72
|
-
return true;
|
73
|
-
}
|
74
|
-
return false;
|
75
|
-
};
|
76
|
-
this.assertBlock(message, block);
|
44
|
+
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', JsUnitTest.inspect(expected), JsUnitTest.inspect(actual));
|
45
|
+
this.assertBlock(message, function() { return JsUnitTest.areHashesEqual(expected, actual); });
|
77
46
|
},
|
78
47
|
|
79
48
|
assertHashNotEqual: function(expected, actual, message) {
|
80
|
-
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', expected, actual);
|
81
|
-
|
82
|
-
var actual_array = JsUnitTest.flattenArray(JsUnitTest.hashToSortedArray(actual));
|
83
|
-
// from now we recursively zip & compare nested arrays
|
84
|
-
var block = function() {
|
85
|
-
if (expected_array.length == actual_array.length) {
|
86
|
-
for (var i=0; i < expected_array.length; i++) {
|
87
|
-
if (expected_array[i] != actual_array[i]) return true;
|
88
|
-
};
|
89
|
-
return false;
|
90
|
-
}
|
91
|
-
return true;
|
92
|
-
};
|
93
|
-
this.assertBlock(message, block);
|
49
|
+
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', JsUnitTest.inspect(expected), JsUnitTest.inspect(actual));
|
50
|
+
this.assertBlock(message, function() { return JsUnitTest.areHashesNotEqual(expected, actual); });
|
94
51
|
},
|
95
52
|
|
96
53
|
assertIdentical: function(expected, actual, message) {
|
97
54
|
message = this.buildMessage(message || 'assertIdentical', 'expected <?>, actual: <?>', expected, actual);
|
98
|
-
this.assertBlock(message, function() { return expected === actual });
|
55
|
+
this.assertBlock(message, function() { return expected === actual; });
|
99
56
|
},
|
100
57
|
|
101
58
|
assertNotIdentical: function(expected, actual, message) {
|
102
59
|
message = this.buildMessage(message || 'assertNotIdentical', 'expected <?>, actual: <?>', expected, actual);
|
103
|
-
this.assertBlock(message, function() { return expected !== actual });
|
60
|
+
this.assertBlock(message, function() { return expected !== actual; });
|
104
61
|
},
|
105
62
|
|
106
63
|
assertNull: function(obj, message) {
|
107
64
|
message = this.buildMessage(message || 'assertNull', 'got <?>', obj);
|
108
|
-
this.assertBlock(message, function() { return obj === null });
|
65
|
+
this.assertBlock(message, function() { return obj === null; });
|
109
66
|
},
|
110
67
|
|
111
68
|
assertNotNull: function(obj, message) {
|
112
69
|
message = this.buildMessage(message || 'assertNotNull', 'got <?>', obj);
|
113
|
-
this.assertBlock(message, function() { return obj !== null });
|
70
|
+
this.assertBlock(message, function() { return obj !== null; });
|
114
71
|
},
|
115
72
|
|
116
73
|
assertUndefined: function(obj, message) {
|
117
74
|
message = this.buildMessage(message || 'assertUndefined', 'got <?>', obj);
|
118
|
-
this.assertBlock(message, function() { return typeof obj == "undefined" });
|
75
|
+
this.assertBlock(message, function() { return typeof obj == "undefined"; });
|
119
76
|
},
|
120
77
|
|
121
78
|
assertNotUndefined: function(obj, message) {
|
122
79
|
message = this.buildMessage(message || 'assertNotUndefined', 'got <?>', obj);
|
123
|
-
this.assertBlock(message, function() { return typeof obj != "undefined" });
|
80
|
+
this.assertBlock(message, function() { return typeof obj != "undefined"; });
|
124
81
|
},
|
125
82
|
|
126
83
|
assertNullOrUndefined: function(obj, message) {
|
127
84
|
message = this.buildMessage(message || 'assertNullOrUndefined', 'got <?>', obj);
|
128
|
-
this.assertBlock(message, function() { return obj == null });
|
85
|
+
this.assertBlock(message, function() { return obj == null; });
|
129
86
|
},
|
130
87
|
|
131
88
|
assertNotNullOrUndefined: function(obj, message) {
|
132
89
|
message = this.buildMessage(message || 'assertNotNullOrUndefined', 'got <?>', obj);
|
133
|
-
this.assertBlock(message, function() { return obj != null });
|
90
|
+
this.assertBlock(message, function() { return obj != null; });
|
134
91
|
},
|
135
92
|
|
136
93
|
assertMatch: function(expected, actual, message) {
|
137
94
|
message = this.buildMessage(message || 'assertMatch', 'regex <?> did not match <?>', expected, actual);
|
138
|
-
this.assertBlock(message, function() { return new RegExp(expected).exec(actual) });
|
95
|
+
this.assertBlock(message, function() { return new RegExp(expected).exec(actual); });
|
139
96
|
},
|
140
97
|
|
141
98
|
assertNoMatch: function(expected, actual, message) {
|
142
99
|
message = this.buildMessage(message || 'assertNoMatch', 'regex <?> matched <?>', expected, actual);
|
143
|
-
this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) });
|
100
|
+
this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)); });
|
144
101
|
},
|
145
102
|
|
146
103
|
assertHasClass: function(element, klass, message) {
|
147
104
|
element = JsUnitTest.$(element);
|
148
105
|
message = this.buildMessage(message || 'assertHasClass', '? doesn\'t have class <?>.', element, klass);
|
149
|
-
this.assertBlock(message, function() {
|
150
|
-
|
106
|
+
this.assertBlock(message, function() {
|
107
|
+
var elementClassName = element.className;
|
108
|
+
return (elementClassName.length > 0 && (elementClassName == klass ||
|
109
|
+
new RegExp("(^|\\s)" + klass + "(\\s|$)").test(elementClassName)));
|
110
|
+
// return !!element.className.match(new RegExp(klass))
|
111
|
+
});
|
112
|
+
},
|
113
|
+
|
114
|
+
assertNotHasClass: function(element, klass, message) {
|
115
|
+
element = JsUnitTest.$(element);
|
116
|
+
message = this.buildMessage(message || 'assertNotHasClass', '? does have class <?>.', element, klass);
|
117
|
+
this.assertBlock(message, function() {
|
118
|
+
var elementClassName = element.className;
|
119
|
+
return !(elementClassName.length > 0 && (elementClassName == klass ||
|
120
|
+
new RegExp("(^|\\s)" + klass + "(\\s|$)").test(elementClassName)));
|
151
121
|
});
|
152
122
|
},
|
153
123
|
|
154
124
|
assertHidden: function(element, message) {
|
155
125
|
element = JsUnitTest.$(element);
|
156
126
|
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
|
157
|
-
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
|
127
|
+
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none'; });
|
158
128
|
},
|
159
129
|
|
160
130
|
assertInstanceOf: function(expected, actual, message) {
|
161
131
|
message = this.buildMessage(message || 'assertInstanceOf', '<?> was not an instance of the expected type', actual);
|
162
|
-
this.assertBlock(message, function() { return actual instanceof expected });
|
132
|
+
this.assertBlock(message, function() { return actual instanceof expected; });
|
163
133
|
},
|
164
134
|
|
165
135
|
assertNotInstanceOf: function(expected, actual, message) {
|
166
136
|
message = this.buildMessage(message || 'assertNotInstanceOf', '<?> was an instance of the expected type', actual);
|
167
|
-
this.assertBlock(message, function() { return !(actual instanceof expected) });
|
137
|
+
this.assertBlock(message, function() { return !(actual instanceof expected); });
|
168
138
|
},
|
169
139
|
|
170
140
|
assertRespondsTo: function(method, obj, message) {
|
171
141
|
message = this.buildMessage(message || 'assertRespondsTo', 'object doesn\'t respond to <?>', method);
|
172
|
-
this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function') });
|
142
|
+
this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function'); });
|
173
143
|
},
|
174
144
|
|
175
145
|
assertRaise: function(exceptionName, method, message) {
|
@@ -179,8 +149,8 @@ JsUnitTest.Unit.Assertions = {
|
|
179
149
|
method();
|
180
150
|
return false;
|
181
151
|
} catch(e) {
|
182
|
-
if (e.name == exceptionName) return true;
|
183
|
-
else throw e;
|
152
|
+
if (e.name == exceptionName) {return true;}
|
153
|
+
else {throw e;}
|
184
154
|
}
|
185
155
|
};
|
186
156
|
this.assertBlock(message, block);
|
@@ -198,22 +168,23 @@ JsUnitTest.Unit.Assertions = {
|
|
198
168
|
|
199
169
|
_isVisible: function(element) {
|
200
170
|
element = JsUnitTest.$(element);
|
201
|
-
if(!element.parentNode) return true;
|
171
|
+
if(!element.parentNode) {return true;}
|
202
172
|
this.assertNotNull(element);
|
203
|
-
if(element.style && (element.style.display == 'none'))
|
173
|
+
if(element.style && (element.style.display == 'none')) {
|
204
174
|
return false;
|
175
|
+
}
|
205
176
|
|
206
177
|
return arguments.callee.call(this, element.parentNode);
|
207
178
|
},
|
208
179
|
|
209
180
|
assertVisible: function(element, message) {
|
210
181
|
message = this.buildMessage(message, '? was not visible.', element);
|
211
|
-
this.assertBlock(message, function() { return this._isVisible(element) });
|
182
|
+
this.assertBlock(message, function() { return this._isVisible(element); });
|
212
183
|
},
|
213
184
|
|
214
185
|
assertNotVisible: function(element, message) {
|
215
186
|
message = this.buildMessage(message, '? was not hidden and didn\'t have a hidden parent either.', element);
|
216
|
-
this.assertBlock(message, function() { return !this._isVisible(element) });
|
187
|
+
this.assertBlock(message, function() { return !this._isVisible(element); });
|
217
188
|
},
|
218
189
|
|
219
190
|
assertElementsMatch: function() {
|
@@ -234,7 +205,7 @@ JsUnitTest.Unit.Assertions = {
|
|
234
205
|
message = this.buildMessage('assertElementsMatch', 'In index <?>: expected <?> but got ?', index, expression, element);
|
235
206
|
this.flunk(message);
|
236
207
|
pass = false;
|
237
|
-
}
|
208
|
+
}
|
238
209
|
this.assert(pass, "Expected all elements to match.");
|
239
210
|
},
|
240
211
|
|
@@ -2,34 +2,57 @@ var JsUnitTest = {
|
|
2
2
|
Unit: {},
|
3
3
|
inspect: function(object) {
|
4
4
|
try {
|
5
|
-
if (typeof object == "undefined") return 'undefined';
|
6
|
-
if (object === null) return 'null';
|
5
|
+
if (typeof object == "undefined") {return 'undefined';}
|
6
|
+
if (object === null) {return 'null';}
|
7
7
|
if (typeof object == "string") {
|
8
8
|
var useDoubleQuotes = arguments[1];
|
9
9
|
var escapedString = this.gsub(object, /[\x00-\x1f\\]/, function(match) {
|
10
|
-
var character =
|
11
|
-
|
10
|
+
var character = {
|
11
|
+
'\b': '\\b',
|
12
|
+
'\t': '\\t',
|
13
|
+
'\n': '\\n',
|
14
|
+
'\f': '\\f',
|
15
|
+
'\r': '\\r',
|
16
|
+
'\\': '\\\\'
|
17
|
+
}[match[0]];
|
18
|
+
return character ? character : '\\u00' + JsUnitTest.toHexString(match[0].charCodeAt());
|
12
19
|
});
|
13
|
-
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
|
20
|
+
if (useDoubleQuotes) {return '"' + escapedString.replace(/"/g, '\\"') + '"';}
|
14
21
|
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
|
15
|
-
}
|
22
|
+
}
|
23
|
+
if (JsUnitTest.getClass(object) === 'Object') {
|
24
|
+
var keys_values = new Array(), prefix = 'Object: { ';
|
25
|
+
for (property in object) {
|
26
|
+
keys_values.push(property + ': ' + object[property]);
|
27
|
+
}
|
28
|
+
return (prefix + keys_values.join(', ') + ' }');
|
29
|
+
}
|
16
30
|
return String(object);
|
17
31
|
} catch (e) {
|
18
|
-
if (e instanceof RangeError) return '...';
|
32
|
+
if (e instanceof RangeError) {return '...';}
|
19
33
|
throw e;
|
20
34
|
}
|
21
35
|
},
|
22
|
-
|
36
|
+
|
37
|
+
getClass: function(object) {
|
38
|
+
return Object.prototype.toString.call(object)
|
39
|
+
.match(/^\[object\s(.*)\]$/)[1];
|
40
|
+
},
|
41
|
+
|
42
|
+
$: function(element) {
|
23
43
|
if (arguments.length > 1) {
|
24
|
-
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
|
44
|
+
for (var i = 0, elements = [], length = arguments.length; i < length; i++) {
|
25
45
|
elements.push(this.$(arguments[i]));
|
46
|
+
}
|
26
47
|
return elements;
|
27
48
|
}
|
28
|
-
if (typeof element == "string")
|
49
|
+
if (typeof element == "string") {
|
29
50
|
element = document.getElementById(element);
|
51
|
+
}
|
30
52
|
return element;
|
31
53
|
},
|
32
|
-
|
54
|
+
|
55
|
+
gsub: function(source, pattern, replacement) {
|
33
56
|
var result = '', match;
|
34
57
|
replacement = arguments.callee.prepareReplacement(replacement);
|
35
58
|
|
@@ -51,15 +74,48 @@ var JsUnitTest = {
|
|
51
74
|
escapeHTML: function(data) {
|
52
75
|
return data.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
53
76
|
},
|
77
|
+
toHexString : function(n) {
|
78
|
+
var string = n.toString(16);
|
79
|
+
return '00'.substring(string.length) + string;
|
80
|
+
},
|
54
81
|
arrayfromargs: function(args) {
|
55
82
|
var myarray = new Array();
|
56
83
|
var i;
|
57
84
|
|
58
|
-
for (i=0;i<args.length;i++)
|
59
|
-
|
85
|
+
for (i=0;i<args.length;i++) {
|
86
|
+
myarray[i] = args[i];
|
87
|
+
}
|
60
88
|
|
61
89
|
return myarray;
|
62
90
|
},
|
91
|
+
|
92
|
+
// from now we recursively zip & compare nested arrays
|
93
|
+
areArraysEqual: function(expected, actual) {
|
94
|
+
var expected_array = JsUnitTest.flattenArray(expected);
|
95
|
+
var actual_array = JsUnitTest.flattenArray(actual);
|
96
|
+
if (expected_array.length == actual_array.length) {
|
97
|
+
for (var i=0; i < expected_array.length; i++) {
|
98
|
+
if (expected_array[i] != actual_array[i]) {return false;}
|
99
|
+
}
|
100
|
+
return true;
|
101
|
+
}
|
102
|
+
return false;
|
103
|
+
},
|
104
|
+
|
105
|
+
areArraysNotEqual: function(expected, actual) {
|
106
|
+
return !this.areArraysEqual(expected, actual);
|
107
|
+
},
|
108
|
+
|
109
|
+
areHashesEqual: function(expected, actual) {
|
110
|
+
var expected_array = JsUnitTest.hashToSortedArray(expected);
|
111
|
+
var actual_array = JsUnitTest.hashToSortedArray(actual);
|
112
|
+
return this.areArraysEqual(expected_array, actual_array);
|
113
|
+
},
|
114
|
+
|
115
|
+
areHashesNotEqual: function(expected, actual) {
|
116
|
+
return !this.areHashesEqual(expected, actual);
|
117
|
+
},
|
118
|
+
|
63
119
|
hashToSortedArray: function(hash) {
|
64
120
|
var results = [];
|
65
121
|
for (key in hash) {
|
@@ -77,7 +133,7 @@ var JsUnitTest = {
|
|
77
133
|
} else {
|
78
134
|
results.push(object);
|
79
135
|
}
|
80
|
-
}
|
136
|
+
}
|
81
137
|
return results;
|
82
138
|
},
|
83
139
|
selectorMatch: function(expression, element) {
|
@@ -142,7 +198,7 @@ var JsUnitTest = {
|
|
142
198
|
|
143
199
|
var match = true, name, matches;
|
144
200
|
for (var i = 0, token; token = tokens[i]; i++) {
|
145
|
-
name = token[0]
|
201
|
+
name = token[0]; matches = token[1];
|
146
202
|
if (!assertions[name](element, matches)) {
|
147
203
|
match = false; break;
|
148
204
|
}
|
@@ -150,10 +206,11 @@ var JsUnitTest = {
|
|
150
206
|
|
151
207
|
return match;
|
152
208
|
},
|
209
|
+
|
153
210
|
toQueryParams: function(query, separator) {
|
154
211
|
var query = query || window.location.search;
|
155
212
|
var match = query.replace(/^\s+/, '').replace(/\s+$/, '').match(/([^?#]*)(#.*)?$/);
|
156
|
-
if (!match) return { };
|
213
|
+
if (!match) {return { };}
|
157
214
|
|
158
215
|
var hash = {};
|
159
216
|
var parts = match[1].split(separator || '&');
|
@@ -162,18 +219,20 @@ var JsUnitTest = {
|
|
162
219
|
if (pair[0]) {
|
163
220
|
var key = decodeURIComponent(pair.shift());
|
164
221
|
var value = pair.length > 1 ? pair.join('=') : pair[0];
|
165
|
-
if (value != undefined) value = decodeURIComponent(value);
|
222
|
+
if (value != undefined) {value = decodeURIComponent(value);}
|
166
223
|
|
167
224
|
if (key in hash) {
|
168
225
|
var object = hash[key];
|
169
226
|
var isArray = object != null && typeof object == "object" &&
|
170
|
-
'splice' in object && 'join' in object
|
171
|
-
if (!isArray) hash[key] = [hash[key]];
|
227
|
+
'splice' in object && 'join' in object;
|
228
|
+
if (!isArray) {hash[key] = [hash[key]];}
|
172
229
|
hash[key].push(value);
|
173
230
|
}
|
174
|
-
else
|
231
|
+
else {
|
232
|
+
hash[key] = value;
|
233
|
+
}
|
175
234
|
}
|
176
|
-
}
|
235
|
+
}
|
177
236
|
return hash;
|
178
237
|
},
|
179
238
|
|
@@ -185,7 +244,7 @@ var JsUnitTest = {
|
|
185
244
|
};
|
186
245
|
|
187
246
|
JsUnitTest.gsub.prepareReplacement = function(replacement) {
|
188
|
-
if (typeof replacement == "function") return replacement;
|
247
|
+
if (typeof replacement == "function") {return replacement;}
|
189
248
|
var template = new Template(replacement);
|
190
|
-
return function(match) { return template.evaluate(match) };
|
191
|
-
};
|
249
|
+
return function(match) { return template.evaluate(match); };
|
250
|
+
};
|