Skip to content

Commit f4baca3

Browse files
authored
Merge pull request #11 from mm-gmbd/feature/blob-support
Add blob support to `_assertDeepEqual`
2 parents 3657c65 + c9c34e5 commit f4baca3

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

Diff for: src/ImpTestCase.nut

+33-3
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,51 @@ local ImpTestCase = class {
138138
throw "Possible cyclic reference at " + cleanPath(path);
139139
}
140140

141+
if (typeof value1 != typeof value2) {
142+
throw format("Values are not the same type, typeof lhs = %s, typeof rhs = %s", typeof value1, typeof value2)
143+
}
144+
141145
switch (type(value1)) {
142146
case "table":
143147
case "class":
144148
case "array":
145149

146150
foreach (k, v in value1) {
147-
path += "." + k;
151+
local extendedPath = path + "." + k;
148152

149153
if (!(k in value2)) {
150-
throw format(message, cleanPath(path),
154+
throw format(message, cleanPath(extendedPath),
151155
isForwardPass ? v + "" : "none",
152156
isForwardPass ? "none" : v + "");
153157
}
154158

155-
this._assertDeepEqual(value1[k], value2[k], message, isForwardPass, path, level + 1);
159+
this._assertDeepEqual(value1[k], value2[k], message, isForwardPass, extendedPath, level + 1);
160+
}
161+
162+
break;
163+
164+
case "meta":
165+
166+
switch(typeof value1) {
167+
case "blob":
168+
169+
if (value1.len() != value2.len()) {
170+
throw format("Blob lengths unequal, lhs.len() == %d, rhs.len() == %d", value1.len(), value2.len());
171+
}
172+
173+
if (crypto.equals(value1, value2) == false) {
174+
throw format("Blobs are the same length (%d bytes), but the contents are not identical.", value1.len());
175+
}
176+
177+
break;
178+
179+
default:
180+
181+
if (value2 != value1) {
182+
throw format(message, cleanPath(path), value1 + "", value2 + "");
183+
}
184+
185+
break;
156186
}
157187

158188
break;

0 commit comments

Comments
 (0)