Permalink
Browse files

Merge branch 'master' of git://github.com/smith/jsunittest into integ…

…ration
  • Loading branch information...
2 parents 26b61e0 + 8b6cc00 commit 14444b93e91eaca23982d73b2992827a394ec893 @drnic committed Mar 21, 2009
View
@@ -7,8 +7,15 @@ var JsUnitTest = {
if (typeof object == "string") {
var useDoubleQuotes = arguments[1];
var escapedString = this.gsub(object, /[\x00-\x1f\\]/, function(match) {
- var character = String.specialChar[match[0]];
- return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
+ var character = {
+ '\b': '\\b',
+ '\t': '\\t',
+ '\n': '\\n',
+ '\f': '\\f',
+ '\r': '\\r',
+ '\\': '\\\\'
+ }[match[0]];
+ return character ? character : '\\u00' + JsUnitTest.toHexString(match[0].charCodeAt());
});
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
@@ -51,6 +58,10 @@ var JsUnitTest = {
escapeHTML: function(data) {
return data.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
},
+ toHexString : function(n) {
+ var string = n.toString(16);
+ return '00'.substring(string.length) + string;
+ },
arrayfromargs: function(args) {
var myarray = new Array();
var i;
@@ -188,4 +199,4 @@ JsUnitTest.gsub.prepareReplacement = function(replacement) {
if (typeof replacement == "function") return replacement;
var template = new Template(replacement);
return function(match) { return template.evaluate(match) };
-};
+};
View
@@ -85,8 +85,13 @@ JsUnitTest.Unit.Testcase.prototype.info = function(message) {
JsUnitTest.Unit.Testcase.prototype.error = function(error, test) {
this.errors++;
- this.actions['retry with throw'] = function() { test.run(true) };
+ this.actions['retry with throw'] = function() { test.run(true); };
this.messages.push(error.name + ": "+ error.message + "(" + JsUnitTest.inspect(error) + ")");
+ if( typeof console != "undefined" && console.error) {
+ console.error("Test '" + test.name + "' died, exception and test follows");
+ console.error(error);
+ console.error(test.test.toString());
+ }
};
JsUnitTest.Unit.Testcase.prototype.status = function() {
@@ -82,6 +82,9 @@
assertEqual("a", "a");
assertEqual("a", "a", "test");
+ assertEqual("A\nnew line", "A\nnew line", "New lines");
+ assertEqual("A\x18special char", "A\x18special char", "Other special char");
+
assertNotEqual(0, 1);
assertNotEqual("a","b");
assertNotEqual({},{});
View
@@ -51,11 +51,19 @@
var expected = [ 'a', 1, 'b', 2, 'zzz', 1, 2, 3];
var actual = JsUnitTest.flattenArray(original);
assertEnumEqual(expected, actual);
+ }},
+ testToHexString: function() { with(this) {
+ assertEqual('01', JsUnitTest.toHexString(1));
+ assertEqual('0f', JsUnitTest.toHexString(15));
+ assertEqual('f0', JsUnitTest.toHexString(240));
+ assertEqual('ff', JsUnitTest.toHexString(255));
}}
+
+
});
// ]]>
</script>
</body>
-</html>
+</html>
@@ -82,7 +82,7 @@
logger.start("test 1");
logger.summary("some summary");
assertMatch(/some\ssummary/, testlog_test.innerHTML);
- }},
+ }}
@@ -95,4 +95,4 @@
// ]]>
</script>
</body>
-</html>
+</html>
@@ -34,11 +34,11 @@
testBuildMessage: function() {
this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
// this.assertEqual("<'foo'> 'bar'", this.buildMessage('', '<?> ?', 'foo', 'bar'))
- },
+ }
});
// ]]>
</script>
</body>
-</html>
+</html>
@@ -67,11 +67,11 @@
assertEqual(0, results.failures);
assertEqual(0, results.warnings);
assertEqual("2 tests, 2 assertions, 0 failures, 0 errors, 0 warnings", runner.summary());
- }},
+ }}
});
// ]]>
</script>
</body>
-</html>
+</html>
@@ -47,11 +47,11 @@
var pattern = /(^|.|\r|\n)(#\((.*?)\))/;
assertEqual('#{name}: Stephan', new JsUnitTest.Template('\\#{name}: #{name}').evaluate(subject));
assertEqual('#(name): Stephan', new JsUnitTest.Template('\\#(name): #(name)', pattern).evaluate(subject));
- }},
+ }}
});
// ]]>
</script>
</body>
-</html>
+</html>
@@ -83,15 +83,36 @@
// Error
testError: function() { with(this) {
- testcase.error({name: "name", message: "An Error"});
+ testcase.error({name: "name", message: "An Error"}, testcase);
assertEqual(0, testcase.assertions, "Assertions");
assertEqual(1, testcase.errors, "Errors");
assertEqual("name: An Error([object Object])", testcase.messages[0], 'Should be equal');
assertEqual('error', testcase.status(), 'Should be equal');
}},
+
+ testErrorOnFirebug : function() { with(this) {
+ var results = [];
+ var orig_console = window.console;
+ try {
+ // we need to delete the firebug console on Firefox
+ // but the delete statement fails on IE
+ delete window.console;
+ } catch(e) {};
+ window.console = {
+ error: function(s) {
+ results.push(s);
+ }
+ };
+ testcase.error({name: "name", message: "An Error"}, testcase);
+ var fn = function() {};
+ assertEqual("Test 'name' died, exception and test follows", results[0]);
+ assertEqual(fn.toString(), results[2]);
+ assertHashEqual({ message: 'An Error', name: 'name' }, results[1]);
+ window.console = orig_console;
+ }}
});
// ]]>
</script>
</body>
-</html>
+</html>

0 comments on commit 14444b9

Please sign in to comment.