Skip to content

Commit

Permalink
Update dist
Browse files Browse the repository at this point in the history
  • Loading branch information
myurasov committed Mar 17, 2016
1 parent 037fce5 commit dd6a851
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions dist/impUnit.nut
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* impUnit Test Framework
*
* @author Mikhail Yurasov <[email protected]>
* @version 0.4.1
* @version 0.4.2
* @package ImpUnit
*/

Expand Down Expand Up @@ -515,37 +515,36 @@ local ImpTestCase = class {

/**
* Perform a deep comparison of two values
* Useful for comparing arrays or tables
* @param {*} expected
* @param {*} actual
* @param {*} value1
* @param {*} value2
* @param {string} message
* @param {boolean} isForwardPass - on forward pass value1 is treated "expected", value2 as "actual" and vice-versa on backward pass
* @param {string} path - current slot path
* @param {int} level - current depth level
* @private
*/
function assertDeepEqual(expected, actual, message = "At [%s]: expected \"%s\", got \"%s\"", path = "", level = 0) {

if (0 == level) {
this.assertions++;
}

function _assertDeepEqual(value1, value2, message, isForwardPass, path = "", level = 0) {
local cleanPath = @(p) p.len() == 0 ? p : p.slice(1);

if (level > 32) {
throw "Possible cyclic reference at " + cleanPath(path);
}

switch (type(actual)) {
switch (type(value1)) {
case "table":
case "class":
case "array":

foreach (k, v in expected) {
foreach (k, v in value2) {

path += "." + k;

if (!(k in actual)) {
throw format("Missing slot [%s] in actual value", cleanPath(path));
if (!(k in value1)) {
throw format("%s slot [%s] in actual value",
isForwardPass ? "Missing" : "Extra", cleanPath(path));
}

this.assertDeepEqual(expected[k], actual[k], message, path, level + 1);
this._assertDeepEqual(value2[k], value1[k], message, isForwardPass, path, level + 1);
}

break;
Expand All @@ -554,14 +553,27 @@ local ImpTestCase = class {
break;

default:
if (expected != actual) {
throw format(message, cleanPath(path), expected + "", actual + "");
if (value2 != value1) {
throw format(message, cleanPath(path), value2 + "", value1 + "");
}

break;
}
}

/**
* Perform a deep comparison of two values
* Useful for comparing arrays or tables
* @param {*} expected
* @param {*} actual
* @param {string} message
*/
function assertDeepEqual(expected, actual, message = "At [%s]: expected \"%s\", got \"%s\"") {
this.assertions++;
this._assertDeepEqual(expected, actual, message, true); // forward pass
this._assertDeepEqual(actual, expected, message, false); // backwards pass
}

/**
* Assert that the value is between min amd max
* @param {number|*} actual
Expand Down

0 comments on commit dd6a851

Please sign in to comment.