Add regex comparison to test driver.

This commit is contained in:
Ingvar Stepanyan
2015-01-23 13:50:01 +02:00
parent e6f1e1027e
commit cb94a0851c
3 changed files with 32 additions and 29 deletions

View File

@@ -66,7 +66,7 @@
}
};
function ppJSON(v) { return JSON.stringify(v, null, 2); }
function ppJSON(v) { return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2); }
function addPath(str, pt) {
if (str.charAt(str.length-1) == ")")
return str.slice(0, str.length-1) + "/" + pt + ")";
@@ -76,6 +76,9 @@
var misMatch = exports.misMatch = function(exp, act) {
if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {
if (exp !== act) return ppJSON(exp) + " !== " + ppJSON(act);
} else if (exp instanceof RegExp || act instanceof RegExp) {
var left = ppJSON(exp), right = ppJSON(act);
if (left !== right) return left + " !== " + right;
} else if (exp.splice) {
if (!act.slice) return ppJSON(exp) + " != " + ppJSON(act);
if (act.length != exp.length) return "array length mismatch " + exp.length + " != " + act.length;