Skip to content

Add blob support to _assertDeepEqual #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 9, 2021
36 changes: 33 additions & 3 deletions src/ImpTestCase.nut
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,51 @@ local ImpTestCase = class {
throw "Possible cyclic reference at " + cleanPath(path);
}

if (typeof value1 != typeof value2) {
throw format("Values are not the same type, typeof lhs = %s, typeof rhs = %s", typeof value1, typeof value2)
}

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

foreach (k, v in value1) {
path += "." + k;
local extendedPath = path + "." + k;

if (!(k in value2)) {
throw format(message, cleanPath(path),
throw format(message, cleanPath(extendedPath),
isForwardPass ? v + "" : "none",
isForwardPass ? "none" : v + "");
}

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

break;

case "meta":

switch(typeof value1) {
case "blob":

if (value1.len() != value2.len()) {
throw format("Blob lengths unequal, lhs.len() == %d, rhs.len() == %d", value1.len(), value2.len());
}

if (crypto.equals(value1, value2) == false) {
throw format("Blobs are the same length (%d bytes), but the contents are not identical.", value1.len());
}

break;

default:

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

break;
}

break;
Expand Down