Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/tests/test_setup.js
Show All 12 Lines | function fail(msg) | ||||
trace = trace.splice(2); | trace = trace.splice(2); | ||||
trace = "Stack trace:\n" + trace.join("\n"); | trace = "Stack trace:\n" + trace.join("\n"); | ||||
Engine.TS_FAIL(trace + msg); | Engine.TS_FAIL(trace + msg); | ||||
} | } | ||||
global.TS_FAIL = function TS_FAIL(msg) | global.TS_FAIL = function TS_FAIL(msg) | ||||
{ | { | ||||
fail(msg); | fail(msg); | ||||
} | }; | ||||
global.TS_ASSERT = function TS_ASSERT(e) | global.TS_ASSERT = function TS_ASSERT(e) | ||||
{ | { | ||||
if (!e) | if (!e) | ||||
fail("Assert failed"); | fail("Assert failed"); | ||||
} | }; | ||||
global.TS_ASSERT_EQUALS = function TS_ASSERT_EQUALS(x, y) | global.TS_ASSERT_EQUALS = function TS_ASSERT_EQUALS(x, y) | ||||
{ | { | ||||
if (!(x === y)) | if (!(x === y)) | ||||
fail("Expected equal, got "+uneval(x)+" !== "+uneval(y)); | fail("Expected equal, got "+uneval(x)+" !== "+uneval(y)); | ||||
} | }; | ||||
global.TS_ASSERT_EQUALS_APPROX = function TS_ASSERT_EQUALS_APPROX(x, y, maxDifference) | global.TS_ASSERT_EQUALS_APPROX = function TS_ASSERT_EQUALS_APPROX(x, y, maxDifference) | ||||
{ | { | ||||
TS_ASSERT_NUMBER(maxDifference); | TS_ASSERT_NUMBER(maxDifference); | ||||
if (Math.abs(x - y) > maxDifference) | if (Math.abs(x - y) > maxDifference) | ||||
fail("Expected almost equal, got " + uneval(x) + " !== " + uneval(y)); | fail("Expected almost equal, got " + uneval(x) + " !== " + uneval(y)); | ||||
} | }; | ||||
global.TS_ASSERT_UNEVAL_EQUALS = function TS_ASSERT_UNEVAL_EQUALS(x, y) | global.TS_ASSERT_UNEVAL_EQUALS = function TS_ASSERT_UNEVAL_EQUALS(x, y) | ||||
{ | { | ||||
if (!(uneval(x) === uneval(y))) | if (!(uneval(x) === uneval(y))) | ||||
fail("Expected equal, got "+uneval(x)+" !== "+uneval(y)); | fail("Expected equal, got "+uneval(x)+" !== "+uneval(y)); | ||||
} | }; | ||||
global.TS_ASSERT_EXCEPTION = function(func) | global.TS_ASSERT_EXCEPTION = function(func) | ||||
{ | { | ||||
try { | try { | ||||
func(); | func(); | ||||
Engine.TS_FAIL("Missed exception at:\n" + new Error().stack); | Engine.TS_FAIL("Missed exception at:\n" + new Error().stack); | ||||
} catch (e) { | } catch (e) { | ||||
} | } | ||||
} | }; | ||||
global.TS_ASSERT_NUMBER = function(value) | global.TS_ASSERT_NUMBER = function(value) | ||||
{ | { | ||||
if (typeof value != "number" || !isFinite(value)) | if (typeof value != "number" || !isFinite(value)) | ||||
fail("The given value must be a real number!"); | fail("The given value must be a real number!"); | ||||
} | }; |
Wildfire Games · Phabricator