Skip to content

Commit

Permalink
"replacing totally wrong diff algorithm with a working one" Patch fro…
Browse files Browse the repository at this point in the history
…m kassens (manually applied).
  • Loading branch information
kassens authored and jeresig committed Oct 2, 2009
1 parent d45722d commit 9c8d83c
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions qunit/qunit.js
Expand Up @@ -21,7 +21,6 @@ var QUnit = {
blocking: false,
autorun: false,
assertions: [],
pollution: [],
filters: [],
queue: []
};
Expand Down Expand Up @@ -566,7 +565,7 @@ function saveGlobal() {

if ( config.noglobals ) {
for ( var key in window ) {
config.pollution.push(key);
config.pollution.push( key );
}
}
}
Expand All @@ -575,24 +574,32 @@ function checkPollution( name ) {
var old = config.pollution;
saveGlobal();

if ( config.pollution.length > old.length ) {
ok( false, "Introduced global variable(s): " + diff(old, config.pollution).join(", ") );
var newGlobals = diff( old, config.pollution );
if ( newGlobals.length > 0 ) {
ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );
config.expected++;
}
}

function diff( clean, dirty ) {
var results = [];
var deletedGlobals = diff( config.pollution, old );
if ( deletedGlobals.length > 0 ) {
ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );
config.expected++;
}
}

for ( var i = 0; i < dirty.length; i++ ) {
for ( var c = 0; c < clean.length; c++ ) {
if ( clean[c] === dirty[i] ) {
results.push( clean[c] );
// returns a new Array with the elements that are in a but not in b
function diff( a, b ) {
var result = a.slice();
for ( var i = 0; i < result.length; i++ ) {
for ( var j = 0; j < b.length; j++ ) {
if ( result[i] === b[j] ) {
result.splice(i, 1);
i--;
break;
}
}
}

return results;
return result;
}

function fail(message, exception, callback) {
Expand Down

0 comments on commit 9c8d83c

Please sign in to comment.