diff options
author | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-05-15 10:46:54 +0200 |
---|---|---|
committer | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-05-16 07:37:14 +0200 |
commit | 26476d2bd113da46c08bb99cb298f923267be88f (patch) | |
tree | 710ecef09be14e125923d72921881215a19e47a4 /tests | |
parent | a7260a4b6a82b25642da26854e6e8199220cd1d3 (diff) |
make it possible to compare arrays from the C++ side
Change-Id: I3cb0ae4c3648a4c61e5e2bbe1cca442814ee5161
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test.js | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tests/test.js b/tests/test.js index 5202f5c..960c5d8 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,6 +1,7 @@ var TEST_JS_LOADED // Purposfully left undefined - this is to avoid the global variables being loaded more than once if (TEST_JS_LOADED == undefined) { TEST_JS_LOADED = true + // Set to true to print out every single comparison var verbose = false @@ -25,21 +26,40 @@ if (TEST_JS_LOADED == undefined) { } } - function compare(act, exp, message) { + function logCompare(act,exp,message) { if ( verbose ) { if ( message != undefined ) console.log("comparing(" + message + ") " + act + " with " + exp) else console.log("comparing " + act + " with " + exp) } - if (act != exp) { - if ( message != undefined ) - error("Compare failed (" + message +"): actual=" + act + " expected=" + exp) - else - error("Compare failed: actual=" + act + " expected=" + exp) + } + + function failCompare(act,exp,message) { + if ( message != undefined ) + error("Compare failed (" + message +"): actual=" + act + " expected=" + exp) + else + error("Compare failed: actual=" + act + " expected=" + exp) + } + + function compareArrays(act, exp, message) { + logCompare(act,exp,message) + if (act.length != exp.length) + failCompare(act,exp,message) + for (var i=0; i<act.length; ++i) { + if (act[i] != exp[i]) { + failCompare(act,exp,message) + break + } } } + function compare(act, exp, message) { + logCompare(act,exp,message) + if (act != exp) + failCompare(act,exp,message) + } + function comparePositions(act, exp, message) { compare(act.line, exp.line, message) compare(act.column, exp.column, message) |