Permalink
Browse files

Merge branch 'master' into better_errors

  • Loading branch information...
2 parents af24617 + 5127895 commit b3d23168faa8066b886b0c287eed22e39d84d74f @choan choan committed Nov 29, 2008
Showing with 25 additions and 3 deletions.
  1. +13 −2 src/common.js
  2. +3 −0 test/unit/assertions_test.html
  3. +9 −1 test/unit/common_test.html
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;
@@ -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,7 +51,15 @@
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));
+ }},
+
+
});

0 comments on commit b3d2316

Please sign in to comment.