mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1345769 - Part 5: Move compareSource's source code normalization to the one remaining test which needs it. r=arai
--HG-- extra : rebase_source : 5b99a2f625108e98ab6efb519d2f2d4d726488c5
This commit is contained in:
parent
fcb085bf11
commit
30d3752f7d
@ -9,6 +9,13 @@ var summary = 'uneval(eval(expression closure))';
|
||||
var actual = 'No Crash';
|
||||
var expect = 'No Crash';
|
||||
|
||||
function normalizeSource(source) {
|
||||
source = String(source);
|
||||
source = source.replace(/([(){},.:\[\]])/mg, ' $1 ');
|
||||
source = source.replace(/\s+/mg, ' ');
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
test();
|
||||
@ -34,7 +41,7 @@ function test()
|
||||
expect = 'SyntaxError: missing { before function body';
|
||||
actual = ex + '';
|
||||
}
|
||||
compareSource(expect, actual, summary);
|
||||
compareSource(normalizeSource(expect), normalizeSource(actual), summary);
|
||||
|
||||
expect = '({get f () /x/g})';
|
||||
try
|
||||
@ -48,7 +55,7 @@ function test()
|
||||
expect = 'SyntaxError: missing { before function body';
|
||||
actual = ex + '';
|
||||
}
|
||||
compareSource(expect, actual, summary);
|
||||
compareSource(normalizeSource(expect), normalizeSource(actual), summary);
|
||||
}
|
||||
|
||||
exitFunc ('test');
|
||||
|
@ -95,28 +95,6 @@
|
||||
return ReflectApply(StringPrototypeEndsWith, str, [needle]);
|
||||
}
|
||||
|
||||
function StringReplace(str, regexp, replacement) {
|
||||
assertEq(typeof str === "string" && typeof regexp === "object" &&
|
||||
typeof replacement === "function", true,
|
||||
"StringReplace must be called with a string, a RegExp object and a function");
|
||||
|
||||
regexp.lastIndex = 0;
|
||||
|
||||
var result = "";
|
||||
var last = 0;
|
||||
while (true) {
|
||||
var match = ReflectApply(RegExpPrototypeExec, regexp, [str]);
|
||||
if (!match) {
|
||||
result += ReflectApply(StringPrototypeSubstring, str, [last]);
|
||||
return result;
|
||||
}
|
||||
|
||||
result += ReflectApply(StringPrototypeSubstring, str, [last, match.index]);
|
||||
result += ReflectApply(replacement, null, match);
|
||||
last = match.index + match[0].length;
|
||||
}
|
||||
}
|
||||
|
||||
function StringSplit(str, delimiter) {
|
||||
assertEq(typeof str === "string" && typeof delimiter === "string", true,
|
||||
"StringSplit must be called with two string arguments");
|
||||
@ -624,18 +602,10 @@
|
||||
}
|
||||
global.reportMatch = reportMatch;
|
||||
|
||||
function normalizeSource(source) {
|
||||
source = String(source);
|
||||
source = StringReplace(source, /([(){},.:\[\]])/mg, (_, punctuator) => ` ${punctuator} `);
|
||||
source = StringReplace(source, /\s+/mg, _ => ' ');
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
function compareSource(expect, actual, summary) {
|
||||
// compare source
|
||||
var expectP = normalizeSource(expect);
|
||||
var actualP = normalizeSource(actual);
|
||||
var expectP = String(expect);
|
||||
var actualP = String(actual);
|
||||
|
||||
print('expect:\n' + expectP);
|
||||
print('actual:\n' + actualP);
|
||||
|
Loading…
Reference in New Issue
Block a user