vendor/v8/test/mjsunit/mjsunit.js in mustang-0.0.1 vs vendor/v8/test/mjsunit/mjsunit.js in mustang-0.1.0

- old
+ new

@@ -39,19 +39,66 @@ * This file is included in all mini jsunit test cases. The test * framework expects lines that signal failed tests to start with * the f-word and ignore all other lines. */ +function MjsUnitToString(value) { + switch (typeof value) { + case "string": + return JSON.stringify(value); + case "number": + if (value === 0 && (1 / value) < 0) return "-0"; + case "boolean": + case "null": + case "undefined": + case "function": + return String(value); + case "object": + if (value === null) return "null"; + var clazz = Object.prototype.toString.call(value); + clazz = clazz.substring(8, clazz.length - 1); + switch (clazz) { + case "Number": + case "String": + case "Boolean": + case "Date": + return clazz + "(" + MjsUnitToString(value.valueOf()) + ")"; + case "RegExp": + return value.toString(); + case "Array": + return "[" + value.map(MjsUnitArrayElementToString).join(",") + "]"; + case "Object": + break; + default: + return clazz + "()"; + } + // [[Class]] is "Object". + var constructor = value.constructor.name; + if (name) return name + "()"; + return "Object()"; + default: + return "-- unknown value --"; + } +} + + +function MjsUnitArrayElementToString(value, index, array) { + if (value === undefined && !(index in array)) return ""; + return MjsUnitToString(value); +} + + function fail(expected, found, name_opt) { - var start; + var message = "Fail" + "ure"; if (name_opt) { // Fix this when we ditch the old test runner. - start = "Fail" + "ure (" + name_opt + "): "; - } else { - start = "Fail" + "ure:"; + message += " (" + name_opt + ")"; } - throw new MjsUnitAssertionError(start + " expected <" + expected + "> found <" + found + ">"); + + message += ": expected <" + MjsUnitToString(expected) + + "> found <" + MjsUnitToString(found) + ">"; + throw new MjsUnitAssertionError(message); } function deepObjectEquals(a, b) { var aProps = []; @@ -71,17 +118,21 @@ return true; } function deepEquals(a, b) { - if (a == b) return true; + if (a == b) { + // Check for -0. + if (a === 0 && b === 0) return (1 / a) === (1 / b); + return true; + } if (typeof a == "number" && typeof b == "number" && isNaN(a) && isNaN(b)) { return true; } if (a == null || b == null) return false; if (a.constructor === RegExp || b.constructor === RegExp) { - return (a.constructor === b.constructor) && (a.toString === b.toString); + return (a.constructor === b.constructor) && (a.toString() === b.toString()); } if ((typeof a) !== 'object' || (typeof b) !== 'object' || (a === null) || (b === null)) return false; if (a.constructor === Array) { @@ -203,10 +254,10 @@ } function assertUnreachable(name_opt) { // Fix this when we ditch the old test runner. - var message = "Fail" + "ure: unreachable" + var message = "Fail" + "ure: unreachable"; if (name_opt) { message += " - " + name_opt; } throw new MjsUnitAssertionError(message); }