Permalink
Browse files

Remove dependance on prototype toPaddedString; added method toHexStri…

…ng; changed the call; added tests
  • Loading branch information...
1 parent 7a543ab commit 5127895dae537debd9c71118c236cbad71c9ad1f @choan choan committed Nov 4, 2008
Showing with 16 additions and 3 deletions.
  1. +5 −1 src/common.js
  2. +2 −1 test/unit/assertions_test.html
  3. +9 −1 test/unit/common_test.html
View
@@ -15,7 +15,7 @@ var JsUnitTest = {
'\r': '\\r',
'\\': '\\\\'
}[match[0]];
- return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
+ return character ? character : '\\u00' + JsUnitTest.toHexString(match[0].charCodeAt());
});
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
@@ -58,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,7 +82,8 @@
assertEqual("a", "a");
assertEqual("a", "a", "test");
- assertEqual("A\nnew line", "A\nnew line", "Special characters");
+ 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");
@@ -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 5127895

Please sign in to comment.