Permalink
Browse files

linting.

  • Loading branch information...
1 parent a774b95 commit 5699afebc1e42e7bd2bfc65f1dc39b7c878f318c @olleolleolle olleolleolle committed Apr 6, 2009
Showing with 94 additions and 85 deletions.
  1. +2 −1 src/ajax.js
  2. +31 −30 src/assertions.js
  3. +27 −22 src/common.js
  4. +6 −6 src/logger.js
  5. +1 −1 src/message_template.js
  6. +2 −2 src/prototype/event.js
  7. +7 −6 src/prototype/template.js
  8. +13 −12 src/runner.js
  9. +5 −5 src/test_case.js
View
3 src/ajax.js
@@ -111,8 +111,9 @@ JsUnitTest.ajax = function( options ) {
// If the specified type is "script", execute the returned text
// response as if it was JavaScript
- if ( type == "script" )
+ if ( type == "script" ) {
eval.call( window, data );
+ }
// Return the response data (either an XML Document or a text string)
return data;
View
61 src/assertions.js
@@ -6,98 +6,98 @@ JsUnitTest.Unit.Assertions = {
},
flunk: function(message) {
- this.assertBlock(message || 'Flunked', function() { return false });
+ this.assertBlock(message || 'Flunked', function() { return false; });
},
assertBlock: function(message, block) {
try {
block.call(this) ? this.pass() : this.fail(message);
- } catch(e) { this.error(e) }
+ } catch(e) { this.error(e); }
},
assert: function(expression, message) {
message = this.buildMessage(message || 'assert', 'got <?>', expression);
- this.assertBlock(message, function() { return expression });
+ this.assertBlock(message, function() { return expression; });
},
assertEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertEqual', 'expected <?>, actual: <?>', expected, actual);
- this.assertBlock(message, function() { return expected == actual });
+ this.assertBlock(message, function() { return expected == actual; });
},
assertNotEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertNotEqual', 'expected <?>, actual: <?>', expected, actual);
- this.assertBlock(message, function() { return expected != actual });
+ this.assertBlock(message, function() { return expected != actual; });
},
assertEnumEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertEnumEqual', 'expected <?>, actual: <?>', expected, actual);
- this.assertBlock(message, function() { return JsUnitTest.areArraysEqual(expected, actual) });
+ this.assertBlock(message, function() { return JsUnitTest.areArraysEqual(expected, actual); });
},
assertEnumNotEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertEnumNotEqual', '<?> was the same as <?>', expected, actual);
- this.assertBlock(message, function() { return JsUnitTest.areArraysNotEqual(expected, actual) });
+ this.assertBlock(message, function() { return JsUnitTest.areArraysNotEqual(expected, actual); });
},
assertHashEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertHashEqual', 'expected <?>, actual: <?>', JsUnitTest.inspect(expected), JsUnitTest.inspect(actual));
- this.assertBlock(message, function() { return JsUnitTest.areHashesEqual(expected, actual) });
+ this.assertBlock(message, function() { return JsUnitTest.areHashesEqual(expected, actual); });
},
assertHashNotEqual: function(expected, actual, message) {
message = this.buildMessage(message || 'assertHashNotEqual', '<?> was the same as <?>', JsUnitTest.inspect(expected), JsUnitTest.inspect(actual));
- this.assertBlock(message, function() { return JsUnitTest.areHashesNotEqual(expected, actual) });
+ this.assertBlock(message, function() { return JsUnitTest.areHashesNotEqual(expected, actual); });
},
assertIdentical: function(expected, actual, message) {
message = this.buildMessage(message || 'assertIdentical', 'expected <?>, actual: <?>', expected, actual);
- this.assertBlock(message, function() { return expected === actual });
+ this.assertBlock(message, function() { return expected === actual; });
},
assertNotIdentical: function(expected, actual, message) {
message = this.buildMessage(message || 'assertNotIdentical', 'expected <?>, actual: <?>', expected, actual);
- this.assertBlock(message, function() { return expected !== actual });
+ this.assertBlock(message, function() { return expected !== actual; });
},
assertNull: function(obj, message) {
message = this.buildMessage(message || 'assertNull', 'got <?>', obj);
- this.assertBlock(message, function() { return obj === null });
+ this.assertBlock(message, function() { return obj === null; });
},
assertNotNull: function(obj, message) {
message = this.buildMessage(message || 'assertNotNull', 'got <?>', obj);
- this.assertBlock(message, function() { return obj !== null });
+ this.assertBlock(message, function() { return obj !== null; });
},
assertUndefined: function(obj, message) {
message = this.buildMessage(message || 'assertUndefined', 'got <?>', obj);
- this.assertBlock(message, function() { return typeof obj == "undefined" });
+ this.assertBlock(message, function() { return typeof obj == "undefined"; });
},
assertNotUndefined: function(obj, message) {
message = this.buildMessage(message || 'assertNotUndefined', 'got <?>', obj);
- this.assertBlock(message, function() { return typeof obj != "undefined" });
+ this.assertBlock(message, function() { return typeof obj != "undefined"; });
},
assertNullOrUndefined: function(obj, message) {
message = this.buildMessage(message || 'assertNullOrUndefined', 'got <?>', obj);
- this.assertBlock(message, function() { return obj == null });
+ this.assertBlock(message, function() { return obj == null; });
},
assertNotNullOrUndefined: function(obj, message) {
message = this.buildMessage(message || 'assertNotNullOrUndefined', 'got <?>', obj);
- this.assertBlock(message, function() { return obj != null });
+ this.assertBlock(message, function() { return obj != null; });
},
assertMatch: function(expected, actual, message) {
message = this.buildMessage(message || 'assertMatch', 'regex <?> did not match <?>', expected, actual);
- this.assertBlock(message, function() { return new RegExp(expected).exec(actual) });
+ this.assertBlock(message, function() { return new RegExp(expected).exec(actual); });
},
assertNoMatch: function(expected, actual, message) {
message = this.buildMessage(message || 'assertNoMatch', 'regex <?> matched <?>', expected, actual);
- this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) });
+ this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)); });
},
assertHasClass: function(element, klass, message) {
@@ -124,22 +124,22 @@ JsUnitTest.Unit.Assertions = {
assertHidden: function(element, message) {
element = JsUnitTest.$(element);
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
- this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
+ this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none'; });
},
assertInstanceOf: function(expected, actual, message) {
message = this.buildMessage(message || 'assertInstanceOf', '<?> was not an instance of the expected type', actual);
- this.assertBlock(message, function() { return actual instanceof expected });
+ this.assertBlock(message, function() { return actual instanceof expected; });
},
assertNotInstanceOf: function(expected, actual, message) {
message = this.buildMessage(message || 'assertNotInstanceOf', '<?> was an instance of the expected type', actual);
- this.assertBlock(message, function() { return !(actual instanceof expected) });
+ this.assertBlock(message, function() { return !(actual instanceof expected); });
},
assertRespondsTo: function(method, obj, message) {
message = this.buildMessage(message || 'assertRespondsTo', 'object doesn\'t respond to <?>', method);
- this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function') });
+ this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function'); });
},
assertRaise: function(exceptionName, method, message) {
@@ -149,8 +149,8 @@ JsUnitTest.Unit.Assertions = {
method();
return false;
} catch(e) {
- if (e.name == exceptionName) return true;
- else throw e;
+ if (e.name == exceptionName) {return true;}
+ else {throw e;}
}
};
this.assertBlock(message, block);
@@ -168,22 +168,23 @@ JsUnitTest.Unit.Assertions = {
_isVisible: function(element) {
element = JsUnitTest.$(element);
- if(!element.parentNode) return true;
+ if(!element.parentNode) {return true;}
this.assertNotNull(element);
- if(element.style && (element.style.display == 'none'))
+ if(element.style && (element.style.display == 'none')) {
return false;
+ }
return arguments.callee.call(this, element.parentNode);
},
assertVisible: function(element, message) {
message = this.buildMessage(message, '? was not visible.', element);
- this.assertBlock(message, function() { return this._isVisible(element) });
+ this.assertBlock(message, function() { return this._isVisible(element); });
},
assertNotVisible: function(element, message) {
message = this.buildMessage(message, '? was not hidden and didn\'t have a hidden parent either.', element);
- this.assertBlock(message, function() { return !this._isVisible(element) });
+ this.assertBlock(message, function() { return !this._isVisible(element); });
},
assertElementsMatch: function() {
@@ -204,7 +205,7 @@ JsUnitTest.Unit.Assertions = {
message = this.buildMessage('assertElementsMatch', 'In index <?>: expected <?> but got ?', index, expression, element);
this.flunk(message);
pass = false;
- };
+ }
this.assert(pass, "Expected all elements to match.");
},
View
49 src/common.js
@@ -2,8 +2,8 @@ var JsUnitTest = {
Unit: {},
inspect: function(object) {
try {
- if (typeof object == "undefined") return 'undefined';
- if (object === null) return 'null';
+ if (typeof object == "undefined") {return 'undefined';}
+ if (object === null) {return 'null';}
if (typeof object == "string") {
var useDoubleQuotes = arguments[1];
var escapedString = this.gsub(object, /[\x00-\x1f\\]/, function(match) {
@@ -17,9 +17,9 @@ var JsUnitTest = {
}[match[0]];
return character ? character : '\\u00' + JsUnitTest.toHexString(match[0].charCodeAt());
});
- if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
+ if (useDoubleQuotes) {return '"' + escapedString.replace(/"/g, '\\"') + '"';}
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
- };
+ }
if (JsUnitTest.getClass(object) === 'Object') {
var keys_values = new Array(), prefix = 'Object: { ';
for (property in object) {
@@ -29,7 +29,7 @@ var JsUnitTest = {
}
return String(object);
} catch (e) {
- if (e instanceof RangeError) return '...';
+ if (e instanceof RangeError) {return '...';}
throw e;
}
},
@@ -41,12 +41,14 @@ var JsUnitTest = {
$: function(element) {
if (arguments.length > 1) {
- for (var i = 0, elements = [], length = arguments.length; i < length; i++)
+ for (var i = 0, elements = [], length = arguments.length; i < length; i++) {
elements.push(this.$(arguments[i]));
+ }
return elements;
}
- if (typeof element == "string")
+ if (typeof element == "string") {
element = document.getElementById(element);
+ }
return element;
},
@@ -80,8 +82,9 @@ var JsUnitTest = {
var myarray = new Array();
var i;
- for (i=0;i<args.length;i++)
- myarray[i] = args[i];
+ for (i=0;i<args.length;i++) {
+ myarray[i] = args[i];
+ }
return myarray;
},
@@ -92,8 +95,8 @@ var JsUnitTest = {
var actual_array = JsUnitTest.flattenArray(actual);
if (expected_array.length == actual_array.length) {
for (var i=0; i < expected_array.length; i++) {
- if (expected_array[i] != actual_array[i]) return false;
- };
+ if (expected_array[i] != actual_array[i]) {return false;}
+ }
return true;
}
return false;
@@ -130,7 +133,7 @@ var JsUnitTest = {
} else {
results.push(object);
}
- };
+ }
return results;
},
selectorMatch: function(expression, element) {
@@ -195,7 +198,7 @@ var JsUnitTest = {
var match = true, name, matches;
for (var i = 0, token; token = tokens[i]; i++) {
- name = token[0], matches = token[1];
+ name = token[0]; matches = token[1];
if (!assertions[name](element, matches)) {
match = false; break;
}
@@ -204,10 +207,10 @@ var JsUnitTest = {
return match;
},
- toQueryParams: function(query, separator) {
+ toQueryParams: function(query, separator) {
var query = query || window.location.search;
var match = query.replace(/^\s+/, '').replace(/\s+$/, '').match(/([^?#]*)(#.*)?$/);
- if (!match) return { };
+ if (!match) {return { };}
var hash = {};
var parts = match[1].split(separator || '&');
@@ -216,18 +219,20 @@ var JsUnitTest = {
if (pair[0]) {
var key = decodeURIComponent(pair.shift());
var value = pair.length > 1 ? pair.join('=') : pair[0];
- if (value != undefined) value = decodeURIComponent(value);
+ if (value != undefined) {value = decodeURIComponent(value);}
if (key in hash) {
var object = hash[key];
var isArray = object != null && typeof object == "object" &&
- 'splice' in object && 'join' in object
- if (!isArray) hash[key] = [hash[key]];
+ 'splice' in object && 'join' in object;
+ if (!isArray) {hash[key] = [hash[key]];}
hash[key].push(value);
}
- else hash[key] = value;
+ else {
+ hash[key] = value;
+ }
}
- };
+ }
return hash;
},
@@ -239,7 +244,7 @@ var JsUnitTest = {
};
JsUnitTest.gsub.prepareReplacement = function(replacement) {
- if (typeof replacement == "function") return replacement;
+ if (typeof replacement == "function") {return replacement;}
var template = new Template(replacement);
- return function(match) { return template.evaluate(match) };
+ return function(match) { return template.evaluate(match); };
};
View
12 src/logger.js
@@ -1,10 +1,10 @@
JsUnitTest.Unit.Logger = function(element) {
this.element = JsUnitTest.$(element);
- if (this.element) this._createLogTable();
+ if (this.element) {this._createLogTable();}
};
JsUnitTest.Unit.Logger.prototype.start = function(testName) {
- if (!this.element) return;
+ if (!this.element) {return;}
var tbody = this.element.getElementsByTagName('tbody')[0];
var tr = document.createElement('tr');
@@ -13,7 +13,7 @@ JsUnitTest.Unit.Logger.prototype.start = function(testName) {
//testname
td = document.createElement('td');
td.appendChild(document.createTextNode(testName));
- tr.appendChild(td)
+ tr.appendChild(td);
tr.appendChild(document.createElement('td'));//status
tr.appendChild(document.createElement('td'));//message
@@ -29,21 +29,21 @@ JsUnitTest.Unit.Logger.prototype.setStatus = function(status) {
};
JsUnitTest.Unit.Logger.prototype.finish = function(status, summary) {
- if (!this.element) return;
+ if (!this.element) {return;}
this.setStatus(status);
this.message(summary);
};
JsUnitTest.Unit.Logger.prototype.message = function(message) {
- if (!this.element) return;
+ if (!this.element) {return;}
var cell = this.getMessageCell();
// cell.appendChild(document.createTextNode(this._toHTML(message)));
cell.innerHTML = this._toHTML(message);
};
JsUnitTest.Unit.Logger.prototype.summary = function(summary) {
- if (!this.element) return;
+ if (!this.element) {return;}
var div = this.element.getElementsByTagName('div')[0];
div.innerHTML = this._toHTML(summary);
};
View
2 src/message_template.js
@@ -12,6 +12,6 @@ JsUnitTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
var part = this.parts[i];
var result = (part == '?') ? JsUnitTest.inspect(params.shift()) : part.replace(/\\\?/, '?');
results.push(result);
- };
+ }
return results.join('');
};
View
4 src/prototype/event.js
@@ -10,9 +10,9 @@ JsUnitTest.Event.addEvent = function(element, type, handler) {
element.addEventListener(type, handler, false);
} else {
// assign each event handler a unique ID
- if (!handler.$$guid) handler.$$guid = JsUnitTest.Event.addEvent.guid++;
+ if (!handler.$$guid) {handler.$$guid = JsUnitTest.Event.addEvent.guid++;}
// create a hash table of event types for the element
- if (!element.events) element.events = {};
+ if (!element.events) {element.events = {};}
// create a hash table of event handlers for each element/event pair
var handlers = element.events[type];
if (!handlers) {
View
13 src/prototype/template.js
@@ -4,30 +4,31 @@ JsUnitTest.Template = function(template, pattern) {
};
JsUnitTest.Template.prototype.evaluate = function(object) {
- if (typeof object.toTemplateReplacements == "function")
+ if (typeof object.toTemplateReplacements == "function") {
object = object.toTemplateReplacements();
+ }
return JsUnitTest.gsub(this.template, this.pattern, function(match) {
- if (object == null) return '';
+ if (object == null) {return '';}
var before = match[1] || '';
- if (before == '\\') return match[2];
+ if (before == '\\') {return match[2];}
var ctx = object, expr = match[3];
var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
match = pattern.exec(expr);
- if (match == null) return before;
+ if (match == null) {return before;}
while (match != null) {
var comp = (match[1].indexOf('[]') === 0) ? match[2].gsub('\\\\]', ']') : match[1];
ctx = ctx[comp];
- if (null == ctx || '' == match[3]) break;
+ if (null == ctx || '' == match[3]) {break;}
expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
match = pattern.exec(expr);
}
return before + JsUnitTest.String.interpret(ctx);
});
-}
+};
JsUnitTest.Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
View
25 src/runner.js
@@ -23,30 +23,31 @@ JsUnitTest.Unit.Runner.prototype.portNumber = function() {
if (window.location.search.length > 0) {
var matches = window.location.search.match(/\:(\d{3,5})\//);
if (matches) {
- return parseInt(matches[1]);
+ return parseInt(matches[1], 10);
}
}
return null;
};
JsUnitTest.Unit.Runner.prototype.getTests = function(testcases) {
var tests = [], options = this.options;
- if (this.queryParams.tests) tests = this.queryParams.tests.split(',');
- else if (options.tests) tests = options.tests;
- else if (options.test) tests = [option.test];
+ if (this.queryParams.tests) {tests = this.queryParams.tests.split(',');}
+ else if (options.tests) {tests = options.tests;}
+ else if (options.test) {tests = [option.test];}
else {
for (testname in testcases) {
- if (testname.match(/^test/)) tests.push(testname);
+ if (testname.match(/^test/)) {tests.push(testname);}
}
}
var results = [];
for (var i=0; i < tests.length; i++) {
var test = tests[i];
- if (testcases[test])
+ if (testcases[test]) {
results.push(
new JsUnitTest.Unit.Testcase(test, testcases[test], testcases.setup, testcases.teardown)
);
- };
+ }
+ }
return results;
};
@@ -65,7 +66,7 @@ JsUnitTest.Unit.Runner.prototype.getResult = function() {
results.failures += test.failures;
results.errors += test.errors;
results.warnings += test.warnings;
- };
+ }
return results;
};
@@ -83,15 +84,15 @@ JsUnitTest.Unit.Runner.prototype.postResults = function() {
JsUnitTest.ajax({
url: url,
type: 'GET'
- })
+ });
}
};
JsUnitTest.Unit.Runner.prototype.runTests = function() {
var test = this.tests[this.currentTest], actions;
- if (!test) return this.finish();
- if (!test.isWaiting) this.logger.start(test.name);
+ if (!test) {return this.finish();}
+ if (!test.isWaiting) {this.logger.start(test.name);}
test.run();
var self = this;
if(test.isWaiting) {
@@ -104,7 +105,7 @@ JsUnitTest.Unit.Runner.prototype.runTests = function() {
}
this.logger.finish(test.status(), test.summary());
- if (actions = test.actions) this.logger.appendActionButtons(actions);
+ if (actions = test.actions) {this.logger.appendActionButtons(actions);}
this.currentTest++;
// tail recursive, hopefully the browser will skip the stackframe
this.runTests();
View
10 src/test_case.js
@@ -31,7 +31,7 @@ JsUnitTest.Unit.Testcase.prototype.wait = function(time, nextPart) {
JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
try {
try {
- if (!this.isWaiting) this.setup();
+ if (!this.isWaiting) {this.setup();}
this.isWaiting = false;
this.test();
} finally {
@@ -41,7 +41,7 @@ JsUnitTest.Unit.Testcase.prototype.run = function(rethrow) {
}
}
catch(e) {
- if (rethrow) throw e;
+ if (rethrow) {throw e;}
this.error(e, this);
}
};
@@ -95,9 +95,9 @@ JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
};
JsUnitTest.Unit.Testcase.prototype.status = function() {
- if (this.failures > 0) return 'failed';
- if (this.errors > 0) return 'error';
- if (this.warnings > 0) return 'warning';
+ if (this.failures > 0) {return 'failed';}
+ if (this.errors > 0) {return 'error';}
+ if (this.warnings > 0) {return 'warning';}
return 'passed';
};

0 comments on commit 5699afe

Please sign in to comment.