Browse files

Complete onevar conformance

Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
  • Loading branch information...
1 parent bc1d519 commit 7684b4c7f1508436ffd77a77e449171378727488 @rwaldron rwaldron committed Apr 14, 2012
Showing with 191 additions and 183 deletions.
  1. +191 −183 qunit/qunit.js
View
374 qunit/qunit.js
@@ -10,7 +10,12 @@
(function( window ) {
-var defined = {
+var QUnit,
+ config,
+ testId = 0,
+ toString = Object.prototype.toString,
+ hasOwn = Object.prototype.hasOwnProperty,
+ defined = {
setTimeout: typeof window.setTimeout !== "undefined",
sessionStorage: (function() {
var x = "qunit-test-string";
@@ -24,18 +29,14 @@ var defined = {
}())
};
-var testId = 0,
- toString = Object.prototype.toString,
- hasOwn = Object.prototype.hasOwnProperty;
-
-var Test = function( name, testName, expected, async, callback ) {
+function Test( name, testName, expected, async, callback ) {
this.name = name;
this.testName = testName;
this.expected = expected;
this.async = async;
this.callback = callback;
this.assertions = [];
-};
+}
Test.prototype = {
init: function() {
@@ -290,7 +291,8 @@ Test.prototype = {
}
};
-var QUnit = {
+// `QUnit` initialized at top of scope
+QUnit = {
// call on start of module test to prepend name to all tests
module: function( name, testEnvironment ) {
@@ -489,7 +491,8 @@ QUnit.same = function() {
};
// Maintain internal state
-var config = {
+// `config` initialized at top of scope
+config = {
// The queue of tests to run
queue: [],
@@ -791,7 +794,7 @@ QUnit.load = function() {
runLoggingCallbacks( "begin", QUnit, {} );
// Initialize the config, saving the execution queue
- var banner, filter, i, label, len, main, toolbar, userAgent, val,
+ var banner, filter, i, label, len, main, ol, toolbar, userAgent, val,
urlConfigHtml = "",
oldconfig = extend( {}, config );
@@ -834,11 +837,13 @@ QUnit.load = function() {
filter.id = "qunit-filter-pass";
addEvent( filter, "click", function() {
- var ol = document.getElementById( "qunit-tests" );
+ var tmp,
+ ol = document.getElementById( "qunit-tests" );
+
if ( filter.checked ) {
ol.className = ol.className + " hidepass";
} else {
- var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
+ tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
ol.className = tmp.replace(/ hidepass /, " " );
}
if ( defined.sessionStorage ) {
@@ -852,7 +857,8 @@ QUnit.load = function() {
if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) {
filter.checked = true;
- var ol = document.getElementById( "qunit-tests" );
+ // `ol` initialized at top of scope
+ ol = document.getElementById( "qunit-tests" );
ol.className = ol.className + " hidepass";
}
toolbar.appendChild( filter );
@@ -1095,9 +1101,11 @@ function checkPollution( name ) {
// 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++ ) {
+ var i, j,
+ result = a.slice();
+
+ for ( i = 0; i < result.length; i++ ) {
+ for ( j = 0; j < b.length; j++ ) {
if ( result[i] === b[j] ) {
result.splice( i, 1 );
i--;
@@ -1115,7 +1123,7 @@ function extend( a, b ) {
// Avoid "Member not found" error in IE8 caused by setting window.constructor
} else if ( prop !== "constructor" || a !== window ) {
- a[prop] = b[ prop ];
+ a[ prop ] = b[ prop ];
}
}
@@ -1380,179 +1388,178 @@ QUnit.jsDump = (function() {
return join( "[", ret, "]" );
}
- var reName = /^function (\w+)/;
+ var reName = /^function (\w+)/,
+ jsDump = {
+ parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
+ stack = stack || [ ];
+ var inStack, res,
+ parser = this.parsers[ type || this.typeOf(obj) ];
- var jsDump = {
- parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
- stack = stack || [ ];
- var inStack,
- parser = this.parsers[ type || this.typeOf(obj) ];
+ type = typeof parser;
+ inStack = inArray( obj, stack );
- type = typeof parser;
- inStack = inArray( obj, stack );
-
- if (inStack != -1) {
- return "recursion(" + (inStack - stack.length) + ")";
- }
- //else
- if ( type == "function" ) {
- stack.push( obj );
- var res = parser.call( this, obj, stack );
- stack.pop();
- return res;
- }
- // else
- return ( type == "string" ) ? parser : this.parsers.error;
- },
- typeOf: function( obj ) {
- var type;
- if ( obj === null ) {
- type = "null";
- } else if ( typeof obj === "undefined" ) {
- type = "undefined";
- } else if ( QUnit.is( "RegExp", obj) ) {
- type = "regexp";
- } else if ( QUnit.is( "Date", obj) ) {
- type = "date";
- } else if ( QUnit.is( "Function", obj) ) {
- type = "function";
- } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
- type = "window";
- } else if ( obj.nodeType === 9 ) {
- type = "document";
- } else if ( obj.nodeType ) {
- type = "node";
- } else if (
- // native arrays
- toString.call( obj ) === "[object Array]" ||
- // NodeList objects
- ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
- ) {
- type = "array";
- } else {
- type = typeof obj;
- }
- return type;
- },
- separator: function() {
- return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? "&nbsp;" : " ";
- },
- indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
- if ( !this.multiline ) {
- return "";
- }
- var chr = this.indentChar;
- if ( this.HTML ) {
- chr = chr.replace(/\t/g," " ).replace(/ /g,"&nbsp;" );
- }
- return new Array( this._depth_ + (extra||0) ).join(chr);
- },
- up: function( a ) {
- this._depth_ += a || 1;
- },
- down: function( a ) {
- this._depth_ -= a || 1;
- },
- setParser: function( name, parser ) {
- this.parsers[name] = parser;
- },
- // The next 3 are exposed so you can use them
- quote: quote,
- literal: literal,
- join: join,
- //
- _depth_: 1,
- // This is the list of parsers, to modify them, use jsDump.setParser
- parsers: {
- window: "[Window]",
- document: "[Document]",
- error: "[ERROR]", //when no parser is found, shouldn"t happen
- unknown: "[Unknown]",
- "null": "null",
- "undefined": "undefined",
- "function": function( fn ) {
- var ret = "function",
- name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE
-
- if ( name ) {
- ret += " " + name;
+ if ( inStack != -1 ) {
+ return "recursion(" + (inStack - stack.length) + ")";
}
- ret += "( ";
-
- ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
- return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
+ //else
+ if ( type == "function" ) {
+ stack.push( obj );
+ res = parser.call( this, obj, stack );
+ stack.pop();
+ return res;
+ }
+ // else
+ return ( type == "string" ) ? parser : this.parsers.error;
},
- array: array,
- nodelist: array,
- "arguments": array,
- object: function( map, stack ) {
- var ret = [ ], keys, key, val, i;
- QUnit.jsDump.up();
- if ( Object.keys ) {
- keys = Object.keys( map );
+ typeOf: function( obj ) {
+ var type;
+ if ( obj === null ) {
+ type = "null";
+ } else if ( typeof obj === "undefined" ) {
+ type = "undefined";
+ } else if ( QUnit.is( "RegExp", obj) ) {
+ type = "regexp";
+ } else if ( QUnit.is( "Date", obj) ) {
+ type = "date";
+ } else if ( QUnit.is( "Function", obj) ) {
+ type = "function";
+ } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) {
+ type = "window";
+ } else if ( obj.nodeType === 9 ) {
+ type = "document";
+ } else if ( obj.nodeType ) {
+ type = "node";
+ } else if (
+ // native arrays
+ toString.call( obj ) === "[object Array]" ||
+ // NodeList objects
+ ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) )
+ ) {
+ type = "array";
} else {
- keys = [];
- for ( key in map ) {
- keys.push( key );
- }
- }
- keys.sort();
- for ( i = 0; i < keys.length; i++ ) {
- key = keys[ i ];
- val = map[ key ];
- ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
+ type = typeof obj;
}
- QUnit.jsDump.down();
- return join( "{", ret, "}" );
+ return type;
},
- node: function( node ) {
- var a, val,
- open = QUnit.jsDump.HTML ? "&lt;" : "<",
- close = QUnit.jsDump.HTML ? "&gt;" : ">",
- tag = node.nodeName.toLowerCase(),
- ret = open + tag;
-
- for ( a in QUnit.jsDump.DOMAttrs ) {
- val = node[ QUnit.jsDump.DOMAttrs[a] ];
- if ( val ) {
- ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" );
- }
- }
- return ret + close + open + "/" + tag + close;
+ separator: function() {
+ return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? "&nbsp;" : " ";
},
- functionArgs: function( fn ) {//function calls it internally, it"s the arguments part of the function
- var args,
- l = fn.length;
-
- if ( !l ) {
+ indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
+ if ( !this.multiline ) {
return "";
}
-
- args = new Array(l);
- while ( l-- ) {
- args[l] = String.fromCharCode(97+l);//97 is 'a'
+ var chr = this.indentChar;
+ if ( this.HTML ) {
+ chr = chr.replace(/\t/g," " ).replace(/ /g,"&nbsp;" );
}
- return " " + args.join( ", " ) + " ";
+ return new Array( this._depth_ + (extra||0) ).join(chr);
},
- key: quote, //object calls it internally, the key part of an item in a map
- functionCode: "[code]", //function calls it internally, it's the content of the function
- attribute: quote, //node calls it internally, it's an html attribute value
- string: quote,
- date: quote,
- regexp: literal, //regex
- number: literal,
- "boolean": literal
- },
- DOMAttrs: {
- //attributes to dump from nodes, name=>realName
- id: "id",
- name: "name",
- "class": "className"
- },
- HTML: false,//if true, entities are escaped ( <, >, \t, space and \n )
- indentChar: " ",//indentation unit
- multiline: true //if true, items in a collection, are separated by a \n, else just a space.
- };
+ up: function( a ) {
+ this._depth_ += a || 1;
+ },
+ down: function( a ) {
+ this._depth_ -= a || 1;
+ },
+ setParser: function( name, parser ) {
+ this.parsers[name] = parser;
+ },
+ // The next 3 are exposed so you can use them
+ quote: quote,
+ literal: literal,
+ join: join,
+ //
+ _depth_: 1,
+ // This is the list of parsers, to modify them, use jsDump.setParser
+ parsers: {
+ window: "[Window]",
+ document: "[Document]",
+ error: "[ERROR]", //when no parser is found, shouldn"t happen
+ unknown: "[Unknown]",
+ "null": "null",
+ "undefined": "undefined",
+ "function": function( fn ) {
+ var ret = "function",
+ name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE
+
+ if ( name ) {
+ ret += " " + name;
+ }
+ ret += "( ";
+
+ ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" );
+ return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" );
+ },
+ array: array,
+ nodelist: array,
+ "arguments": array,
+ object: function( map, stack ) {
+ var ret = [ ], keys, key, val, i;
+ QUnit.jsDump.up();
+ if ( Object.keys ) {
+ keys = Object.keys( map );
+ } else {
+ keys = [];
+ for ( key in map ) {
+ keys.push( key );
+ }
+ }
+ keys.sort();
+ for ( i = 0; i < keys.length; i++ ) {
+ key = keys[ i ];
+ val = map[ key ];
+ ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) );
+ }
+ QUnit.jsDump.down();
+ return join( "{", ret, "}" );
+ },
+ node: function( node ) {
+ var a, val,
+ open = QUnit.jsDump.HTML ? "&lt;" : "<",
+ close = QUnit.jsDump.HTML ? "&gt;" : ">",
+ tag = node.nodeName.toLowerCase(),
+ ret = open + tag;
+
+ for ( a in QUnit.jsDump.DOMAttrs ) {
+ val = node[ QUnit.jsDump.DOMAttrs[a] ];
+ if ( val ) {
+ ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" );
+ }
+ }
+ return ret + close + open + "/" + tag + close;
+ },
+ functionArgs: function( fn ) {//function calls it internally, it"s the arguments part of the function
+ var args,
+ l = fn.length;
+
+ if ( !l ) {
+ return "";
+ }
+
+ args = new Array(l);
+ while ( l-- ) {
+ args[l] = String.fromCharCode(97+l);//97 is 'a'
+ }
+ return " " + args.join( ", " ) + " ";
+ },
+ key: quote, //object calls it internally, the key part of an item in a map
+ functionCode: "[code]", //function calls it internally, it's the content of the function
+ attribute: quote, //node calls it internally, it's an html attribute value
+ string: quote,
+ date: quote,
+ regexp: literal, //regex
+ number: literal,
+ "boolean": literal
+ },
+ DOMAttrs: {
+ //attributes to dump from nodes, name=>realName
+ id: "id",
+ name: "name",
+ "class": "className"
+ },
+ HTML: false,//if true, entities are escaped ( <, >, \t, space and \n )
+ indentChar: " ",//indentation unit
+ multiline: true //if true, items in a collection, are separated by a \n, else just a space.
+ };
return jsDump;
}());
@@ -1609,9 +1616,9 @@ function inArray( elem, array ) {
*/
QUnit.diff = (function() {
function diff( o, n ) {
- var ns = {};
- var os = {};
- var i;
+ var i,
+ ns = {},
+ os = {};
for ( i = 0; i < n.length; i++ ) {
if ( ns[ n[i] ] == null ) {
@@ -1689,7 +1696,7 @@ QUnit.diff = (function() {
o = o.replace( /\s+$/, "" );
n = n.replace( /\s+$/, "" );
- var i,
+ var i, pre,
str = "",
out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ),
oSpace = o.match(/\s+/g),
@@ -1726,7 +1733,8 @@ QUnit.diff = (function() {
str += "<ins>" + out.n[i] + nSpace[i] + "</ins>";
}
else {
- var pre = "";
+ // `pre` initialized at top of scope
+ pre = "";
for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
pre += "<del>" + out.o[n] + oSpace[n] + "</del>";

0 comments on commit 7684b4c

Please sign in to comment.