JavaScript Tests - tweak compareSource for decompilation testing

git-svn-id: svn://10.0.0.236/trunk@211685 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bclary%bclary.com
2006-09-14 12:31:31 +00:00
parent e3831c522e
commit 2b1e9b3f30
4 changed files with 104 additions and 9 deletions

View File

@@ -340,15 +340,16 @@ JavaScriptOptions.prototype.reset = function ()
function compareSource(n, expect, actual)
{
// compare source
var expectP = expect.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
@@ -358,4 +359,26 @@ function compareSource(n, expect, actual)
print('actual:\n' + actualP);
TEST(n, expectP, actualP);
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
TEST(n, expectCompile, actualCompile);
}
catch(ex)
{
}
}

View File

@@ -482,15 +482,16 @@ JavaScriptOptions.prototype.reset = function ()
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
@@ -500,4 +501,27 @@ function compareSource(expect, actual, summary)
writeLineToLog('actual:\n' + actualP);
reportCompare(true, expectP === actualP, summary);
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}

View File

@@ -483,15 +483,16 @@ JavaScriptOptions.prototype.reset = function ()
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
@@ -501,4 +502,27 @@ function compareSource(expect, actual, summary)
writeLineToLog('actual:\n' + actualP);
reportCompare(true, expectP === actualP, summary);
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}

View File

@@ -489,15 +489,16 @@ JavaScriptOptions.prototype.reset = function ()
function compareSource(expect, actual, summary)
{
// compare source
var expectP = expect.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
replace(/new (\w+)\s*\(\s*\)/mg, 'new $1');
var actualP = actual.
replace(/([(){},.\[\]])/mg, ' $1 ').
replace(/([(){},.:\[\]])/mg, ' $1 ').
replace(/(\w+)/mg, ' $1 ').
replace(/<(\/)? (\w+) (\/)?>/mg, '<$1$2$3>').
replace(/\s+/mg, ' ').
@@ -506,5 +507,28 @@ function compareSource(expect, actual, summary)
writeLineToLog('expect:\n' + expectP);
writeLineToLog('actual:\n' + actualP);
reportCompare(true, expectP === actualP, summary);
reportCompare(true, expectP === actualP, summary + ': compare source');
// actual must be compilable if expect is?
try
{
var expectCompile = 'No Error';
var actualCompile;
eval(expect);
try
{
eval(actual);
actualCompile = 'No Error';
}
catch(ex1)
{
actualCompile = ex1 + '';
}
reportCompare(expectCompile, actualCompile,
summary + ': compile actual');
}
catch(ex)
{
}
}