From 9f1b86ab875ce0c15a571685ea93400163210781 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 24 Jun 2012 15:40:48 +0200 Subject: [PATCH] Ox.test: eval all scripts; add stringifyResult method; properly stringify actual async result; in async path, rename 'result' to 'actual' --- source/Ox/js/JavaScript.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/source/Ox/js/JavaScript.js b/source/Ox/js/JavaScript.js index 4eb6ffc6..28c70c6e 100644 --- a/source/Ox/js/JavaScript.js +++ b/source/Ox/js/JavaScript.js @@ -823,18 +823,12 @@ Ox.test = function(argument, callback) { "$1'" + statement.replace(/'/g, "\\'") + "', " ); } - if (test.expected || statement.match(/Ox\.test\./)) { - // Eval the statement, unless it's a script tag that doesn't - // add a property to Ox.test - Ox.Log('TEST', statement); - actual = eval(statement); - } + Ox.Log('TEST', statement); + actual = eval(statement); + Ox.print(JSON.stringify(actual)) if (!isAsync && test.expected) { Ox.test.data[id].results.push({ - actual: Ox.isEqual(actual, -0) ? '-0' - : Ox.isNaN(actual) ? 'NaN' - : Ox.isUndefined(actual) ? 'undefined' - : JSON.stringify(actual), + actual: stringifyResult(actual), expected: test.expected, name: item.name, section: item.section, @@ -852,6 +846,12 @@ Ox.test = function(argument, callback) { delete Ox.test.data[id]; } } + function stringifyResult(result) { + return Ox.isEqual(result, -0) ? '-0' + : Ox.isNaN(result) ? 'NaN' + : Ox.isUndefined(result) ? 'undefined' + : JSON.stringify(result); + } if (arguments.length == 2) { if (Ox.typeOf(argument) == 'string' && Ox.contains(argument, '\n')) { // source code @@ -868,7 +868,7 @@ Ox.test = function(argument, callback) { } } else { var statement = arguments[0], - result = arguments[1], + actual = arguments[1], expected = arguments[2], id, test; Ox.forEach(Ox.test.data, function(v, k) { @@ -879,9 +879,9 @@ Ox.test = function(argument, callback) { } }); Ox.test.data[id].results.push(Ox.extend(test, { - actual: result, + actual: stringifyResult(actual), statement: statement, - passed: Ox.isEqual(result, expected) + passed: Ox.isEqual(actual, expected) })); delete Ox.test.data[id].tests[statement]; if (Ox.test.data[id].done && Ox.isEmpty(Ox.test.data[id].tests)) {