blob: a0471778d6fd017ce1e5ad55bfb6837ecb9f95cd [file] [log] [blame]
// Checks that |a_orig| and |b_orig| are:
// 1. Both instances of |type|, and
// 2. Are structurally equivalent (as dictated by the structure of |type|).
function assertTypedEqual(type, a_orig, b_orig) {
try {
recur(type, a_orig, b_orig);
} catch (e) {
print("failure during "+
"assertTypedEqual("+type.toSource()+", "+a_orig.toSource()+", "+b_orig.toSource()+")");
throw e;
}
function recur(type, a, b) {
if (type instanceof ArrayType) {
assertEq(a.length, type.length);
assertEq(b.length, type.length);
for (var i = 0; i < type.length; i++)
recur(type.elementType, a[i], b[i]);
} else if (type instanceof StructType) {
var fieldNames = Object.getOwnPropertyNames(type.fieldTypes);
for (var i = 0; i < fieldNames.length; i++) {
var fieldName = fieldNames[i];
recur(type.fieldTypes[fieldName], a[fieldName], b[fieldName]);
}
} else {
assertEq(a, b);
}
}
}