+++ /dev/null
-/*\r
- * QUnit - A JavaScript Unit Testing Framework\r
- * \r
- * http://docs.jquery.com/QUnit\r
- *\r
- * Copyright (c) 2009 John Resig, Jörn Zaefferer\r
- * Dual licensed under the MIT (MIT-LICENSE.txt)\r
- * and GPL (GPL-LICENSE.txt) licenses.\r
- */\r
-\r
-(function(window) {\r
-\r
-var QUnit = {\r
-\r
- // Initialize the configuration options\r
- init: function() {\r
- config = {\r
- stats: { all: 0, bad: 0 },\r
- moduleStats: { all: 0, bad: 0 },\r
- started: +new Date,\r
- blocking: false,\r
- autorun: false,\r
- assertions: [],\r
- filters: [],\r
- queue: []\r
- };\r
-\r
- var tests = id("qunit-tests"),\r
- banner = id("qunit-banner"),\r
- result = id("qunit-testresult");\r
-\r
- if ( tests ) {\r
- tests.innerHTML = "";\r
- }\r
-\r
- if ( banner ) {\r
- banner.className = "";\r
- }\r
-\r
- if ( result ) {\r
- result.parentNode.removeChild( result );\r
- }\r
- },\r
- \r
- // call on start of module test to prepend name to all tests\r
- module: function(name, testEnvironment) {\r
- config.currentModule = name;\r
-\r
- synchronize(function() {\r
- if ( config.currentModule ) {\r
- QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all );\r
- }\r
-\r
- config.currentModule = name;\r
- config.moduleTestEnvironment = testEnvironment;\r
- config.moduleStats = { all: 0, bad: 0 };\r
-\r
- QUnit.moduleStart( name, testEnvironment );\r
- });\r
- },\r
-\r
- asyncTest: function(testName, expected, callback) {\r
- if ( arguments.length === 2 ) {\r
- callback = expected;\r
- expected = 0;\r
- }\r
-\r
- QUnit.test(testName, expected, callback, true);\r
- },\r
- \r
- test: function(testName, expected, callback, async) {\r
- var name = testName, testEnvironment, testEnvironmentArg;\r
-\r
- if ( arguments.length === 2 ) {\r
- callback = expected;\r
- expected = null;\r
- }\r
- // is 2nd argument a testEnvironment?\r
- if ( expected && typeof expected === 'object') {\r
- testEnvironmentArg = expected;\r
- expected = null;\r
- }\r
-\r
- if ( config.currentModule ) {\r
- name = config.currentModule + " module: " + name;\r
- }\r
-\r
- if ( !validTest(name) ) {\r
- return;\r
- }\r
-\r
- synchronize(function() {\r
- QUnit.testStart( testName );\r
-\r
- testEnvironment = extend({\r
- setup: function() {},\r
- teardown: function() {}\r
- }, config.moduleTestEnvironment);\r
- if (testEnvironmentArg) {\r
- extend(testEnvironment,testEnvironmentArg);\r
- }\r
-\r
- // allow utility functions to access the current test environment\r
- QUnit.current_testEnvironment = testEnvironment;\r
- \r
- config.assertions = [];\r
- config.expected = expected;\r
-\r
- try {\r
- if ( !config.pollution ) {\r
- saveGlobal();\r
- }\r
-\r
- testEnvironment.setup.call(testEnvironment);\r
- } catch(e) {\r
- QUnit.ok( false, "Setup failed on " + name + ": " + e.message );\r
- }\r
-\r
- if ( async ) {\r
- QUnit.stop();\r
- }\r
-\r
- try {\r
- callback.call(testEnvironment);\r
- } catch(e) {\r
- fail("Test " + name + " died, exception and test follows", e, callback);\r
- QUnit.ok( false, "Died on test #" + (config.assertions.length + 1) + ": " + e.message );\r
- // else next test will carry the responsibility\r
- saveGlobal();\r
-\r
- // Restart the tests if they're blocking\r
- if ( config.blocking ) {\r
- start();\r
- }\r
- }\r
- });\r
-\r
- synchronize(function() {\r
- try {\r
- checkPollution();\r
- testEnvironment.teardown.call(testEnvironment);\r
- } catch(e) {\r
- QUnit.ok( false, "Teardown failed on " + name + ": " + e.message );\r
- }\r
-\r
- try {\r
- QUnit.reset();\r
- } catch(e) {\r
- fail("reset() failed, following Test " + name + ", exception and reset fn follows", e, reset);\r
- }\r
-\r
- if ( config.expected && config.expected != config.assertions.length ) {\r
- QUnit.ok( false, "Expected " + config.expected + " assertions, but " + config.assertions.length + " were run" );\r
- }\r
-\r
- var good = 0, bad = 0,\r
- tests = id("qunit-tests");\r
-\r
- config.stats.all += config.assertions.length;\r
- config.moduleStats.all += config.assertions.length;\r
-\r
- if ( tests ) {\r
- var ol = document.createElement("ol");\r
- ol.style.display = "none";\r
-\r
- for ( var i = 0; i < config.assertions.length; i++ ) {\r
- var assertion = config.assertions[i];\r
-\r
- var li = document.createElement("li");\r
- li.className = assertion.result ? "pass" : "fail";\r
- li.appendChild(document.createTextNode(assertion.message || "(no message)"));\r
- ol.appendChild( li );\r
-\r
- if ( assertion.result ) {\r
- good++;\r
- } else {\r
- bad++;\r
- config.stats.bad++;\r
- config.moduleStats.bad++;\r
- }\r
- }\r
-\r
- var b = document.createElement("strong");\r
- b.innerHTML = name + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + config.assertions.length + ")</b>";\r
- \r
- addEvent(b, "click", function() {\r
- var next = b.nextSibling, display = next.style.display;\r
- next.style.display = display === "none" ? "block" : "none";\r
- });\r
- \r
- addEvent(b, "dblclick", function(e) {\r
- var target = e && e.target ? e.target : window.event.srcElement;\r
- if ( target.nodeName.toLowerCase() === "strong" ) {\r
- var text = "", node = target.firstChild;\r
-\r
- while ( node.nodeType === 3 ) {\r
- text += node.nodeValue;\r
- node = node.nextSibling;\r
- }\r
-\r
- text = text.replace(/(^\s*|\s*$)/g, "");\r
-\r
- if ( window.location ) {\r
- window.location.href = window.location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent(text);\r
- }\r
- }\r
- });\r
-\r
- var li = document.createElement("li");\r
- li.className = bad ? "fail" : "pass";\r
- li.appendChild( b );\r
- li.appendChild( ol );\r
- tests.appendChild( li );\r
-\r
- if ( bad ) {\r
- var toolbar = id("qunit-testrunner-toolbar");\r
- if ( toolbar ) {\r
- toolbar.style.display = "block";\r
- id("qunit-filter-pass").disabled = null;\r
- id("qunit-filter-missing").disabled = null;\r
- }\r
- }\r
-\r
- } else {\r
- for ( var i = 0; i < config.assertions.length; i++ ) {\r
- if ( !config.assertions[i].result ) {\r
- bad++;\r
- config.stats.bad++;\r
- config.moduleStats.bad++;\r
- }\r
- }\r
- }\r
-\r
- QUnit.testDone( testName, bad, config.assertions.length );\r
-\r
- if ( !window.setTimeout && !config.queue.length ) {\r
- done();\r
- }\r
- });\r
-\r
- if ( window.setTimeout && !config.doneTimer ) {\r
- config.doneTimer = window.setTimeout(function(){\r
- if ( !config.queue.length ) {\r
- done();\r
- } else {\r
- synchronize( done );\r
- }\r
- }, 13);\r
- }\r
- },\r
- \r
- /**\r
- * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.\r
- */\r
- expect: function(asserts) {\r
- config.expected = asserts;\r
- },\r
-\r
- /**\r
- * Asserts true.\r
- * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );\r
- */\r
- ok: function(a, msg) {\r
- QUnit.log(a, msg);\r
-\r
- config.assertions.push({\r
- result: !!a,\r
- message: msg\r
- });\r
- },\r
-\r
- /**\r
- * Checks that the first two arguments are equal, with an optional message.\r
- * Prints out both actual and expected values.\r
- *\r
- * Prefered to ok( actual == expected, message )\r
- *\r
- * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." );\r
- *\r
- * @param Object actual\r
- * @param Object expected\r
- * @param String message (optional)\r
- */\r
- equal: function(actual, expected, message) {\r
- push(expected == actual, actual, expected, message);\r
- },\r
-\r
- notEqual: function(actual, expected, message) {\r
- push(expected != actual, actual, expected, message);\r
- },\r
- \r
- deepEqual: function(a, b, message) {\r
- push(QUnit.equiv(a, b), a, b, message);\r
- },\r
-\r
- notDeepEqual: function(a, b, message) {\r
- push(!QUnit.equiv(a, b), a, b, message);\r
- },\r
-\r
- strictEqual: function(actual, expected, message) {\r
- push(expected === actual, actual, expected, message);\r
- },\r
-\r
- notStrictEqual: function(actual, expected, message) {\r
- push(expected !== actual, actual, expected, message);\r
- },\r
- \r
- start: function() {\r
- // A slight delay, to avoid any current callbacks\r
- if ( window.setTimeout ) {\r
- window.setTimeout(function() {\r
- if ( config.timeout ) {\r
- clearTimeout(config.timeout);\r
- }\r
-\r
- config.blocking = false;\r
- process();\r
- }, 13);\r
- } else {\r
- config.blocking = false;\r
- process();\r
- }\r
- },\r
- \r
- stop: function(timeout) {\r
- config.blocking = true;\r
-\r
- if ( timeout && window.setTimeout ) {\r
- config.timeout = window.setTimeout(function() {\r
- QUnit.ok( false, "Test timed out" );\r
- QUnit.start();\r
- }, timeout);\r
- }\r
- },\r
- \r
- /**\r
- * Resets the test setup. Useful for tests that modify the DOM.\r
- */\r
- reset: function() {\r
- if ( window.jQuery ) {\r
- jQuery("#main").html( config.fixture );\r
- jQuery.event.global = {};\r
- jQuery.ajaxSettings = extend({}, config.ajaxSettings);\r
- }\r
- },\r
- \r
- /**\r
- * Trigger an event on an element.\r
- *\r
- * @example triggerEvent( document.body, "click" );\r
- *\r
- * @param DOMElement elem\r
- * @param String type\r
- */\r
- triggerEvent: function( elem, type, event ) {\r
- if ( document.createEvent ) {\r
- event = document.createEvent("MouseEvents");\r
- event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,\r
- 0, 0, 0, 0, 0, false, false, false, false, 0, null);\r
- elem.dispatchEvent( event );\r
-\r
- } else if ( elem.fireEvent ) {\r
- elem.fireEvent("on"+type);\r
- }\r
- },\r
- \r
- // Safe object type checking\r
- is: function( type, obj ) {\r
- return Object.prototype.toString.call( obj ) === "[object "+ type +"]";\r
- },\r
- \r
- // Logging callbacks\r
- done: function(failures, total) {},\r
- log: function(result, message) {},\r
- testStart: function(name) {},\r
- testDone: function(name, failures, total) {},\r
- moduleStart: function(name, testEnvironment) {},\r
- moduleDone: function(name, failures, total) {}\r
-};\r
-\r
-// Backwards compatibility, deprecated\r
-QUnit.equals = QUnit.equal;\r
-QUnit.same = QUnit.deepEqual;\r
-\r
-// Maintain internal state\r
-var config = {\r
- // The queue of tests to run\r
- queue: [],\r
-\r
- // block until document ready\r
- blocking: true\r
-};\r
-\r
-// Load paramaters\r
-(function() {\r
- var location = window.location || { search: "", protocol: "file:" },\r
- GETParams = location.search.slice(1).split('&');\r
-\r
- for ( var i = 0; i < GETParams.length; i++ ) {\r
- GETParams[i] = decodeURIComponent( GETParams[i] );\r
- if ( GETParams[i] === "noglobals" ) {\r
- GETParams.splice( i, 1 );\r
- i--;\r
- config.noglobals = true;\r
- } else if ( GETParams[i].search('=') > -1 ) {\r
- GETParams.splice( i, 1 );\r
- i--;\r
- }\r
- }\r
- \r
- // restrict modules/tests by get parameters\r
- config.filters = GETParams;\r
- \r
- // Figure out if we're running the tests from a server or not\r
- QUnit.isLocal = !!(location.protocol === 'file:');\r
-})();\r
-\r
-// Expose the API as global variables, unless an 'exports'\r
-// object exists, in that case we assume we're in CommonJS\r
-if ( typeof exports === "undefined" || typeof require === "undefined" ) {\r
- extend(window, QUnit);\r
- window.QUnit = QUnit;\r
-} else {\r
- extend(exports, QUnit);\r
- exports.QUnit = QUnit;\r
-}\r
-\r
-if ( typeof document === "undefined" || document.readyState === "complete" ) {\r
- config.autorun = true;\r
-}\r
-\r
-addEvent(window, "load", function() {\r
- // Initialize the config, saving the execution queue\r
- var oldconfig = extend({}, config);\r
- QUnit.init();\r
- extend(config, oldconfig);\r
-\r
- config.blocking = false;\r
-\r
- var userAgent = id("qunit-userAgent");\r
- if ( userAgent ) {\r
- userAgent.innerHTML = navigator.userAgent;\r
- }\r
- \r
- var toolbar = id("qunit-testrunner-toolbar");\r
- if ( toolbar ) {\r
- toolbar.style.display = "none";\r
- \r
- var filter = document.createElement("input");\r
- filter.type = "checkbox";\r
- filter.id = "qunit-filter-pass";\r
- filter.disabled = true;\r
- addEvent( filter, "click", function() {\r
- var li = document.getElementsByTagName("li");\r
- for ( var i = 0; i < li.length; i++ ) {\r
- if ( li[i].className.indexOf("pass") > -1 ) {\r
- li[i].style.display = filter.checked ? "none" : "";\r
- }\r
- }\r
- });\r
- toolbar.appendChild( filter );\r
-\r
- var label = document.createElement("label");\r
- label.setAttribute("for", "qunit-filter-pass");\r
- label.innerHTML = "Hide passed tests";\r
- toolbar.appendChild( label );\r
-\r
- var missing = document.createElement("input");\r
- missing.type = "checkbox";\r
- missing.id = "qunit-filter-missing";\r
- missing.disabled = true;\r
- addEvent( missing, "click", function() {\r
- var li = document.getElementsByTagName("li");\r
- for ( var i = 0; i < li.length; i++ ) {\r
- if ( li[i].className.indexOf("fail") > -1 && li[i].innerHTML.indexOf('missing test - untested code is broken code') > - 1 ) {\r
- li[i].parentNode.parentNode.style.display = missing.checked ? "none" : "block";\r
- }\r
- }\r
- });\r
- toolbar.appendChild( missing );\r
-\r
- label = document.createElement("label");\r
- label.setAttribute("for", "qunit-filter-missing");\r
- label.innerHTML = "Hide missing tests (untested code is broken code)";\r
- toolbar.appendChild( label );\r
- }\r
-\r
- var main = id('main');\r
- if ( main ) {\r
- config.fixture = main.innerHTML;\r
- }\r
-\r
- if ( window.jQuery ) {\r
- config.ajaxSettings = window.jQuery.ajaxSettings;\r
- }\r
-\r
- QUnit.start();\r
-});\r
-\r
-function done() {\r
- if ( config.doneTimer && window.clearTimeout ) {\r
- window.clearTimeout( config.doneTimer );\r
- config.doneTimer = null;\r
- }\r
-\r
- if ( config.queue.length ) {\r
- config.doneTimer = window.setTimeout(function(){\r
- if ( !config.queue.length ) {\r
- done();\r
- } else {\r
- synchronize( done );\r
- }\r
- }, 13);\r
-\r
- return;\r
- }\r
-\r
- config.autorun = true;\r
-\r
- // Log the last module results\r
- if ( config.currentModule ) {\r
- QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all );\r
- }\r
-\r
- var banner = id("qunit-banner"),\r
- tests = id("qunit-tests"),\r
- html = ['Tests completed in ',\r
- +new Date - config.started, ' milliseconds.<br/>',\r
- '<span class="passed">', config.stats.all - config.stats.bad, '</span> tests of <span class="total">', config.stats.all, '</span> passed, <span class="failed">', config.stats.bad,'</span> failed.'].join('');\r
-\r
- if ( banner ) {\r
- banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass");\r
- }\r
-\r
- if ( tests ) { \r
- var result = id("qunit-testresult");\r
-\r
- if ( !result ) {\r
- result = document.createElement("p");\r
- result.id = "qunit-testresult";\r
- result.className = "result";\r
- tests.parentNode.insertBefore( result, tests.nextSibling );\r
- }\r
-\r
- result.innerHTML = html;\r
- }\r
-\r
- QUnit.done( config.stats.bad, config.stats.all );\r
-}\r
-\r
-function validTest( name ) {\r
- var i = config.filters.length,\r
- run = false;\r
-\r
- if ( !i ) {\r
- return true;\r
- }\r
- \r
- while ( i-- ) {\r
- var filter = config.filters[i],\r
- not = filter.charAt(0) == '!';\r
-\r
- if ( not ) {\r
- filter = filter.slice(1);\r
- }\r
-\r
- if ( name.indexOf(filter) !== -1 ) {\r
- return !not;\r
- }\r
-\r
- if ( not ) {\r
- run = true;\r
- }\r
- }\r
-\r
- return run;\r
-}\r
-\r
-function push(result, actual, expected, message) {\r
- message = message || (result ? "okay" : "failed");\r
- QUnit.ok( result, result ? message + ": " + expected : message + ", expected: " + QUnit.jsDump.parse(expected) + " result: " + QUnit.jsDump.parse(actual) );\r
-}\r
-\r
-function synchronize( callback ) {\r
- config.queue.push( callback );\r
-\r
- if ( config.autorun && !config.blocking ) {\r
- process();\r
- }\r
-}\r
-\r
-function process() {\r
- while ( config.queue.length && !config.blocking ) {\r
- config.queue.shift()();\r
- }\r
-}\r
-\r
-function saveGlobal() {\r
- config.pollution = [];\r
- \r
- if ( config.noglobals ) {\r
- for ( var key in window ) {\r
- config.pollution.push( key );\r
- }\r
- }\r
-}\r
-\r
-function checkPollution( name ) {\r
- var old = config.pollution;\r
- saveGlobal();\r
- \r
- var newGlobals = diff( old, config.pollution );\r
- if ( newGlobals.length > 0 ) {\r
- ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );\r
- config.expected++;\r
- }\r
-\r
- var deletedGlobals = diff( config.pollution, old );\r
- if ( deletedGlobals.length > 0 ) {\r
- ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );\r
- config.expected++;\r
- }\r
-}\r
-\r
-// returns a new Array with the elements that are in a but not in b\r
-function diff( a, b ) {\r
- var result = a.slice();\r
- for ( var i = 0; i < result.length; i++ ) {\r
- for ( var j = 0; j < b.length; j++ ) {\r
- if ( result[i] === b[j] ) {\r
- result.splice(i, 1);\r
- i--;\r
- break;\r
- }\r
- }\r
- }\r
- return result;\r
-}\r
-\r
-function fail(message, exception, callback) {\r
- if ( typeof console !== "undefined" && console.error && console.warn ) {\r
- console.error(message);\r
- console.error(exception);\r
- console.warn(callback.toString());\r
-\r
- } else if ( window.opera && opera.postError ) {\r
- opera.postError(message, exception, callback.toString);\r
- }\r
-}\r
-\r
-function extend(a, b) {\r
- for ( var prop in b ) {\r
- a[prop] = b[prop];\r
- }\r
-\r
- return a;\r
-}\r
-\r
-function addEvent(elem, type, fn) {\r
- if ( elem.addEventListener ) {\r
- elem.addEventListener( type, fn, false );\r
- } else if ( elem.attachEvent ) {\r
- elem.attachEvent( "on" + type, fn );\r
- } else {\r
- fn();\r
- }\r
-}\r
-\r
-function id(name) {\r
- return !!(typeof document !== "undefined" && document && document.getElementById) &&\r
- document.getElementById( name );\r
-}\r
-\r
-// Test for equality any JavaScript type.\r
-// Discussions and reference: http://philrathe.com/articles/equiv\r
-// Test suites: http://philrathe.com/tests/equiv\r
-// Author: Philippe Rathé <prathe@gmail.com>\r
-QUnit.equiv = function () {\r
-\r
- var innerEquiv; // the real equiv function\r
- var callers = []; // stack to decide between skip/abort functions\r
-\r
-\r
- // Determine what is o.\r
- function hoozit(o) {\r
- if (QUnit.is("String", o)) {\r
- return "string";\r
- \r
- } else if (QUnit.is("Boolean", o)) {\r
- return "boolean";\r
-\r
- } else if (QUnit.is("Number", o)) {\r
-\r
- if (isNaN(o)) {\r
- return "nan";\r
- } else {\r
- return "number";\r
- }\r
-\r
- } else if (typeof o === "undefined") {\r
- return "undefined";\r
-\r
- // consider: typeof null === object\r
- } else if (o === null) {\r
- return "null";\r
-\r
- // consider: typeof [] === object\r
- } else if (QUnit.is( "Array", o)) {\r
- return "array";\r
- \r
- // consider: typeof new Date() === object\r
- } else if (QUnit.is( "Date", o)) {\r
- return "date";\r
-\r
- // consider: /./ instanceof Object;\r
- // /./ instanceof RegExp;\r
- // typeof /./ === "function"; // => false in IE and Opera,\r
- // true in FF and Safari\r
- } else if (QUnit.is( "RegExp", o)) {\r
- return "regexp";\r
-\r
- } else if (typeof o === "object") {\r
- return "object";\r
-\r
- } else if (QUnit.is( "Function", o)) {\r
- return "function";\r
- } else {\r
- return undefined;\r
- }\r
- }\r
-\r
- // Call the o related callback with the given arguments.\r
- function bindCallbacks(o, callbacks, args) {\r
- var prop = hoozit(o);\r
- if (prop) {\r
- if (hoozit(callbacks[prop]) === "function") {\r
- return callbacks[prop].apply(callbacks, args);\r
- } else {\r
- return callbacks[prop]; // or undefined\r
- }\r
- }\r
- }\r
- \r
- var callbacks = function () {\r
-\r
- // for string, boolean, number and null\r
- function useStrictEquality(b, a) {\r
- if (b instanceof a.constructor || a instanceof b.constructor) {\r
- // to catch short annotaion VS 'new' annotation of a declaration\r
- // e.g. var i = 1;\r
- // var j = new Number(1);\r
- return a == b;\r
- } else {\r
- return a === b;\r
- }\r
- }\r
-\r
- return {\r
- "string": useStrictEquality,\r
- "boolean": useStrictEquality,\r
- "number": useStrictEquality,\r
- "null": useStrictEquality,\r
- "undefined": useStrictEquality,\r
-\r
- "nan": function (b) {\r
- return isNaN(b);\r
- },\r
-\r
- "date": function (b, a) {\r
- return hoozit(b) === "date" && a.valueOf() === b.valueOf();\r
- },\r
-\r
- "regexp": function (b, a) {\r
- return hoozit(b) === "regexp" &&\r
- a.source === b.source && // the regex itself\r
- a.global === b.global && // and its modifers (gmi) ...\r
- a.ignoreCase === b.ignoreCase &&\r
- a.multiline === b.multiline;\r
- },\r
-\r
- // - skip when the property is a method of an instance (OOP)\r
- // - abort otherwise,\r
- // initial === would have catch identical references anyway\r
- "function": function () {\r
- var caller = callers[callers.length - 1];\r
- return caller !== Object &&\r
- typeof caller !== "undefined";\r
- },\r
-\r
- "array": function (b, a) {\r
- var i;\r
- var len;\r
-\r
- // b could be an object literal here\r
- if ( ! (hoozit(b) === "array")) {\r
- return false;\r
- }\r
-\r
- len = a.length;\r
- if (len !== b.length) { // safe and faster\r
- return false;\r
- }\r
- for (i = 0; i < len; i++) {\r
- if ( ! innerEquiv(a[i], b[i])) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- },\r
-\r
- "object": function (b, a) {\r
- var i;\r
- var eq = true; // unless we can proove it\r
- var aProperties = [], bProperties = []; // collection of strings\r
-\r
- // comparing constructors is more strict than using instanceof\r
- if ( a.constructor !== b.constructor) {\r
- return false;\r
- }\r
-\r
- // stack constructor before traversing properties\r
- callers.push(a.constructor);\r
-\r
- for (i in a) { // be strict: don't ensures hasOwnProperty and go deep\r
-\r
- aProperties.push(i); // collect a's properties\r
-\r
- if ( ! innerEquiv(a[i], b[i])) {\r
- eq = false;\r
- }\r
- }\r
-\r
- callers.pop(); // unstack, we are done\r
-\r
- for (i in b) {\r
- bProperties.push(i); // collect b's properties\r
- }\r
-\r
- // Ensures identical properties name\r
- return eq && innerEquiv(aProperties.sort(), bProperties.sort());\r
- }\r
- };\r
- }();\r
-\r
- innerEquiv = function () { // can take multiple arguments\r
- var args = Array.prototype.slice.apply(arguments);\r
- if (args.length < 2) {\r
- return true; // end transition\r
- }\r
-\r
- return (function (a, b) {\r
- if (a === b) {\r
- return true; // catch the most you can\r
- } else if (a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || hoozit(a) !== hoozit(b)) {\r
- return false; // don't lose time with error prone cases\r
- } else {\r
- return bindCallbacks(a, callbacks, [b, a]);\r
- }\r
-\r
- // apply transition with (1..n) arguments\r
- })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));\r
- };\r
-\r
- return innerEquiv;\r
-\r
-}();\r
-\r
-/**\r
- * jsDump\r
- * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com\r
- * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)\r
- * Date: 5/15/2008\r
- * @projectDescription Advanced and extensible data dumping for Javascript.\r
- * @version 1.0.0\r
- * @author Ariel Flesler\r
- * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}\r
- */\r
-QUnit.jsDump = (function() {\r
- function quote( str ) {\r
- return '"' + str.toString().replace(/"/g, '\\"') + '"';\r
- };\r
- function literal( o ) {\r
- return o + ''; \r
- };\r
- function join( pre, arr, post ) {\r
- var s = jsDump.separator(),\r
- base = jsDump.indent(),\r
- inner = jsDump.indent(1);\r
- if ( arr.join )\r
- arr = arr.join( ',' + s + inner );\r
- if ( !arr )\r
- return pre + post;\r
- return [ pre, inner + arr, base + post ].join(s);\r
- };\r
- function array( arr ) {\r
- var i = arr.length, ret = Array(i); \r
- this.up();\r
- while ( i-- )\r
- ret[i] = this.parse( arr[i] ); \r
- this.down();\r
- return join( '[', ret, ']' );\r
- };\r
- \r
- var reName = /^function (\w+)/;\r
- \r
- var jsDump = {\r
- parse:function( obj, type ) { //type is used mostly internally, you can fix a (custom)type in advance\r
- var parser = this.parsers[ type || this.typeOf(obj) ];\r
- type = typeof parser; \r
- \r
- return type == 'function' ? parser.call( this, obj ) :\r
- type == 'string' ? parser :\r
- this.parsers.error;\r
- },\r
- typeOf:function( obj ) {\r
- var type;\r
- if ( obj === null ) {\r
- type = "null";\r
- } else if (typeof obj === "undefined") {\r
- type = "undefined";\r
- } else if (QUnit.is("RegExp", obj)) {\r
- type = "regexp";\r
- } else if (QUnit.is("Date", obj)) {\r
- type = "date";\r
- } else if (QUnit.is("Function", obj)) {\r
- type = "function";\r
- } else if (QUnit.is("Array", obj)) {\r
- type = "array";\r
- } else if (QUnit.is("Window", obj) || QUnit.is("global", obj)) {\r
- type = "window";\r
- } else if (QUnit.is("HTMLDocument", obj)) {\r
- type = "document";\r
- } else if (QUnit.is("HTMLCollection", obj) || QUnit.is("NodeList", obj)) {\r
- type = "nodelist";\r
- } else if (/^\[object HTML/.test(Object.prototype.toString.call( obj ))) {\r
- type = "node";\r
- } else {\r
- type = typeof obj;\r
- }\r
- return type;\r
- },\r
- separator:function() {\r
- return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? ' ' : ' ';\r
- },\r
- indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing\r
- if ( !this.multiline )\r
- return '';\r
- var chr = this.indentChar;\r
- if ( this.HTML )\r
- chr = chr.replace(/\t/g,' ').replace(/ /g,' ');\r
- return Array( this._depth_ + (extra||0) ).join(chr);\r
- },\r
- up:function( a ) {\r
- this._depth_ += a || 1;\r
- },\r
- down:function( a ) {\r
- this._depth_ -= a || 1;\r
- },\r
- setParser:function( name, parser ) {\r
- this.parsers[name] = parser;\r
- },\r
- // The next 3 are exposed so you can use them\r
- quote:quote, \r
- literal:literal,\r
- join:join,\r
- //\r
- _depth_: 1,\r
- // This is the list of parsers, to modify them, use jsDump.setParser\r
- parsers:{\r
- window: '[Window]',\r
- document: '[Document]',\r
- error:'[ERROR]', //when no parser is found, shouldn't happen\r
- unknown: '[Unknown]',\r
- 'null':'null',\r
- undefined:'undefined',\r
- 'function':function( fn ) {\r
- var ret = 'function',\r
- name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE\r
- if ( name )\r
- ret += ' ' + name;\r
- ret += '(';\r
- \r
- ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join('');\r
- return join( ret, this.parse(fn,'functionCode'), '}' );\r
- },\r
- array: array,\r
- nodelist: array,\r
- arguments: array,\r
- object:function( map ) {\r
- var ret = [ ];\r
- this.up();\r
- for ( var key in map )\r
- ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) );\r
- this.down();\r
- return join( '{', ret, '}' );\r
- },\r
- node:function( node ) {\r
- var open = this.HTML ? '<' : '<',\r
- close = this.HTML ? '>' : '>';\r
- \r
- var tag = node.nodeName.toLowerCase(),\r
- ret = open + tag;\r
- \r
- for ( var a in this.DOMAttrs ) {\r
- var val = node[this.DOMAttrs[a]];\r
- if ( val )\r
- ret += ' ' + a + '=' + this.parse( val, 'attribute' );\r
- }\r
- return ret + close + open + '/' + tag + close;\r
- },\r
- functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function\r
- var l = fn.length;\r
- if ( !l ) return ''; \r
- \r
- var args = Array(l);\r
- while ( l-- )\r
- args[l] = String.fromCharCode(97+l);//97 is 'a'\r
- return ' ' + args.join(', ') + ' ';\r
- },\r
- key:quote, //object calls it internally, the key part of an item in a map\r
- functionCode:'[code]', //function calls it internally, it's the content of the function\r
- attribute:quote, //node calls it internally, it's an html attribute value\r
- string:quote,\r
- date:quote,\r
- regexp:literal, //regex\r
- number:literal,\r
- 'boolean':literal\r
- },\r
- DOMAttrs:{//attributes to dump from nodes, name=>realName\r
- id:'id',\r
- name:'name',\r
- 'class':'className'\r
- },\r
- HTML:true,//if true, entities are escaped ( <, >, \t, space and \n )\r
- indentChar:' ',//indentation unit\r
- multiline:true //if true, items in a collection, are separated by a \n, else just a space.\r
- };\r
-\r
- return jsDump;\r
-})();\r
-\r
-})(this);\r