backbone-indexeddb
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -263,8 +263,3 @@ (function () { /*global _: false, Backbone: false */ | ||
if (!store.keyPath) | ||
writeRequest = store.add(json, json.id); | ||
else | ||
writeRequest = store.add(json); | ||
writeRequest.onerror = function (e) { | ||
writeTransaction.onerror = function (e) { | ||
options.error(e); | ||
@@ -275,2 +270,7 @@ }; | ||
}; | ||
if (!store.keyPath) | ||
writeRequest = store.add(json, json.id); | ||
else | ||
writeRequest = store.add(json); | ||
}, | ||
@@ -571,3 +571,3 @@ | ||
resolve(); | ||
if (success) success(resp, options); | ||
if (success) success(object, resp, options); | ||
object.trigger('sync', object, resp, options); | ||
@@ -579,3 +579,3 @@ }; | ||
reject(); | ||
if (error) error(resp, options); | ||
if (error) error(object, resp, options); | ||
object.trigger('error', object, resp, options); | ||
@@ -582,0 +582,0 @@ }; |
2216
lib/qunit.js
/** | ||
* QUnit - A JavaScript Unit Testing Framework | ||
* QUnit v1.11.0 - A JavaScript Unit Testing Framework | ||
* | ||
* http://docs.jquery.com/QUnit | ||
* http://qunitjs.com | ||
* | ||
* Copyright (c) 2011 John Resig, Jörn Zaefferer | ||
* Dual licensed under the MIT (MIT-LICENSE.txt) | ||
* or GPL (GPL-LICENSE.txt) licenses. | ||
* Copyright 2012 jQuery Foundation and other contributors | ||
* Released under the MIT license. | ||
* http://jquery.org/license | ||
*/ | ||
(function(window) { | ||
(function( window ) { | ||
var defined = { | ||
setTimeout: typeof window.setTimeout !== "undefined", | ||
sessionStorage: (function() { | ||
try { | ||
return !!sessionStorage.getItem; | ||
} catch(e) { | ||
return false; | ||
var QUnit, | ||
assert, | ||
config, | ||
onErrorFnPrev, | ||
testId = 0, | ||
fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""), | ||
toString = Object.prototype.toString, | ||
hasOwn = Object.prototype.hasOwnProperty, | ||
// Keep a local reference to Date (GH-283) | ||
Date = window.Date, | ||
defined = { | ||
setTimeout: typeof window.setTimeout !== "undefined", | ||
sessionStorage: (function() { | ||
var x = "qunit-test-string"; | ||
try { | ||
sessionStorage.setItem( x, x ); | ||
sessionStorage.removeItem( x ); | ||
return true; | ||
} catch( e ) { | ||
return false; | ||
} | ||
}()) | ||
}, | ||
/** | ||
* Provides a normalized error string, correcting an issue | ||
* with IE 7 (and prior) where Error.prototype.toString is | ||
* not properly implemented | ||
* | ||
* Based on http://es5.github.com/#x15.11.4.4 | ||
* | ||
* @param {String|Error} error | ||
* @return {String} error message | ||
*/ | ||
errorString = function( error ) { | ||
var name, message, | ||
errorString = error.toString(); | ||
if ( errorString.substring( 0, 7 ) === "[object" ) { | ||
name = error.name ? error.name.toString() : "Error"; | ||
message = error.message ? error.message.toString() : ""; | ||
if ( name && message ) { | ||
return name + ": " + message; | ||
} else if ( name ) { | ||
return name; | ||
} else if ( message ) { | ||
return message; | ||
} else { | ||
return "Error"; | ||
} | ||
} else { | ||
return errorString; | ||
} | ||
})() | ||
}; | ||
}, | ||
/** | ||
* Makes a clone of an object using only Array or Object as base, | ||
* and copies over the own enumerable properties. | ||
* | ||
* @param {Object} obj | ||
* @return {Object} New object with only the own properties (recursively). | ||
*/ | ||
objectValues = function( obj ) { | ||
// Grunt 0.3.x uses an older version of jshint that still has jshint/jshint#392. | ||
/*jshint newcap: false */ | ||
var key, val, | ||
vals = QUnit.is( "array", obj ) ? [] : {}; | ||
for ( key in obj ) { | ||
if ( hasOwn.call( obj, key ) ) { | ||
val = obj[key]; | ||
vals[key] = val === Object(val) ? objectValues(val) : val; | ||
} | ||
} | ||
return vals; | ||
}; | ||
var testId = 0; | ||
function Test( settings ) { | ||
extend( this, settings ); | ||
this.assertions = []; | ||
this.testNumber = ++Test.count; | ||
} | ||
var Test = function(name, testName, expected, testEnvironmentArg, async, callback) { | ||
this.name = name; | ||
this.testName = testName; | ||
this.expected = expected; | ||
this.testEnvironmentArg = testEnvironmentArg; | ||
this.async = async; | ||
this.callback = callback; | ||
this.assertions = []; | ||
}; | ||
Test.count = 0; | ||
Test.prototype = { | ||
init: function() { | ||
var tests = id("qunit-tests"); | ||
if (tests) { | ||
var b = document.createElement("strong"); | ||
b.innerHTML = "Running " + this.name; | ||
var li = document.createElement("li"); | ||
li.appendChild( b ); | ||
li.className = "running"; | ||
li.id = this.id = "test-output" + testId++; | ||
var a, b, li, | ||
tests = id( "qunit-tests" ); | ||
if ( tests ) { | ||
b = document.createElement( "strong" ); | ||
b.innerHTML = this.nameHtml; | ||
// `a` initialized at top of scope | ||
a = document.createElement( "a" ); | ||
a.innerHTML = "Rerun"; | ||
a.href = QUnit.url({ testNumber: this.testNumber }); | ||
li = document.createElement( "li" ); | ||
li.appendChild( b ); | ||
li.appendChild( a ); | ||
li.className = "running"; | ||
li.id = this.id = "qunit-test-output" + testId++; | ||
tests.appendChild( li ); | ||
@@ -49,5 +118,5 @@ } | ||
setup: function() { | ||
if (this.module != config.previousModule) { | ||
if ( this.module !== config.previousModule ) { | ||
if ( config.previousModule ) { | ||
runLoggingCallbacks('moduleDone', QUnit, { | ||
runLoggingCallbacks( "moduleDone", QUnit, { | ||
name: config.previousModule, | ||
@@ -57,21 +126,24 @@ failed: config.moduleStats.bad, | ||
total: config.moduleStats.all | ||
} ); | ||
}); | ||
} | ||
config.previousModule = this.module; | ||
config.moduleStats = { all: 0, bad: 0 }; | ||
runLoggingCallbacks( 'moduleStart', QUnit, { | ||
runLoggingCallbacks( "moduleStart", QUnit, { | ||
name: this.module | ||
} ); | ||
}); | ||
} else if ( config.autorun ) { | ||
runLoggingCallbacks( "moduleStart", QUnit, { | ||
name: this.module | ||
}); | ||
} | ||
config.current = this; | ||
this.testEnvironment = extend({ | ||
setup: function() {}, | ||
teardown: function() {} | ||
}, this.moduleTestEnvironment); | ||
if (this.testEnvironmentArg) { | ||
extend(this.testEnvironment, this.testEnvironmentArg); | ||
} | ||
}, this.moduleTestEnvironment ); | ||
runLoggingCallbacks( 'testStart', QUnit, { | ||
this.started = +new Date(); | ||
runLoggingCallbacks( "testStart", QUnit, { | ||
name: this.testName, | ||
@@ -85,13 +157,24 @@ module: this.module | ||
if ( !config.pollution ) { | ||
saveGlobal(); | ||
} | ||
if ( config.notrycatch ) { | ||
this.testEnvironment.setup.call( this.testEnvironment ); | ||
return; | ||
} | ||
try { | ||
if ( !config.pollution ) { | ||
saveGlobal(); | ||
} | ||
this.testEnvironment.setup.call(this.testEnvironment); | ||
} catch(e) { | ||
QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message ); | ||
this.testEnvironment.setup.call( this.testEnvironment ); | ||
} catch( e ) { | ||
QUnit.pushFailure( "Setup failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); | ||
} | ||
}, | ||
run: function() { | ||
config.current = this; | ||
var running = id( "qunit-testresult" ); | ||
if ( running ) { | ||
running.innerHTML = "Running: <br/>" + this.nameHtml; | ||
} | ||
if ( this.async ) { | ||
@@ -101,11 +184,17 @@ QUnit.stop(); | ||
this.callbackStarted = +new Date(); | ||
if ( config.notrycatch ) { | ||
this.callback.call(this.testEnvironment); | ||
this.callback.call( this.testEnvironment, QUnit.assert ); | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
return; | ||
} | ||
try { | ||
this.callback.call(this.testEnvironment); | ||
} catch(e) { | ||
fail("Test " + this.testName + " died, exception and test follows", e, this.callback); | ||
QUnit.ok( false, "Died on test #" + (this.assertions.length + 1) + ": " + e.message + " - " + QUnit.jsDump.parse(e) ); | ||
this.callback.call( this.testEnvironment, QUnit.assert ); | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
} catch( e ) { | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) ); | ||
// else next test will carry the responsibility | ||
@@ -116,3 +205,3 @@ saveGlobal(); | ||
if ( config.blocking ) { | ||
start(); | ||
QUnit.start(); | ||
} | ||
@@ -122,17 +211,35 @@ } | ||
teardown: function() { | ||
try { | ||
this.testEnvironment.teardown.call(this.testEnvironment); | ||
checkPollution(); | ||
} catch(e) { | ||
QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message ); | ||
config.current = this; | ||
if ( config.notrycatch ) { | ||
if ( typeof this.callbackRuntime === "undefined" ) { | ||
this.callbackRuntime = +new Date() - this.callbackStarted; | ||
} | ||
this.testEnvironment.teardown.call( this.testEnvironment ); | ||
return; | ||
} else { | ||
try { | ||
this.testEnvironment.teardown.call( this.testEnvironment ); | ||
} catch( e ) { | ||
QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + ( e.message || e ), extractStacktrace( e, 1 ) ); | ||
} | ||
} | ||
checkPollution(); | ||
}, | ||
finish: function() { | ||
if ( this.expected && this.expected != this.assertions.length ) { | ||
QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" ); | ||
config.current = this; | ||
if ( config.requireExpects && this.expected === null ) { | ||
QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack ); | ||
} else if ( this.expected !== null && this.expected !== this.assertions.length ) { | ||
QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack ); | ||
} else if ( this.expected === null && !this.assertions.length ) { | ||
QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack ); | ||
} | ||
var good = 0, bad = 0, | ||
tests = id("qunit-tests"); | ||
var i, assertion, a, b, time, li, ol, | ||
test = this, | ||
good = 0, | ||
bad = 0, | ||
tests = id( "qunit-tests" ); | ||
this.runtime = +new Date() - this.started; | ||
config.stats.all += this.assertions.length; | ||
@@ -142,10 +249,11 @@ config.moduleStats.all += this.assertions.length; | ||
if ( tests ) { | ||
var ol = document.createElement("ol"); | ||
ol = document.createElement( "ol" ); | ||
ol.className = "qunit-assert-list"; | ||
for ( var i = 0; i < this.assertions.length; i++ ) { | ||
var assertion = this.assertions[i]; | ||
for ( i = 0; i < this.assertions.length; i++ ) { | ||
assertion = this.assertions[i]; | ||
var li = document.createElement("li"); | ||
li = document.createElement( "li" ); | ||
li.className = assertion.result ? "pass" : "fail"; | ||
li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed"); | ||
li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); | ||
ol.appendChild( li ); | ||
@@ -164,45 +272,50 @@ | ||
if ( QUnit.config.reorder && defined.sessionStorage ) { | ||
if (bad) { | ||
sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad); | ||
if ( bad ) { | ||
sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); | ||
} else { | ||
sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName); | ||
sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
} | ||
} | ||
if (bad == 0) { | ||
ol.style.display = "none"; | ||
if ( bad === 0 ) { | ||
addClass( ol, "qunit-collapsed" ); | ||
} | ||
var b = document.createElement("strong"); | ||
b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>"; | ||
// `b` initialized at top of scope | ||
b = document.createElement( "strong" ); | ||
b.innerHTML = this.nameHtml + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>"; | ||
var a = document.createElement("a"); | ||
a.innerHTML = "Rerun"; | ||
a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") }); | ||
addEvent(b, "click", function() { | ||
var next = b.nextSibling.nextSibling, | ||
display = next.style.display; | ||
next.style.display = display === "none" ? "block" : "none"; | ||
var next = b.parentNode.lastChild, | ||
collapsed = hasClass( next, "qunit-collapsed" ); | ||
( collapsed ? removeClass : addClass )( next, "qunit-collapsed" ); | ||
}); | ||
addEvent(b, "dblclick", function(e) { | ||
addEvent(b, "dblclick", function( e ) { | ||
var target = e && e.target ? e.target : window.event.srcElement; | ||
if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) { | ||
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { | ||
target = target.parentNode; | ||
} | ||
if ( window.location && target.nodeName.toLowerCase() === "strong" ) { | ||
window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") }); | ||
window.location = QUnit.url({ testNumber: test.testNumber }); | ||
} | ||
}); | ||
var li = id(this.id); | ||
// `time` initialized at top of scope | ||
time = document.createElement( "span" ); | ||
time.className = "runtime"; | ||
time.innerHTML = this.runtime + " ms"; | ||
// `li` initialized at top of scope | ||
li = id( this.id ); | ||
li.className = bad ? "fail" : "pass"; | ||
li.removeChild( li.firstChild ); | ||
a = li.firstChild; | ||
li.appendChild( b ); | ||
li.appendChild( a ); | ||
li.appendChild( time ); | ||
li.appendChild( ol ); | ||
} else { | ||
for ( var i = 0; i < this.assertions.length; i++ ) { | ||
for ( i = 0; i < this.assertions.length; i++ ) { | ||
if ( !this.assertions[i].result ) { | ||
@@ -216,9 +329,3 @@ bad++; | ||
try { | ||
QUnit.reset(); | ||
} catch(e) { | ||
fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset); | ||
} | ||
runLoggingCallbacks( 'testDone', QUnit, { | ||
runLoggingCallbacks( "testDone", QUnit, { | ||
name: this.testName, | ||
@@ -228,8 +335,15 @@ module: this.module, | ||
passed: this.assertions.length - bad, | ||
total: this.assertions.length | ||
} ); | ||
total: this.assertions.length, | ||
duration: this.runtime | ||
}); | ||
QUnit.reset(); | ||
config.current = undefined; | ||
}, | ||
queue: function() { | ||
var test = this; | ||
var bad, | ||
test = this; | ||
synchronize(function() { | ||
@@ -253,32 +367,39 @@ test.init(); | ||
} | ||
// `bad` initialized at top of scope | ||
// defer when previous test run passed, if storage is available | ||
var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName); | ||
if (bad) { | ||
bad = QUnit.config.reorder && defined.sessionStorage && | ||
+sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
if ( bad ) { | ||
run(); | ||
} else { | ||
synchronize(run); | ||
}; | ||
synchronize( run, true ); | ||
} | ||
} | ||
}; | ||
var QUnit = { | ||
// Root QUnit object. | ||
// `QUnit` initialized at top of scope | ||
QUnit = { | ||
// call on start of module test to prepend name to all tests | ||
module: function(name, testEnvironment) { | ||
module: function( name, testEnvironment ) { | ||
config.currentModule = name; | ||
config.currentModuleTestEnviroment = testEnvironment; | ||
config.currentModuleTestEnvironment = testEnvironment; | ||
config.modules[name] = true; | ||
}, | ||
asyncTest: function(testName, expected, callback) { | ||
asyncTest: function( testName, expected, callback ) { | ||
if ( arguments.length === 2 ) { | ||
callback = expected; | ||
expected = 0; | ||
expected = null; | ||
} | ||
QUnit.test(testName, expected, callback, true); | ||
QUnit.test( testName, expected, callback, true ); | ||
}, | ||
test: function(testName, expected, callback, async) { | ||
var name = '<span class="test-name">' + testName + '</span>', testEnvironmentArg; | ||
test: function( testName, expected, callback, async ) { | ||
var test, | ||
nameHtml = "<span class='test-name'>" + escapeText( testName ) + "</span>"; | ||
@@ -289,43 +410,133 @@ if ( arguments.length === 2 ) { | ||
} | ||
// is 2nd argument a testEnvironment? | ||
if ( expected && typeof expected === 'object') { | ||
testEnvironmentArg = expected; | ||
expected = null; | ||
} | ||
if ( config.currentModule ) { | ||
name = '<span class="module-name">' + config.currentModule + "</span>: " + name; | ||
nameHtml = "<span class='module-name'>" + escapeText( config.currentModule ) + "</span>: " + nameHtml; | ||
} | ||
if ( !validTest(config.currentModule + ": " + testName) ) { | ||
test = new Test({ | ||
nameHtml: nameHtml, | ||
testName: testName, | ||
expected: expected, | ||
async: async, | ||
callback: callback, | ||
module: config.currentModule, | ||
moduleTestEnvironment: config.currentModuleTestEnvironment, | ||
stack: sourceFromStacktrace( 2 ) | ||
}); | ||
if ( !validTest( test ) ) { | ||
return; | ||
} | ||
var test = new Test(name, testName, expected, testEnvironmentArg, async, callback); | ||
test.module = config.currentModule; | ||
test.moduleTestEnvironment = config.currentModuleTestEnviroment; | ||
test.queue(); | ||
}, | ||
/** | ||
* Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. | ||
*/ | ||
expect: function(asserts) { | ||
config.current.expected = asserts; | ||
// Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. | ||
expect: function( asserts ) { | ||
if (arguments.length === 1) { | ||
config.current.expected = asserts; | ||
} else { | ||
return config.current.expected; | ||
} | ||
}, | ||
start: function( count ) { | ||
// QUnit hasn't been initialized yet. | ||
// Note: RequireJS (et al) may delay onLoad | ||
if ( config.semaphore === undefined ) { | ||
QUnit.begin(function() { | ||
// This is triggered at the top of QUnit.load, push start() to the event loop, to allow QUnit.load to finish first | ||
setTimeout(function() { | ||
QUnit.start( count ); | ||
}); | ||
}); | ||
return; | ||
} | ||
config.semaphore -= count || 1; | ||
// don't start until equal number of stop-calls | ||
if ( config.semaphore > 0 ) { | ||
return; | ||
} | ||
// ignore if start is called more often then stop | ||
if ( config.semaphore < 0 ) { | ||
config.semaphore = 0; | ||
QUnit.pushFailure( "Called start() while already started (QUnit.config.semaphore was 0 already)", null, sourceFromStacktrace(2) ); | ||
return; | ||
} | ||
// A slight delay, to avoid any current callbacks | ||
if ( defined.setTimeout ) { | ||
window.setTimeout(function() { | ||
if ( config.semaphore > 0 ) { | ||
return; | ||
} | ||
if ( config.timeout ) { | ||
clearTimeout( config.timeout ); | ||
} | ||
config.blocking = false; | ||
process( true ); | ||
}, 13); | ||
} else { | ||
config.blocking = false; | ||
process( true ); | ||
} | ||
}, | ||
stop: function( count ) { | ||
config.semaphore += count || 1; | ||
config.blocking = true; | ||
if ( config.testTimeout && defined.setTimeout ) { | ||
clearTimeout( config.timeout ); | ||
config.timeout = window.setTimeout(function() { | ||
QUnit.ok( false, "Test timed out" ); | ||
config.semaphore = 1; | ||
QUnit.start(); | ||
}, config.testTimeout ); | ||
} | ||
} | ||
}; | ||
// `assert` initialized at top of scope | ||
// Asssert helpers | ||
// All of these must either call QUnit.push() or manually do: | ||
// - runLoggingCallbacks( "log", .. ); | ||
// - config.current.assertions.push({ .. }); | ||
// We attach it to the QUnit object *after* we expose the public API, | ||
// otherwise `assert` will become a global variable in browsers (#341). | ||
assert = { | ||
/** | ||
* Asserts true. | ||
* Asserts rough true-ish result. | ||
* @name ok | ||
* @function | ||
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); | ||
*/ | ||
ok: function(a, msg) { | ||
a = !!a; | ||
var details = { | ||
result: a, | ||
message: msg | ||
}; | ||
msg = escapeInnerText(msg); | ||
runLoggingCallbacks( 'log', QUnit, details ); | ||
ok: function( result, msg ) { | ||
if ( !config.current ) { | ||
throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); | ||
} | ||
result = !!result; | ||
var source, | ||
details = { | ||
module: config.current.module, | ||
name: config.current.testName, | ||
result: result, | ||
message: msg | ||
}; | ||
msg = escapeText( msg || (result ? "okay" : "failed" ) ); | ||
msg = "<span class='test-message'>" + msg + "</span>"; | ||
if ( !result ) { | ||
source = sourceFromStacktrace( 2 ); | ||
if ( source ) { | ||
details.source = source; | ||
msg += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr></table>"; | ||
} | ||
} | ||
runLoggingCallbacks( "log", QUnit, details ); | ||
config.current.assertions.push({ | ||
result: a, | ||
result: result, | ||
message: msg | ||
@@ -336,41 +547,81 @@ }); | ||
/** | ||
* Checks that the first two arguments are equal, with an optional message. | ||
* Assert that the first two arguments are equal, with an optional message. | ||
* Prints out both actual and expected values. | ||
* | ||
* Prefered to ok( actual == expected, message ) | ||
* | ||
* @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." ); | ||
* | ||
* @param Object actual | ||
* @param Object expected | ||
* @param String message (optional) | ||
* @name equal | ||
* @function | ||
* @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); | ||
*/ | ||
equal: function(actual, expected, message) { | ||
QUnit.push(expected == actual, actual, expected, message); | ||
equal: function( actual, expected, message ) { | ||
/*jshint eqeqeq:false */ | ||
QUnit.push( expected == actual, actual, expected, message ); | ||
}, | ||
notEqual: function(actual, expected, message) { | ||
QUnit.push(expected != actual, actual, expected, message); | ||
/** | ||
* @name notEqual | ||
* @function | ||
*/ | ||
notEqual: function( actual, expected, message ) { | ||
/*jshint eqeqeq:false */ | ||
QUnit.push( expected != actual, actual, expected, message ); | ||
}, | ||
deepEqual: function(actual, expected, message) { | ||
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); | ||
/** | ||
* @name propEqual | ||
* @function | ||
*/ | ||
propEqual: function( actual, expected, message ) { | ||
actual = objectValues(actual); | ||
expected = objectValues(expected); | ||
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
notDeepEqual: function(actual, expected, message) { | ||
QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message); | ||
/** | ||
* @name notPropEqual | ||
* @function | ||
*/ | ||
notPropEqual: function( actual, expected, message ) { | ||
actual = objectValues(actual); | ||
expected = objectValues(expected); | ||
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
strictEqual: function(actual, expected, message) { | ||
QUnit.push(expected === actual, actual, expected, message); | ||
/** | ||
* @name deepEqual | ||
* @function | ||
*/ | ||
deepEqual: function( actual, expected, message ) { | ||
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
notStrictEqual: function(actual, expected, message) { | ||
QUnit.push(expected !== actual, actual, expected, message); | ||
/** | ||
* @name notDeepEqual | ||
* @function | ||
*/ | ||
notDeepEqual: function( actual, expected, message ) { | ||
QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
}, | ||
raises: function(block, expected, message) { | ||
var actual, ok = false; | ||
/** | ||
* @name strictEqual | ||
* @function | ||
*/ | ||
strictEqual: function( actual, expected, message ) { | ||
QUnit.push( expected === actual, actual, expected, message ); | ||
}, | ||
if (typeof expected === 'string') { | ||
/** | ||
* @name notStrictEqual | ||
* @function | ||
*/ | ||
notStrictEqual: function( actual, expected, message ) { | ||
QUnit.push( expected !== actual, actual, expected, message ); | ||
}, | ||
"throws": function( block, expected, message ) { | ||
var actual, | ||
expectedOutput = expected, | ||
ok = false; | ||
// 'expected' is optional | ||
if ( typeof expected === "string" ) { | ||
message = expected; | ||
@@ -380,86 +631,73 @@ expected = null; | ||
config.current.ignoreGlobalErrors = true; | ||
try { | ||
block(); | ||
block.call( config.current.testEnvironment ); | ||
} catch (e) { | ||
actual = e; | ||
} | ||
config.current.ignoreGlobalErrors = false; | ||
if (actual) { | ||
if ( actual ) { | ||
// we don't want to validate thrown error | ||
if (!expected) { | ||
if ( !expected ) { | ||
ok = true; | ||
expectedOutput = null; | ||
// expected is a regexp | ||
} else if (QUnit.objectType(expected) === "regexp") { | ||
ok = expected.test(actual); | ||
} else if ( QUnit.objectType( expected ) === "regexp" ) { | ||
ok = expected.test( errorString( actual ) ); | ||
// expected is a constructor | ||
} else if (actual instanceof expected) { | ||
} else if ( actual instanceof expected ) { | ||
ok = true; | ||
// expected is a validation function which returns true is validation passed | ||
} else if (expected.call({}, actual) === true) { | ||
} else if ( expected.call( {}, actual ) === true ) { | ||
expectedOutput = null; | ||
ok = true; | ||
} | ||
} | ||
QUnit.ok(ok, message); | ||
}, | ||
start: function(count) { | ||
config.semaphore -= count || 1; | ||
if (config.semaphore > 0) { | ||
// don't start until equal number of stop-calls | ||
return; | ||
} | ||
if (config.semaphore < 0) { | ||
// ignore if start is called more often then stop | ||
config.semaphore = 0; | ||
} | ||
// A slight delay, to avoid any current callbacks | ||
if ( defined.setTimeout ) { | ||
window.setTimeout(function() { | ||
if (config.semaphore > 0) { | ||
return; | ||
} | ||
if ( config.timeout ) { | ||
clearTimeout(config.timeout); | ||
} | ||
config.blocking = false; | ||
process(); | ||
}, 13); | ||
QUnit.push( ok, actual, expectedOutput, message ); | ||
} else { | ||
config.blocking = false; | ||
process(); | ||
QUnit.pushFailure( message, null, 'No exception was thrown.' ); | ||
} | ||
}, | ||
} | ||
}; | ||
stop: function(count) { | ||
config.semaphore += count || 1; | ||
config.blocking = true; | ||
/** | ||
* @deprecate since 1.8.0 | ||
* Kept assertion helpers in root for backwards compatibility. | ||
*/ | ||
extend( QUnit, assert ); | ||
if ( config.testTimeout && defined.setTimeout ) { | ||
clearTimeout(config.timeout); | ||
config.timeout = window.setTimeout(function() { | ||
QUnit.ok( false, "Test timed out" ); | ||
config.semaphore = 1; | ||
QUnit.start(); | ||
}, config.testTimeout); | ||
} | ||
} | ||
/** | ||
* @deprecated since 1.9.0 | ||
* Kept root "raises()" for backwards compatibility. | ||
* (Note that we don't introduce assert.raises). | ||
*/ | ||
QUnit.raises = assert[ "throws" ]; | ||
/** | ||
* @deprecated since 1.0.0, replaced with error pushes since 1.3.0 | ||
* Kept to avoid TypeErrors for undefined methods. | ||
*/ | ||
QUnit.equals = function() { | ||
QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); | ||
}; | ||
QUnit.same = function() { | ||
QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); | ||
}; | ||
//We want access to the constructor's prototype | ||
// We want access to the constructor's prototype | ||
(function() { | ||
function F(){}; | ||
function F() {} | ||
F.prototype = QUnit; | ||
QUnit = new F(); | ||
//Make F QUnit's constructor so that we can add to the prototype later | ||
// Make F QUnit's constructor so that we can add to the prototype later | ||
QUnit.constructor = F; | ||
})(); | ||
}()); | ||
// Backwards compatibility, deprecated | ||
QUnit.equals = QUnit.equal; | ||
QUnit.same = QUnit.deepEqual; | ||
// Maintain internal state | ||
var config = { | ||
/** | ||
* Config object: Maintain internal state | ||
* Later exposed as QUnit.config | ||
* `config` initialized at top of scope | ||
*/ | ||
config = { | ||
// The queue of tests to run | ||
@@ -482,5 +720,24 @@ queue: [], | ||
urlConfig: ['noglobals', 'notrycatch'], | ||
// when enabled, all tests must call expect() | ||
requireExpects: false, | ||
//logging callback queues | ||
// add checkboxes that are persisted in the query-string | ||
// when enabled, the id is set to `true` as a `QUnit.config` property | ||
urlConfig: [ | ||
{ | ||
id: "noglobals", | ||
label: "Check for Globals", | ||
tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." | ||
}, | ||
{ | ||
id: "notrycatch", | ||
label: "No try-catch", | ||
tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." | ||
} | ||
], | ||
// Set of all modules. | ||
modules: {}, | ||
// logging callback queues | ||
begin: [], | ||
@@ -495,5 +752,15 @@ done: [], | ||
// Load paramaters | ||
// Export global variables, unless an 'exports' object exists, | ||
// in that case we assume we're in CommonJS (dealt with on the bottom of the script) | ||
if ( typeof exports === "undefined" ) { | ||
extend( window, QUnit ); | ||
// Expose QUnit object | ||
window.QUnit = QUnit; | ||
} | ||
// Initialize more QUnit.config and QUnit.urlParams | ||
(function() { | ||
var location = window.location || { search: "", protocol: "file:" }, | ||
var i, | ||
location = window.location || { search: "", protocol: "file:" }, | ||
params = location.search.slice( 1 ).split( "&" ), | ||
@@ -505,3 +772,3 @@ length = params.length, | ||
if ( params[ 0 ] ) { | ||
for ( var i = 0; i < length; i++ ) { | ||
for ( i = 0; i < length; i++ ) { | ||
current = params[ i ].split( "=" ); | ||
@@ -516,20 +783,20 @@ current[ 0 ] = decodeURIComponent( current[ 0 ] ); | ||
QUnit.urlParams = urlParams; | ||
// String search anywhere in moduleName+testName | ||
config.filter = urlParams.filter; | ||
// Exact match of the module name | ||
config.module = urlParams.module; | ||
config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; | ||
// Figure out if we're running the tests from a server or not | ||
QUnit.isLocal = !!(location.protocol === 'file:'); | ||
})(); | ||
QUnit.isLocal = location.protocol === "file:"; | ||
}()); | ||
// Expose the API as global variables, unless an 'exports' | ||
// object exists, in that case we assume we're in CommonJS | ||
if ( typeof exports === "undefined" || typeof require === "undefined" ) { | ||
extend(window, QUnit); | ||
window.QUnit = QUnit; | ||
} else { | ||
extend(exports, QUnit); | ||
exports.QUnit = QUnit; | ||
} | ||
// Extend QUnit object, | ||
// these after set here because they should not be exposed as global functions | ||
extend( QUnit, { | ||
assert: assert, | ||
// define these after exposing globals to keep them in these QUnit namespace only | ||
extend(QUnit, { | ||
config: config, | ||
@@ -539,6 +806,6 @@ | ||
init: function() { | ||
extend(config, { | ||
extend( config, { | ||
stats: { all: 0, bad: 0 }, | ||
moduleStats: { all: 0, bad: 0 }, | ||
started: +new Date, | ||
started: +new Date(), | ||
updateRate: 1000, | ||
@@ -550,9 +817,21 @@ blocking: false, | ||
queue: [], | ||
semaphore: 0 | ||
semaphore: 1 | ||
}); | ||
var tests = id( "qunit-tests" ), | ||
banner = id( "qunit-banner" ), | ||
result = id( "qunit-testresult" ); | ||
var tests, banner, result, | ||
qunit = id( "qunit" ); | ||
if ( qunit ) { | ||
qunit.innerHTML = | ||
"<h1 id='qunit-header'>" + escapeText( document.title ) + "</h1>" + | ||
"<h2 id='qunit-banner'></h2>" + | ||
"<div id='qunit-testrunner-toolbar'></div>" + | ||
"<h2 id='qunit-userAgent'></h2>" + | ||
"<ol id='qunit-tests'></ol>"; | ||
} | ||
tests = id( "qunit-tests" ); | ||
banner = id( "qunit-banner" ); | ||
result = id( "qunit-testresult" ); | ||
if ( tests ) { | ||
@@ -575,39 +854,25 @@ tests.innerHTML = ""; | ||
tests.parentNode.insertBefore( result, tests ); | ||
result.innerHTML = 'Running...<br/> '; | ||
result.innerHTML = "Running...<br/> "; | ||
} | ||
}, | ||
/** | ||
* Resets the test setup. Useful for tests that modify the DOM. | ||
* | ||
* If jQuery is available, uses jQuery's html(), otherwise just innerHTML. | ||
*/ | ||
// Resets the test setup. Useful for tests that modify the DOM. | ||
reset: function() { | ||
if ( window.jQuery ) { | ||
jQuery( "#qunit-fixture" ).html( config.fixture ); | ||
} else { | ||
var main = id( 'qunit-fixture' ); | ||
if ( main ) { | ||
main.innerHTML = config.fixture; | ||
} | ||
var fixture = id( "qunit-fixture" ); | ||
if ( fixture ) { | ||
fixture.innerHTML = config.fixture; | ||
} | ||
}, | ||
/** | ||
* Trigger an event on an element. | ||
* | ||
* @example triggerEvent( document.body, "click" ); | ||
* | ||
* @param DOMElement elem | ||
* @param String type | ||
*/ | ||
// Trigger an event on an element. | ||
// @example triggerEvent( document.body, "click" ); | ||
triggerEvent: function( elem, type, event ) { | ||
if ( document.createEvent ) { | ||
event = document.createEvent("MouseEvents"); | ||
event = document.createEvent( "MouseEvents" ); | ||
event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, | ||
0, 0, 0, 0, 0, false, false, false, false, 0, null); | ||
elem.dispatchEvent( event ); | ||
} else if ( elem.fireEvent ) { | ||
elem.fireEvent("on"+type); | ||
elem.fireEvent( "on" + type ); | ||
} | ||
@@ -618,35 +883,33 @@ }, | ||
is: function( type, obj ) { | ||
return QUnit.objectType( obj ) == type; | ||
return QUnit.objectType( obj ) === type; | ||
}, | ||
objectType: function( obj ) { | ||
if (typeof obj === "undefined") { | ||
if ( typeof obj === "undefined" ) { | ||
return "undefined"; | ||
// consider: typeof null === object | ||
} | ||
if (obj === null) { | ||
if ( obj === null ) { | ||
return "null"; | ||
} | ||
var type = Object.prototype.toString.call( obj ) | ||
.match(/^\[object\s(.*)\]$/)[1] || ''; | ||
var match = toString.call( obj ).match(/^\[object\s(.*)\]$/), | ||
type = match && match[1] || ""; | ||
switch (type) { | ||
case 'Number': | ||
if (isNaN(obj)) { | ||
return "nan"; | ||
} else { | ||
return "number"; | ||
} | ||
case 'String': | ||
case 'Boolean': | ||
case 'Array': | ||
case 'Date': | ||
case 'RegExp': | ||
case 'Function': | ||
return type.toLowerCase(); | ||
switch ( type ) { | ||
case "Number": | ||
if ( isNaN(obj) ) { | ||
return "nan"; | ||
} | ||
return "number"; | ||
case "String": | ||
case "Boolean": | ||
case "Array": | ||
case "Date": | ||
case "RegExp": | ||
case "Function": | ||
return type.toLowerCase(); | ||
} | ||
if (typeof obj === "object") { | ||
return "object"; | ||
if ( typeof obj === "object" ) { | ||
return "object"; | ||
} | ||
@@ -656,29 +919,42 @@ return undefined; | ||
push: function(result, actual, expected, message) { | ||
var details = { | ||
result: result, | ||
message: message, | ||
actual: actual, | ||
expected: expected | ||
}; | ||
push: function( result, actual, expected, message ) { | ||
if ( !config.current ) { | ||
throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); | ||
} | ||
message = escapeInnerText(message) || (result ? "okay" : "failed"); | ||
message = '<span class="test-message">' + message + "</span>"; | ||
expected = escapeInnerText(QUnit.jsDump.parse(expected)); | ||
actual = escapeInnerText(QUnit.jsDump.parse(actual)); | ||
var output = message + '<table><tr class="test-expected"><th>Expected: </th><td><pre>' + expected + '</pre></td></tr>'; | ||
if (actual != expected) { | ||
output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>'; | ||
output += '<tr class="test-diff"><th>Diff: </th><td><pre>' + QUnit.diff(expected, actual) +'</pre></td></tr>'; | ||
} | ||
if (!result) { | ||
var source = sourceFromStacktrace(); | ||
if (source) { | ||
var output, source, | ||
details = { | ||
module: config.current.module, | ||
name: config.current.testName, | ||
result: result, | ||
message: message, | ||
actual: actual, | ||
expected: expected | ||
}; | ||
message = escapeText( message ) || ( result ? "okay" : "failed" ); | ||
message = "<span class='test-message'>" + message + "</span>"; | ||
output = message; | ||
if ( !result ) { | ||
expected = escapeText( QUnit.jsDump.parse(expected) ); | ||
actual = escapeText( QUnit.jsDump.parse(actual) ); | ||
output += "<table><tr class='test-expected'><th>Expected: </th><td><pre>" + expected + "</pre></td></tr>"; | ||
if ( actual !== expected ) { | ||
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + actual + "</pre></td></tr>"; | ||
output += "<tr class='test-diff'><th>Diff: </th><td><pre>" + QUnit.diff( expected, actual ) + "</pre></td></tr>"; | ||
} | ||
source = sourceFromStacktrace(); | ||
if ( source ) { | ||
details.source = source; | ||
output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeInnerText(source) + '</pre></td></tr>'; | ||
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>"; | ||
} | ||
output += "</table>"; | ||
} | ||
output += "</table>"; | ||
runLoggingCallbacks( 'log', QUnit, details ); | ||
runLoggingCallbacks( "log", QUnit, details ); | ||
@@ -691,11 +967,54 @@ config.current.assertions.push({ | ||
pushFailure: function( message, source, actual ) { | ||
if ( !config.current ) { | ||
throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); | ||
} | ||
var output, | ||
details = { | ||
module: config.current.module, | ||
name: config.current.testName, | ||
result: false, | ||
message: message | ||
}; | ||
message = escapeText( message ) || "error"; | ||
message = "<span class='test-message'>" + message + "</span>"; | ||
output = message; | ||
output += "<table>"; | ||
if ( actual ) { | ||
output += "<tr class='test-actual'><th>Result: </th><td><pre>" + escapeText( actual ) + "</pre></td></tr>"; | ||
} | ||
if ( source ) { | ||
details.source = source; | ||
output += "<tr class='test-source'><th>Source: </th><td><pre>" + escapeText( source ) + "</pre></td></tr>"; | ||
} | ||
output += "</table>"; | ||
runLoggingCallbacks( "log", QUnit, details ); | ||
config.current.assertions.push({ | ||
result: false, | ||
message: output | ||
}); | ||
}, | ||
url: function( params ) { | ||
params = extend( extend( {}, QUnit.urlParams ), params ); | ||
var querystring = "?", | ||
key; | ||
var key, | ||
querystring = "?"; | ||
for ( key in params ) { | ||
if ( !hasOwn.call( params, key ) ) { | ||
continue; | ||
} | ||
querystring += encodeURIComponent( key ) + "=" + | ||
encodeURIComponent( params[ key ] ) + "&"; | ||
} | ||
return window.location.pathname + querystring.slice( 0, -1 ); | ||
return window.location.protocol + "//" + window.location.host + | ||
window.location.pathname + querystring.slice( 0, -1 ); | ||
}, | ||
@@ -706,23 +1025,35 @@ | ||
addEvent: addEvent | ||
// load, equiv, jsDump, diff: Attached later | ||
}); | ||
//QUnit.constructor is set to the empty F() above so that we can add to it's prototype later | ||
//Doing this allows us to tell if the following methods have been overwritten on the actual | ||
//QUnit object, which is a deprecated way of using the callbacks. | ||
extend(QUnit.constructor.prototype, { | ||
/** | ||
* @deprecated: Created for backwards compatibility with test runner that set the hook function | ||
* into QUnit.{hook}, instead of invoking it and passing the hook function. | ||
* QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. | ||
* Doing this allows us to tell if the following methods have been overwritten on the actual | ||
* QUnit object. | ||
*/ | ||
extend( QUnit.constructor.prototype, { | ||
// Logging callbacks; all receive a single argument with the listed properties | ||
// run test/logs.html for any related changes | ||
begin: registerLoggingCallback('begin'), | ||
begin: registerLoggingCallback( "begin" ), | ||
// done: { failed, passed, total, runtime } | ||
done: registerLoggingCallback('done'), | ||
done: registerLoggingCallback( "done" ), | ||
// log: { result, actual, expected, message } | ||
log: registerLoggingCallback('log'), | ||
log: registerLoggingCallback( "log" ), | ||
// testStart: { name } | ||
testStart: registerLoggingCallback('testStart'), | ||
// testDone: { name, failed, passed, total } | ||
testDone: registerLoggingCallback('testDone'), | ||
testStart: registerLoggingCallback( "testStart" ), | ||
// testDone: { name, failed, passed, total, duration } | ||
testDone: registerLoggingCallback( "testDone" ), | ||
// moduleStart: { name } | ||
moduleStart: registerLoggingCallback('moduleStart'), | ||
moduleStart: registerLoggingCallback( "moduleStart" ), | ||
// moduleDone: { name, failed, passed, total } | ||
moduleDone: registerLoggingCallback('moduleDone') | ||
moduleDone: registerLoggingCallback( "moduleDone" ) | ||
}); | ||
@@ -735,6 +1066,12 @@ | ||
QUnit.load = function() { | ||
runLoggingCallbacks( 'begin', QUnit, {} ); | ||
runLoggingCallbacks( "begin", QUnit, {} ); | ||
// Initialize the config, saving the execution queue | ||
var oldconfig = extend({}, config); | ||
var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, | ||
urlConfigCheckboxesContainer, urlConfigCheckboxes, moduleFilter, | ||
numModules = 0, | ||
moduleFilterHtml = "", | ||
urlConfigHtml = "", | ||
oldconfig = extend( {}, config ); | ||
QUnit.init(); | ||
@@ -745,46 +1082,79 @@ extend(config, oldconfig); | ||
var urlConfigHtml = '', len = config.urlConfig.length; | ||
for ( var i = 0, val; i < len, val = config.urlConfig[i]; i++ ) { | ||
config[val] = QUnit.urlParams[val]; | ||
urlConfigHtml += '<label><input name="' + val + '" type="checkbox"' + ( config[val] ? ' checked="checked"' : '' ) + '>' + val + '</label>'; | ||
len = config.urlConfig.length; | ||
for ( i = 0; i < len; i++ ) { | ||
val = config.urlConfig[i]; | ||
if ( typeof val === "string" ) { | ||
val = { | ||
id: val, | ||
label: val, | ||
tooltip: "[no tooltip available]" | ||
}; | ||
} | ||
config[ val.id ] = QUnit.urlParams[ val.id ]; | ||
urlConfigHtml += "<input id='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' name='" + escapeText( val.id ) + | ||
"' type='checkbox'" + ( config[ val.id ] ? " checked='checked'" : "" ) + | ||
" title='" + escapeText( val.tooltip ) + | ||
"'><label for='qunit-urlconfig-" + escapeText( val.id ) + | ||
"' title='" + escapeText( val.tooltip ) + "'>" + val.label + "</label>"; | ||
} | ||
var userAgent = id("qunit-userAgent"); | ||
moduleFilterHtml += "<label for='qunit-modulefilter'>Module: </label><select id='qunit-modulefilter' name='modulefilter'><option value='' " + | ||
( config.module === undefined ? "selected='selected'" : "" ) + | ||
">< All Modules ></option>"; | ||
for ( i in config.modules ) { | ||
if ( config.modules.hasOwnProperty( i ) ) { | ||
numModules += 1; | ||
moduleFilterHtml += "<option value='" + escapeText( encodeURIComponent(i) ) + "' " + | ||
( config.module === i ? "selected='selected'" : "" ) + | ||
">" + escapeText(i) + "</option>"; | ||
} | ||
} | ||
moduleFilterHtml += "</select>"; | ||
// `userAgent` initialized at top of scope | ||
userAgent = id( "qunit-userAgent" ); | ||
if ( userAgent ) { | ||
userAgent.innerHTML = navigator.userAgent; | ||
} | ||
var banner = id("qunit-header"); | ||
// `banner` initialized at top of scope | ||
banner = id( "qunit-header" ); | ||
if ( banner ) { | ||
banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' + urlConfigHtml; | ||
addEvent( banner, "change", function( event ) { | ||
var params = {}; | ||
params[ event.target.name ] = event.target.checked ? true : undefined; | ||
window.location = QUnit.url( params ); | ||
}); | ||
banner.innerHTML = "<a href='" + QUnit.url({ filter: undefined, module: undefined, testNumber: undefined }) + "'>" + banner.innerHTML + "</a> "; | ||
} | ||
var toolbar = id("qunit-testrunner-toolbar"); | ||
// `toolbar` initialized at top of scope | ||
toolbar = id( "qunit-testrunner-toolbar" ); | ||
if ( toolbar ) { | ||
var filter = document.createElement("input"); | ||
// `filter` initialized at top of scope | ||
filter = document.createElement( "input" ); | ||
filter.type = "checkbox"; | ||
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, " " ) + " "; | ||
ol.className = tmp.replace(/ hidepass /, " "); | ||
tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; | ||
ol.className = tmp.replace( / hidepass /, " " ); | ||
} | ||
if ( defined.sessionStorage ) { | ||
if (filter.checked) { | ||
sessionStorage.setItem("qunit-filter-passed-tests", "true"); | ||
sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); | ||
} else { | ||
sessionStorage.removeItem("qunit-filter-passed-tests"); | ||
sessionStorage.removeItem( "qunit-filter-passed-tests" ); | ||
} | ||
} | ||
}); | ||
if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) { | ||
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"; | ||
@@ -794,9 +1164,40 @@ } | ||
var label = document.createElement("label"); | ||
label.setAttribute("for", "qunit-filter-pass"); | ||
// `label` initialized at top of scope | ||
label = document.createElement( "label" ); | ||
label.setAttribute( "for", "qunit-filter-pass" ); | ||
label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." ); | ||
label.innerHTML = "Hide passed tests"; | ||
toolbar.appendChild( label ); | ||
urlConfigCheckboxesContainer = document.createElement("span"); | ||
urlConfigCheckboxesContainer.innerHTML = urlConfigHtml; | ||
urlConfigCheckboxes = urlConfigCheckboxesContainer.getElementsByTagName("input"); | ||
// For oldIE support: | ||
// * Add handlers to the individual elements instead of the container | ||
// * Use "click" instead of "change" | ||
// * Fallback from event.target to event.srcElement | ||
addEvents( urlConfigCheckboxes, "click", function( event ) { | ||
var params = {}, | ||
target = event.target || event.srcElement; | ||
params[ target.name ] = target.checked ? true : undefined; | ||
window.location = QUnit.url( params ); | ||
}); | ||
toolbar.appendChild( urlConfigCheckboxesContainer ); | ||
if (numModules > 1) { | ||
moduleFilter = document.createElement( 'span' ); | ||
moduleFilter.setAttribute( 'id', 'qunit-modulefilter-container' ); | ||
moduleFilter.innerHTML = moduleFilterHtml; | ||
addEvent( moduleFilter.lastChild, "change", function() { | ||
var selectBox = moduleFilter.getElementsByTagName("select")[0], | ||
selectedModule = decodeURIComponent(selectBox.options[selectBox.selectedIndex].value); | ||
window.location = QUnit.url( { module: ( selectedModule === "" ) ? undefined : selectedModule } ); | ||
}); | ||
toolbar.appendChild(moduleFilter); | ||
} | ||
} | ||
var main = id('qunit-fixture'); | ||
// `main` initialized at top of scope | ||
main = id( "qunit-fixture" ); | ||
if ( main ) { | ||
@@ -806,3 +1207,3 @@ config.fixture = main.innerHTML; | ||
if (config.autostart) { | ||
if ( config.autostart ) { | ||
QUnit.start(); | ||
@@ -812,4 +1213,36 @@ } | ||
addEvent(window, "load", QUnit.load); | ||
addEvent( window, "load", QUnit.load ); | ||
// `onErrorFnPrev` initialized at top of scope | ||
// Preserve other handlers | ||
onErrorFnPrev = window.onerror; | ||
// Cover uncaught exceptions | ||
// Returning true will surpress the default browser handler, | ||
// returning false will let it run. | ||
window.onerror = function ( error, filePath, linerNr ) { | ||
var ret = false; | ||
if ( onErrorFnPrev ) { | ||
ret = onErrorFnPrev( error, filePath, linerNr ); | ||
} | ||
// Treat return value as window.onerror itself does, | ||
// Only do our handling if not surpressed. | ||
if ( ret !== true ) { | ||
if ( QUnit.config.current ) { | ||
if ( QUnit.config.current.ignoreGlobalErrors ) { | ||
return true; | ||
} | ||
QUnit.pushFailure( error, filePath + ":" + linerNr ); | ||
} else { | ||
QUnit.test( "global failure", extend( function() { | ||
QUnit.pushFailure( error, filePath + ":" + linerNr ); | ||
}, { validTest: validTest } ) ); | ||
} | ||
return false; | ||
} | ||
return ret; | ||
}; | ||
function done() { | ||
@@ -820,3 +1253,3 @@ config.autorun = true; | ||
if ( config.currentModule ) { | ||
runLoggingCallbacks( 'moduleDone', QUnit, { | ||
runLoggingCallbacks( "moduleDone", QUnit, { | ||
name: config.currentModule, | ||
@@ -826,24 +1259,25 @@ failed: config.moduleStats.bad, | ||
total: config.moduleStats.all | ||
} ); | ||
}); | ||
} | ||
var banner = id("qunit-banner"), | ||
tests = id("qunit-tests"), | ||
runtime = +new Date - config.started, | ||
var i, key, | ||
banner = id( "qunit-banner" ), | ||
tests = id( "qunit-tests" ), | ||
runtime = +new Date() - config.started, | ||
passed = config.stats.all - config.stats.bad, | ||
html = [ | ||
'Tests completed in ', | ||
"Tests completed in ", | ||
runtime, | ||
' milliseconds.<br/>', | ||
'<span class="passed">', | ||
" milliseconds.<br/>", | ||
"<span class='passed'>", | ||
passed, | ||
'</span> tests of <span class="total">', | ||
"</span> assertions of <span class='total'>", | ||
config.stats.all, | ||
'</span> passed, <span class="failed">', | ||
"</span> passed, <span class='failed'>", | ||
config.stats.bad, | ||
'</span> failed.' | ||
].join(''); | ||
"</span> failed." | ||
].join( "" ); | ||
if ( banner ) { | ||
banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass"); | ||
banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); | ||
} | ||
@@ -859,8 +1293,24 @@ | ||
document.title = [ | ||
(config.stats.bad ? "\u2716" : "\u2714"), | ||
document.title.replace(/^[\u2714\u2716] /i, "") | ||
].join(" "); | ||
( config.stats.bad ? "\u2716" : "\u2714" ), | ||
document.title.replace( /^[\u2714\u2716] /i, "" ) | ||
].join( " " ); | ||
} | ||
runLoggingCallbacks( 'done', QUnit, { | ||
// clear own sessionStorage items if all tests passed | ||
if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { | ||
// `key` & `i` initialized at top of scope | ||
for ( i = 0; i < sessionStorage.length; i++ ) { | ||
key = sessionStorage.key( i++ ); | ||
if ( key.indexOf( "qunit-test-" ) === 0 ) { | ||
sessionStorage.removeItem( key ); | ||
} | ||
} | ||
} | ||
// scroll back to top to show results | ||
if ( window.scrollTo ) { | ||
window.scrollTo(0, 0); | ||
} | ||
runLoggingCallbacks( "done", QUnit, { | ||
failed: config.stats.bad, | ||
@@ -870,9 +1320,26 @@ passed: passed, | ||
runtime: runtime | ||
} ); | ||
}); | ||
} | ||
function validTest( name ) { | ||
var filter = config.filter, | ||
run = false; | ||
/** @return Boolean: true if this test should be ran */ | ||
function validTest( test ) { | ||
var include, | ||
filter = config.filter && config.filter.toLowerCase(), | ||
module = config.module && config.module.toLowerCase(), | ||
fullName = (test.module + ": " + test.testName).toLowerCase(); | ||
// Internally-generated tests are always valid | ||
if ( test.callback && test.callback.validTest === validTest ) { | ||
delete test.callback.validTest; | ||
return true; | ||
} | ||
if ( config.testNumber ) { | ||
return test.testNumber === config.testNumber; | ||
} | ||
if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { | ||
return false; | ||
} | ||
if ( !filter ) { | ||
@@ -882,49 +1349,86 @@ return true; | ||
var not = filter.charAt( 0 ) === "!"; | ||
if ( not ) { | ||
include = filter.charAt( 0 ) !== "!"; | ||
if ( !include ) { | ||
filter = filter.slice( 1 ); | ||
} | ||
if ( name.indexOf( filter ) !== -1 ) { | ||
return !not; | ||
// If the filter matches, we need to honour include | ||
if ( fullName.indexOf( filter ) !== -1 ) { | ||
return include; | ||
} | ||
if ( not ) { | ||
run = true; | ||
// Otherwise, do the opposite | ||
return !include; | ||
} | ||
// so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) | ||
// Later Safari and IE10 are supposed to support error.stack as well | ||
// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack | ||
function extractStacktrace( e, offset ) { | ||
offset = offset === undefined ? 3 : offset; | ||
var stack, include, i; | ||
if ( e.stacktrace ) { | ||
// Opera | ||
return e.stacktrace.split( "\n" )[ offset + 3 ]; | ||
} else if ( e.stack ) { | ||
// Firefox, Chrome | ||
stack = e.stack.split( "\n" ); | ||
if (/^error$/i.test( stack[0] ) ) { | ||
stack.shift(); | ||
} | ||
if ( fileName ) { | ||
include = []; | ||
for ( i = offset; i < stack.length; i++ ) { | ||
if ( stack[ i ].indexOf( fileName ) !== -1 ) { | ||
break; | ||
} | ||
include.push( stack[ i ] ); | ||
} | ||
if ( include.length ) { | ||
return include.join( "\n" ); | ||
} | ||
} | ||
return stack[ offset ]; | ||
} else if ( e.sourceURL ) { | ||
// Safari, PhantomJS | ||
// hopefully one day Safari provides actual stacktraces | ||
// exclude useless self-reference for generated Error objects | ||
if ( /qunit.js$/.test( e.sourceURL ) ) { | ||
return; | ||
} | ||
// for actual exceptions, this is useful | ||
return e.sourceURL + ":" + e.line; | ||
} | ||
return run; | ||
} | ||
// so far supports only Firefox, Chrome and Opera (buggy) | ||
// could be extended in the future to use something like https://github.com/csnover/TraceKit | ||
function sourceFromStacktrace() { | ||
function sourceFromStacktrace( offset ) { | ||
try { | ||
throw new Error(); | ||
} catch ( e ) { | ||
if (e.stacktrace) { | ||
// Opera | ||
return e.stacktrace.split("\n")[6]; | ||
} else if (e.stack) { | ||
// Firefox, Chrome | ||
return e.stack.split("\n")[4]; | ||
} else if (e.sourceURL) { | ||
// Safari, PhantomJS | ||
// TODO sourceURL points at the 'throw new Error' line above, useless | ||
//return e.sourceURL + ":" + e.line; | ||
} | ||
return extractStacktrace( e, offset ); | ||
} | ||
} | ||
function escapeInnerText(s) { | ||
if (!s) { | ||
/** | ||
* Escape text for attribute or text content. | ||
*/ | ||
function escapeText( s ) { | ||
if ( !s ) { | ||
return ""; | ||
} | ||
s = s + ""; | ||
return s.replace(/[\&<>]/g, function(s) { | ||
switch(s) { | ||
case "&": return "&"; | ||
case "<": return "<"; | ||
case ">": return ">"; | ||
default: return s; | ||
// Both single quotes and double quotes (for attributes) | ||
return s.replace( /['"<>&]/g, function( s ) { | ||
switch( s ) { | ||
case '\'': | ||
return '''; | ||
case '"': | ||
return '"'; | ||
case '<': | ||
return '<'; | ||
case '>': | ||
return '>'; | ||
case '&': | ||
return '&'; | ||
} | ||
@@ -934,22 +1438,27 @@ }); | ||
function synchronize( callback ) { | ||
function synchronize( callback, last ) { | ||
config.queue.push( callback ); | ||
if ( config.autorun && !config.blocking ) { | ||
process(); | ||
process( last ); | ||
} | ||
} | ||
function process() { | ||
var start = (new Date()).getTime(); | ||
function process( last ) { | ||
function next() { | ||
process( last ); | ||
} | ||
var start = new Date().getTime(); | ||
config.depth = config.depth ? config.depth + 1 : 1; | ||
while ( config.queue.length && !config.blocking ) { | ||
if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) { | ||
if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { | ||
config.queue.shift()(); | ||
} else { | ||
window.setTimeout( process, 13 ); | ||
window.setTimeout( next, 13 ); | ||
break; | ||
} | ||
} | ||
if (!config.blocking && !config.queue.length) { | ||
config.depth--; | ||
if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { | ||
done(); | ||
@@ -964,2 +1473,6 @@ } | ||
for ( var key in window ) { | ||
// in Opera sometimes DOM element ids show up here, ignore them | ||
if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) { | ||
continue; | ||
} | ||
config.pollution.push( key ); | ||
@@ -970,14 +1483,17 @@ } | ||
function checkPollution( name ) { | ||
var old = config.pollution; | ||
function checkPollution() { | ||
var newGlobals, | ||
deletedGlobals, | ||
old = config.pollution; | ||
saveGlobal(); | ||
var newGlobals = diff( config.pollution, old ); | ||
newGlobals = diff( config.pollution, old ); | ||
if ( newGlobals.length > 0 ) { | ||
ok( false, "Introduced global variable(s): " + newGlobals.join(", ") ); | ||
QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); | ||
} | ||
var deletedGlobals = diff( old, config.pollution ); | ||
deletedGlobals = diff( old, config.pollution ); | ||
if ( deletedGlobals.length > 0 ) { | ||
ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") ); | ||
QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); | ||
} | ||
@@ -988,7 +1504,9 @@ } | ||
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); | ||
result.splice( i, 1 ); | ||
i--; | ||
@@ -1002,19 +1520,10 @@ break; | ||
function fail(message, exception, callback) { | ||
if ( typeof console !== "undefined" && console.error && console.warn ) { | ||
console.error(message); | ||
console.error(exception); | ||
console.warn(callback.toString()); | ||
function extend( a, b ) { | ||
for ( var prop in b ) { | ||
if ( b[ prop ] === undefined ) { | ||
delete a[ prop ]; | ||
} else if ( window.opera && opera.postError ) { | ||
opera.postError(message, exception, callback.toString); | ||
} | ||
} | ||
function extend(a, b) { | ||
for ( var prop in b ) { | ||
if ( b[prop] === undefined ) { | ||
delete a[prop]; | ||
} else { | ||
a[prop] = b[prop]; | ||
// Avoid "Member not found" error in IE8 caused by setting window.constructor | ||
} else if ( prop !== "constructor" || a !== window ) { | ||
a[ prop ] = b[ prop ]; | ||
} | ||
@@ -1026,19 +1535,56 @@ } | ||
function addEvent(elem, type, fn) { | ||
/** | ||
* @param {HTMLElement} elem | ||
* @param {string} type | ||
* @param {Function} fn | ||
*/ | ||
function addEvent( elem, type, fn ) { | ||
// Standards-based browsers | ||
if ( elem.addEventListener ) { | ||
elem.addEventListener( type, fn, false ); | ||
} else if ( elem.attachEvent ) { | ||
// IE | ||
} else { | ||
elem.attachEvent( "on" + type, fn ); | ||
} else { | ||
fn(); | ||
} | ||
} | ||
function id(name) { | ||
return !!(typeof document !== "undefined" && document && document.getElementById) && | ||
/** | ||
* @param {Array|NodeList} elems | ||
* @param {string} type | ||
* @param {Function} fn | ||
*/ | ||
function addEvents( elems, type, fn ) { | ||
var i = elems.length; | ||
while ( i-- ) { | ||
addEvent( elems[i], type, fn ); | ||
} | ||
} | ||
function hasClass( elem, name ) { | ||
return (" " + elem.className + " ").indexOf(" " + name + " ") > -1; | ||
} | ||
function addClass( elem, name ) { | ||
if ( !hasClass( elem, name ) ) { | ||
elem.className += (elem.className ? " " : "") + name; | ||
} | ||
} | ||
function removeClass( elem, name ) { | ||
var set = " " + elem.className + " "; | ||
// Class name may appear multiple times | ||
while ( set.indexOf(" " + name + " ") > -1 ) { | ||
set = set.replace(" " + name + " " , " "); | ||
} | ||
// If possible, trim it for prettiness, but not neccecarily | ||
elem.className = window.jQuery ? jQuery.trim( set ) : ( set.trim ? set.trim() : set ); | ||
} | ||
function id( name ) { | ||
return !!( typeof document !== "undefined" && document && document.getElementById ) && | ||
document.getElementById( name ); | ||
} | ||
function registerLoggingCallback(key){ | ||
return function(callback){ | ||
function registerLoggingCallback( key ) { | ||
return function( callback ) { | ||
config[key].push( callback ); | ||
@@ -1049,11 +1595,10 @@ }; | ||
// Supports deprecated method of completely overwriting logging callbacks | ||
function runLoggingCallbacks(key, scope, args) { | ||
//debugger; | ||
var callbacks; | ||
if ( QUnit.hasOwnProperty(key) ) { | ||
QUnit[key].call(scope, args); | ||
function runLoggingCallbacks( key, scope, args ) { | ||
var i, callbacks; | ||
if ( QUnit.hasOwnProperty( key ) ) { | ||
QUnit[ key ].call(scope, args ); | ||
} else { | ||
callbacks = config[key]; | ||
for( var i = 0; i < callbacks.length; i++ ) { | ||
callbacks[i].call( scope, args ); | ||
callbacks = config[ key ]; | ||
for ( i = 0; i < callbacks.length; i++ ) { | ||
callbacks[ i ].call( scope, args ); | ||
} | ||
@@ -1065,16 +1610,12 @@ } | ||
// Author: Philippe Rathé <prathe@gmail.com> | ||
QUnit.equiv = function () { | ||
QUnit.equiv = (function() { | ||
var innerEquiv; // the real equiv function | ||
var callers = []; // stack to decide between skip/abort functions | ||
var parents = []; // stack to avoiding loops from circular referencing | ||
// Call the o related callback with the given arguments. | ||
function bindCallbacks(o, callbacks, args) { | ||
var prop = QUnit.objectType(o); | ||
if (prop) { | ||
if (QUnit.objectType(callbacks[prop]) === "function") { | ||
return callbacks[prop].apply(callbacks, args); | ||
function bindCallbacks( o, callbacks, args ) { | ||
var prop = QUnit.objectType( o ); | ||
if ( prop ) { | ||
if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { | ||
return callbacks[ prop ].apply( callbacks, args ); | ||
} else { | ||
return callbacks[prop]; // or undefined | ||
return callbacks[ prop ]; // or undefined | ||
} | ||
@@ -1084,142 +1625,160 @@ } | ||
var callbacks = function () { | ||
// the real equiv function | ||
var innerEquiv, | ||
// stack to decide between skip/abort functions | ||
callers = [], | ||
// stack to avoiding loops from circular referencing | ||
parents = [], | ||
// for string, boolean, number and null | ||
function useStrictEquality(b, a) { | ||
if (b instanceof a.constructor || a instanceof b.constructor) { | ||
// to catch short annotaion VS 'new' annotation of a | ||
// declaration | ||
// e.g. var i = 1; | ||
// var j = new Number(1); | ||
return a == b; | ||
} else { | ||
return a === b; | ||
getProto = Object.getPrototypeOf || function ( obj ) { | ||
return obj.__proto__; | ||
}, | ||
callbacks = (function () { | ||
// for string, boolean, number and null | ||
function useStrictEquality( b, a ) { | ||
/*jshint eqeqeq:false */ | ||
if ( b instanceof a.constructor || a instanceof b.constructor ) { | ||
// to catch short annotaion VS 'new' annotation of a | ||
// declaration | ||
// e.g. var i = 1; | ||
// var j = new Number(1); | ||
return a == b; | ||
} else { | ||
return a === b; | ||
} | ||
} | ||
} | ||
return { | ||
"string" : useStrictEquality, | ||
"boolean" : useStrictEquality, | ||
"number" : useStrictEquality, | ||
"null" : useStrictEquality, | ||
"undefined" : useStrictEquality, | ||
return { | ||
"string": useStrictEquality, | ||
"boolean": useStrictEquality, | ||
"number": useStrictEquality, | ||
"null": useStrictEquality, | ||
"undefined": useStrictEquality, | ||
"nan" : function(b) { | ||
return isNaN(b); | ||
}, | ||
"nan": function( b ) { | ||
return isNaN( b ); | ||
}, | ||
"date" : function(b, a) { | ||
return QUnit.objectType(b) === "date" | ||
&& a.valueOf() === b.valueOf(); | ||
}, | ||
"date": function( b, a ) { | ||
return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); | ||
}, | ||
"regexp" : function(b, a) { | ||
return QUnit.objectType(b) === "regexp" | ||
&& a.source === b.source && // the regex itself | ||
a.global === b.global && // and its modifers | ||
// (gmi) ... | ||
a.ignoreCase === b.ignoreCase | ||
&& a.multiline === b.multiline; | ||
}, | ||
"regexp": function( b, a ) { | ||
return QUnit.objectType( b ) === "regexp" && | ||
// the regex itself | ||
a.source === b.source && | ||
// and its modifers | ||
a.global === b.global && | ||
// (gmi) ... | ||
a.ignoreCase === b.ignoreCase && | ||
a.multiline === b.multiline && | ||
a.sticky === b.sticky; | ||
}, | ||
// - skip when the property is a method of an instance (OOP) | ||
// - abort otherwise, | ||
// initial === would have catch identical references anyway | ||
"function" : function() { | ||
var caller = callers[callers.length - 1]; | ||
return caller !== Object && typeof caller !== "undefined"; | ||
}, | ||
// - skip when the property is a method of an instance (OOP) | ||
// - abort otherwise, | ||
// initial === would have catch identical references anyway | ||
"function": function() { | ||
var caller = callers[callers.length - 1]; | ||
return caller !== Object && typeof caller !== "undefined"; | ||
}, | ||
"array" : function(b, a) { | ||
var i, j, loop; | ||
var len; | ||
"array": function( b, a ) { | ||
var i, j, len, loop; | ||
// b could be an object literal here | ||
if (!(QUnit.objectType(b) === "array")) { | ||
return false; | ||
} | ||
// b could be an object literal here | ||
if ( QUnit.objectType( b ) !== "array" ) { | ||
return false; | ||
} | ||
len = a.length; | ||
if (len !== b.length) { // safe and faster | ||
return false; | ||
} | ||
len = a.length; | ||
if ( len !== b.length ) { | ||
// safe and faster | ||
return false; | ||
} | ||
// track reference to avoid circular references | ||
parents.push(a); | ||
for (i = 0; i < len; i++) { | ||
loop = false; | ||
for (j = 0; j < parents.length; j++) { | ||
if (parents[j] === a[i]) { | ||
loop = true;// dont rewalk array | ||
// track reference to avoid circular references | ||
parents.push( a ); | ||
for ( i = 0; i < len; i++ ) { | ||
loop = false; | ||
for ( j = 0; j < parents.length; j++ ) { | ||
if ( parents[j] === a[i] ) { | ||
loop = true;// dont rewalk array | ||
} | ||
} | ||
if ( !loop && !innerEquiv(a[i], b[i]) ) { | ||
parents.pop(); | ||
return false; | ||
} | ||
} | ||
if (!loop && !innerEquiv(a[i], b[i])) { | ||
parents.pop(); | ||
return false; | ||
parents.pop(); | ||
return true; | ||
}, | ||
"object": function( b, a ) { | ||
var i, j, loop, | ||
// Default to true | ||
eq = true, | ||
aProperties = [], | ||
bProperties = []; | ||
// comparing constructors is more strict than using | ||
// instanceof | ||
if ( a.constructor !== b.constructor ) { | ||
// Allow objects with no prototype to be equivalent to | ||
// objects with Object as their constructor. | ||
if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || | ||
( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { | ||
return false; | ||
} | ||
} | ||
} | ||
parents.pop(); | ||
return true; | ||
}, | ||
"object" : function(b, a) { | ||
var i, j, loop; | ||
var eq = true; // unless we can proove it | ||
var aProperties = [], bProperties = []; // collection of | ||
// strings | ||
// stack constructor before traversing properties | ||
callers.push( a.constructor ); | ||
// track reference to avoid circular references | ||
parents.push( a ); | ||
// comparing constructors is more strict than using | ||
// instanceof | ||
if (a.constructor !== b.constructor) { | ||
return false; | ||
} | ||
for ( i in a ) { // be strict: don't ensures hasOwnProperty | ||
// and go deep | ||
loop = false; | ||
for ( j = 0; j < parents.length; j++ ) { | ||
if ( parents[j] === a[i] ) { | ||
// don't go down the same path twice | ||
loop = true; | ||
} | ||
} | ||
aProperties.push(i); // collect a's properties | ||
// stack constructor before traversing properties | ||
callers.push(a.constructor); | ||
// track reference to avoid circular references | ||
parents.push(a); | ||
for (i in a) { // be strict: don't ensures hasOwnProperty | ||
// and go deep | ||
loop = false; | ||
for (j = 0; j < parents.length; j++) { | ||
if (parents[j] === a[i]) | ||
loop = true; // don't go down the same path | ||
// twice | ||
if (!loop && !innerEquiv( a[i], b[i] ) ) { | ||
eq = false; | ||
break; | ||
} | ||
} | ||
aProperties.push(i); // collect a's properties | ||
if (!loop && !innerEquiv(a[i], b[i])) { | ||
eq = false; | ||
break; | ||
callers.pop(); // unstack, we are done | ||
parents.pop(); | ||
for ( i in b ) { | ||
bProperties.push( i ); // collect b's properties | ||
} | ||
} | ||
callers.pop(); // unstack, we are done | ||
parents.pop(); | ||
for (i in b) { | ||
bProperties.push(i); // collect b's properties | ||
// Ensures identical properties name | ||
return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); | ||
} | ||
}; | ||
}()); | ||
// Ensures identical properties name | ||
return eq | ||
&& innerEquiv(aProperties.sort(), bProperties | ||
.sort()); | ||
} | ||
}; | ||
}(); | ||
innerEquiv = function() { // can take multiple arguments | ||
var args = Array.prototype.slice.apply(arguments); | ||
if (args.length < 2) { | ||
var args = [].slice.apply( arguments ); | ||
if ( args.length < 2 ) { | ||
return true; // end transition | ||
} | ||
return (function(a, b) { | ||
if (a === b) { | ||
return (function( a, b ) { | ||
if ( a === b ) { | ||
return true; // catch the most you can | ||
} else if (a === null || b === null || typeof a === "undefined" | ||
|| typeof b === "undefined" | ||
|| QUnit.objectType(a) !== QUnit.objectType(b)) { | ||
} else if ( a === null || b === null || typeof a === "undefined" || | ||
typeof b === "undefined" || | ||
QUnit.objectType(a) !== QUnit.objectType(b) ) { | ||
return false; // don't lose time with error prone cases | ||
@@ -1231,11 +1790,8 @@ } else { | ||
// apply transition with (1..n) arguments | ||
})(args[0], args[1]) | ||
&& arguments.callee.apply(this, args.splice(1, | ||
args.length - 1)); | ||
}( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) ); | ||
}; | ||
return innerEquiv; | ||
}()); | ||
}(); | ||
/** | ||
@@ -1253,7 +1809,7 @@ * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | | ||
function quote( str ) { | ||
return '"' + str.toString().replace(/"/g, '\\"') + '"'; | ||
}; | ||
return '"' + str.toString().replace( /"/g, '\\"' ) + '"'; | ||
} | ||
function literal( o ) { | ||
return o + ''; | ||
}; | ||
return o + ""; | ||
} | ||
function join( pre, arr, post ) { | ||
@@ -1263,186 +1819,212 @@ var s = jsDump.separator(), | ||
inner = jsDump.indent(1); | ||
if ( arr.join ) | ||
arr = arr.join( ',' + s + inner ); | ||
if ( !arr ) | ||
if ( arr.join ) { | ||
arr = arr.join( "," + s + inner ); | ||
} | ||
if ( !arr ) { | ||
return pre + post; | ||
} | ||
return [ pre, inner + arr, base + post ].join(s); | ||
}; | ||
} | ||
function array( arr, stack ) { | ||
var i = arr.length, ret = Array(i); | ||
var i = arr.length, ret = new Array(i); | ||
this.up(); | ||
while ( i-- ) | ||
while ( i-- ) { | ||
ret[i] = this.parse( arr[i] , undefined , stack); | ||
} | ||
this.down(); | ||
return join( '[', ret, ']' ); | ||
}; | ||
return join( "[", ret, "]" ); | ||
} | ||
var reName = /^function (\w+)/; | ||
var reName = /^function (\w+)/, | ||
jsDump = { | ||
// type is used mostly internally, you can fix a (custom)type in advance | ||
parse: function( obj, type, stack ) { | ||
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 parser = this.parsers[ type || this.typeOf(obj) ]; | ||
type = typeof parser; | ||
var 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 ); | ||
type = typeof parser; | ||
inStack = inArray( obj, stack ); | ||
if ( inStack !== -1 ) { | ||
return "recursion(" + (inStack - stack.length) + ")"; | ||
} | ||
if ( type === "function" ) { | ||
stack.push( obj ); | ||
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 (typeof obj === "object" && typeof obj.length === "number" && obj.length >= 0) { | ||
type = "array"; | ||
} else { | ||
type = typeof obj; | ||
} | ||
return type; | ||
}, | ||
separator:function() { | ||
return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? ' ' : ' '; | ||
}, | ||
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,' '); | ||
return 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; | ||
ret += '('; | ||
ret = [ ret, QUnit.jsDump.parse( fn, 'functionArgs' ), '){'].join(''); | ||
return join( ret, QUnit.jsDump.parse(fn,'functionCode'), '}' ); | ||
} | ||
return ( type === "string" ) ? parser : this.parsers.error; | ||
}, | ||
array: array, | ||
nodelist: array, | ||
arguments: array, | ||
object:function( map, stack ) { | ||
var ret = [ ]; | ||
QUnit.jsDump.up(); | ||
for ( var key in map ) { | ||
var val = map[key]; | ||
ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(val, undefined, stack)); | ||
} | ||
QUnit.jsDump.down(); | ||
return join( '{', ret, '}' ); | ||
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 if ( obj.constructor === Error.prototype.constructor ) { | ||
type = "error"; | ||
} else { | ||
type = typeof obj; | ||
} | ||
return type; | ||
}, | ||
node:function( node ) { | ||
var open = QUnit.jsDump.HTML ? '<' : '<', | ||
close = QUnit.jsDump.HTML ? '>' : '>'; | ||
var tag = node.nodeName.toLowerCase(), | ||
ret = open + tag; | ||
for ( var a in QUnit.jsDump.DOMAttrs ) { | ||
var val = node[QUnit.jsDump.DOMAttrs[a]]; | ||
if ( val ) | ||
ret += ' ' + a + '=' + QUnit.jsDump.parse( val, 'attribute' ); | ||
separator: function() { | ||
return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? " " : " "; | ||
}, | ||
// extra can be a number, shortcut for increasing-calling-decreasing | ||
indent: function( extra ) { | ||
if ( !this.multiline ) { | ||
return ""; | ||
} | ||
return ret + close + open + '/' + tag + close; | ||
var chr = this.indentChar; | ||
if ( this.HTML ) { | ||
chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); | ||
} | ||
return new Array( this._depth_ + (extra||0) ).join(chr); | ||
}, | ||
functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function | ||
var l = fn.length; | ||
if ( !l ) return ''; | ||
var args = Array(l); | ||
while ( l-- ) | ||
args[l] = String.fromCharCode(97+l);//97 is 'a' | ||
return ' ' + args.join(', ') + ' '; | ||
up: function( a ) { | ||
this._depth_ += a || 1; | ||
}, | ||
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. | ||
}; | ||
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: function(error) { | ||
return "Error(\"" + error.message + "\")"; | ||
}, | ||
unknown: "[Unknown]", | ||
"null": "null", | ||
"undefined": "undefined", | ||
"function": function( fn ) { | ||
var ret = "function", | ||
// functions never have name in IE | ||
name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1]; | ||
return jsDump; | ||
})(); | ||
if ( name ) { | ||
ret += " " + name; | ||
} | ||
ret += "( "; | ||
// from Sizzle.js | ||
function getText( elems ) { | ||
var ret = "", elem; | ||
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(); | ||
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 len, i, val, | ||
open = QUnit.jsDump.HTML ? "<" : "<", | ||
close = QUnit.jsDump.HTML ? ">" : ">", | ||
tag = node.nodeName.toLowerCase(), | ||
ret = open + tag, | ||
attrs = node.attributes; | ||
for ( var i = 0; elems[i]; i++ ) { | ||
elem = elems[i]; | ||
if ( attrs ) { | ||
for ( i = 0, len = attrs.length; i < len; i++ ) { | ||
val = attrs[i].nodeValue; | ||
// IE6 includes all attributes in .attributes, even ones not explicitly set. | ||
// Those have values like undefined, null, 0, false, "" or "inherit". | ||
if ( val && val !== "inherit" ) { | ||
ret += " " + attrs[i].nodeName + "=" + QUnit.jsDump.parse( val, "attribute" ); | ||
} | ||
} | ||
} | ||
ret += close; | ||
// Get the text from text nodes and CDATA nodes | ||
if ( elem.nodeType === 3 || elem.nodeType === 4 ) { | ||
ret += elem.nodeValue; | ||
// Show content of TextNode or CDATASection | ||
if ( node.nodeType === 3 || node.nodeType === 4 ) { | ||
ret += node.nodeValue; | ||
} | ||
// Traverse everything else, except comment nodes | ||
} else if ( elem.nodeType !== 8 ) { | ||
ret += getText( elem.childNodes ); | ||
} | ||
} | ||
return ret + open + "/" + tag + close; | ||
}, | ||
// function calls it internally, it's the arguments part of the function | ||
functionArgs: function( fn ) { | ||
var args, | ||
l = fn.length; | ||
return ret; | ||
}; | ||
if ( !l ) { | ||
return ""; | ||
} | ||
//from jquery.js | ||
args = new Array(l); | ||
while ( l-- ) { | ||
// 97 is 'a' | ||
args[l] = String.fromCharCode(97+l); | ||
} | ||
return " " + args.join( ", " ) + " "; | ||
}, | ||
// object calls it internally, the key part of an item in a map | ||
key: quote, | ||
// function calls it internally, it's the content of the function | ||
functionCode: "[code]", | ||
// node calls it internally, it's an html attribute value | ||
attribute: quote, | ||
string: quote, | ||
date: quote, | ||
regexp: literal, | ||
number: literal, | ||
"boolean": literal | ||
}, | ||
// if true, entities are escaped ( <, >, \t, space and \n ) | ||
HTML: false, | ||
// indentation unit | ||
indentChar: " ", | ||
// if true, items in a collection, are separated by a \n, else just a space. | ||
multiline: true | ||
}; | ||
return jsDump; | ||
}()); | ||
// from jquery.js | ||
function inArray( elem, array ) { | ||
@@ -1474,35 +2056,42 @@ if ( array.indexOf ) { | ||
* | ||
* QUnit.diff("the quick brown fox jumped over", "the quick fox jumps over") == "the quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over" | ||
* QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick <del>brown </del> fox <del>jumped </del><ins>jumps </ins> over" | ||
*/ | ||
QUnit.diff = (function() { | ||
function diff(o, n) { | ||
var ns = {}; | ||
var os = {}; | ||
/*jshint eqeqeq:false, eqnull:true */ | ||
function diff( o, n ) { | ||
var i, | ||
ns = {}, | ||
os = {}; | ||
for (var i = 0; i < n.length; i++) { | ||
if (ns[n[i]] == null) | ||
ns[n[i]] = { | ||
for ( i = 0; i < n.length; i++ ) { | ||
if ( !hasOwn.call( ns, n[i] ) ) { | ||
ns[ n[i] ] = { | ||
rows: [], | ||
o: null | ||
}; | ||
ns[n[i]].rows.push(i); | ||
} | ||
ns[ n[i] ].rows.push( i ); | ||
} | ||
for (var i = 0; i < o.length; i++) { | ||
if (os[o[i]] == null) | ||
os[o[i]] = { | ||
for ( i = 0; i < o.length; i++ ) { | ||
if ( !hasOwn.call( os, o[i] ) ) { | ||
os[ o[i] ] = { | ||
rows: [], | ||
n: null | ||
}; | ||
os[o[i]].rows.push(i); | ||
} | ||
os[ o[i] ].rows.push( i ); | ||
} | ||
for (var i in ns) { | ||
if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) { | ||
n[ns[i].rows[0]] = { | ||
text: n[ns[i].rows[0]], | ||
for ( i in ns ) { | ||
if ( !hasOwn.call( ns, i ) ) { | ||
continue; | ||
} | ||
if ( ns[i].rows.length === 1 && hasOwn.call( os, i ) && os[i].rows.length === 1 ) { | ||
n[ ns[i].rows[0] ] = { | ||
text: n[ ns[i].rows[0] ], | ||
row: os[i].rows[0] | ||
}; | ||
o[os[i].rows[0]] = { | ||
text: o[os[i].rows[0]], | ||
o[ os[i].rows[0] ] = { | ||
text: o[ os[i].rows[0] ], | ||
row: ns[i].rows[0] | ||
@@ -1513,11 +2102,12 @@ }; | ||
for (var i = 0; i < n.length - 1; i++) { | ||
if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null && | ||
n[i + 1] == o[n[i].row + 1]) { | ||
n[i + 1] = { | ||
text: n[i + 1], | ||
for ( i = 0; i < n.length - 1; i++ ) { | ||
if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && | ||
n[ i + 1 ] == o[ n[i].row + 1 ] ) { | ||
n[ i + 1 ] = { | ||
text: n[ i + 1 ], | ||
row: n[i].row + 1 | ||
}; | ||
o[n[i].row + 1] = { | ||
text: o[n[i].row + 1], | ||
o[ n[i].row + 1 ] = { | ||
text: o[ n[i].row + 1 ], | ||
row: i + 1 | ||
@@ -1528,11 +2118,12 @@ }; | ||
for (var i = n.length - 1; i > 0; i--) { | ||
if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null && | ||
n[i - 1] == o[n[i].row - 1]) { | ||
n[i - 1] = { | ||
text: n[i - 1], | ||
for ( i = n.length - 1; i > 0; i-- ) { | ||
if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && | ||
n[ i - 1 ] == o[ n[i].row - 1 ]) { | ||
n[ i - 1 ] = { | ||
text: n[ i - 1 ], | ||
row: n[i].row - 1 | ||
}; | ||
o[n[i].row - 1] = { | ||
text: o[n[i].row - 1], | ||
o[ n[i].row - 1 ] = { | ||
text: o[ n[i].row - 1 ], | ||
row: i - 1 | ||
@@ -1549,45 +2140,48 @@ }; | ||
return function(o, n) { | ||
o = o.replace(/\s+$/, ''); | ||
n = n.replace(/\s+$/, ''); | ||
var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/)); | ||
return function( o, n ) { | ||
o = o.replace( /\s+$/, "" ); | ||
n = n.replace( /\s+$/, "" ); | ||
var str = ""; | ||
var i, pre, | ||
str = "", | ||
out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), | ||
oSpace = o.match(/\s+/g), | ||
nSpace = n.match(/\s+/g); | ||
var oSpace = o.match(/\s+/g); | ||
if (oSpace == null) { | ||
oSpace = [" "]; | ||
if ( oSpace == null ) { | ||
oSpace = [ " " ]; | ||
} | ||
else { | ||
oSpace.push(" "); | ||
oSpace.push( " " ); | ||
} | ||
var nSpace = n.match(/\s+/g); | ||
if (nSpace == null) { | ||
nSpace = [" "]; | ||
if ( nSpace == null ) { | ||
nSpace = [ " " ]; | ||
} | ||
else { | ||
nSpace.push(" "); | ||
nSpace.push( " " ); | ||
} | ||
if (out.n.length == 0) { | ||
for (var i = 0; i < out.o.length; i++) { | ||
str += '<del>' + out.o[i] + oSpace[i] + "</del>"; | ||
if ( out.n.length === 0 ) { | ||
for ( i = 0; i < out.o.length; i++ ) { | ||
str += "<del>" + out.o[i] + oSpace[i] + "</del>"; | ||
} | ||
} | ||
else { | ||
if (out.n[0].text == null) { | ||
for (n = 0; n < out.o.length && out.o[n].text == null; n++) { | ||
str += '<del>' + out.o[n] + oSpace[n] + "</del>"; | ||
if ( out.n[0].text == null ) { | ||
for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { | ||
str += "<del>" + out.o[n] + oSpace[n] + "</del>"; | ||
} | ||
} | ||
for (var i = 0; i < out.n.length; i++) { | ||
for ( i = 0; i < out.n.length; i++ ) { | ||
if (out.n[i].text == null) { | ||
str += '<ins>' + out.n[i] + nSpace[i] + "</ins>"; | ||
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>"; | ||
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>"; | ||
} | ||
@@ -1601,4 +2195,10 @@ str += " " + out.n[i].text + nSpace[i] + pre; | ||
}; | ||
})(); | ||
}()); | ||
})(this); | ||
// for CommonJS enviroments, export everything | ||
if ( typeof exports !== "undefined" ) { | ||
extend( exports, QUnit ); | ||
} | ||
// get at whatever the global object is, like window in browsers | ||
}( (function() {return this;}.call()) )); |
@@ -1,31 +0,1 @@ | ||
// Underscore.js 1.3.1 | ||
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. | ||
// Underscore is freely distributable under the MIT license. | ||
// Portions of Underscore are inspired or borrowed from Prototype, | ||
// Oliver Steele's Functional, and John Resig's Micro-Templating. | ||
// For all details and documentation: | ||
// http://documentcloud.github.com/underscore | ||
(function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== | ||
c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, | ||
h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= | ||
b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(d,a[e],e,a)===n)break}else for(e in a)if(b.has(a,e)&&c.call(d,a[e],e,a)===n)break};b.map=b.collect=function(a,c,b){var e=[];if(a==null)return e;if(x&&a.map===x)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});if(a.length===+a.length)e.length=a.length;return e};b.reduce=b.foldl=b.inject=function(a,c,d,e){var f=arguments.length>2;a== | ||
null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= | ||
function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= | ||
e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= | ||
function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,computed:b})}); | ||
return e.value};b.shuffle=function(a){var b=[],d;j(a,function(a,f){f==0?b[0]=a:(d=Math.floor(Math.random()*(f+1)),b[f]=b[d],b[d]=a)});return b};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, | ||
c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-1]};b.rest= | ||
b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},[]); | ||
return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,c, | ||
d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(p&&a.indexOf===p)return a.indexOf(c);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(D&&a.lastIndexOf===D)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g}; | ||
var F=function(){};b.bind=function(a,c){var d,e;if(a.bind===s&&s)return s.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));F.prototype=a.prototype;var b=new F,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a, | ||
c){var d={};c||(c=b.identity);return function(){var e=c.apply(this,arguments);return b.has(d,e)?d[e]:d[e]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);i()},c));g?h=true: | ||
a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=[a].concat(i.call(arguments,0));return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}}; | ||
b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, | ||
1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; | ||
b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; | ||
b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), | ||
function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ | ||
u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= | ||
function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= | ||
true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); | ||
(function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,d=e.filter,g=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,_=Object.keys,j=i.bind,w=function(n){return n instanceof w?n:this instanceof w?(this._wrapped=n,void 0):new w(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=w),exports._=w):n._=w,w.VERSION="1.4.4";var A=w.each=w.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a in n)if(w.has(n,a)&&t.call(e,n[a],a,n)===r)return};w.map=w.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e[e.length]=t.call(r,n,u,i)}),e)};var O="Reduce of empty array with no initial value";w.reduce=w.foldl=w.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=w.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(O);return r},w.reduceRight=w.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=w.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=w.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(O);return r},w.find=w.detect=function(n,t,r){var e;return E(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},w.filter=w.select=function(n,t,r){var e=[];return null==n?e:d&&n.filter===d?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&(e[e.length]=n)}),e)},w.reject=function(n,t,r){return w.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},w.every=w.all=function(n,t,e){t||(t=w.identity);var u=!0;return null==n?u:g&&n.every===g?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var E=w.some=w.any=function(n,t,e){t||(t=w.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};w.contains=w.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:E(n,function(n){return n===t})},w.invoke=function(n,t){var r=o.call(arguments,2),e=w.isFunction(t);return w.map(n,function(n){return(e?t:n[t]).apply(n,r)})},w.pluck=function(n,t){return w.map(n,function(n){return n[t]})},w.where=function(n,t,r){return w.isEmpty(t)?r?null:[]:w[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},w.findWhere=function(n,t){return w.where(n,t,!0)},w.max=function(n,t,r){if(!t&&w.isArray(n)&&n[0]===+n[0]&&65535>n.length)return Math.max.apply(Math,n);if(!t&&w.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>=e.computed&&(e={value:n,computed:a})}),e.value},w.min=function(n,t,r){if(!t&&w.isArray(n)&&n[0]===+n[0]&&65535>n.length)return Math.min.apply(Math,n);if(!t&&w.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;e.computed>a&&(e={value:n,computed:a})}),e.value},w.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=w.random(r++),e[r-1]=e[t],e[t]=n}),e};var k=function(n){return w.isFunction(n)?n:function(t){return t[n]}};w.sortBy=function(n,t,r){var e=k(t);return w.pluck(w.map(n,function(n,t,u){return{value:n,index:t,criteria:e.call(r,n,t,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index<t.index?-1:1}),"value")};var F=function(n,t,r,e){var u={},i=k(t||w.identity);return A(n,function(t,a){var o=i.call(r,t,a,n);e(u,o,t)}),u};w.groupBy=function(n,t,r){return F(n,t,r,function(n,t,r){(w.has(n,t)?n[t]:n[t]=[]).push(r)})},w.countBy=function(n,t,r){return F(n,t,r,function(n,t){w.has(n,t)||(n[t]=0),n[t]++})},w.sortedIndex=function(n,t,r,e){r=null==r?w.identity:k(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;u>r.call(e,n[o])?i=o+1:a=o}return i},w.toArray=function(n){return n?w.isArray(n)?o.call(n):n.length===+n.length?w.map(n,w.identity):w.values(n):[]},w.size=function(n){return null==n?0:n.length===+n.length?n.length:w.keys(n).length},w.first=w.head=w.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:o.call(n,0,t)},w.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},w.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},w.rest=w.tail=w.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},w.compact=function(n){return w.filter(n,w.identity)};var R=function(n,t,r){return A(n,function(n){w.isArray(n)?t?a.apply(r,n):R(n,t,r):r.push(n)}),r};w.flatten=function(n,t){return R(n,t,[])},w.without=function(n){return w.difference(n,o.call(arguments,1))},w.uniq=w.unique=function(n,t,r,e){w.isFunction(t)&&(e=r,r=t,t=!1);var u=r?w.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:w.contains(a,r))||(a.push(r),i.push(n[e]))}),i},w.union=function(){return w.uniq(c.apply(e,arguments))},w.intersection=function(n){var t=o.call(arguments,1);return w.filter(w.uniq(n),function(n){return w.every(t,function(t){return w.indexOf(t,n)>=0})})},w.difference=function(n){var t=c.apply(e,o.call(arguments,1));return w.filter(n,function(n){return!w.contains(t,n)})},w.zip=function(){for(var n=o.call(arguments),t=w.max(w.pluck(n,"length")),r=Array(t),e=0;t>e;e++)r[e]=w.pluck(n,""+e);return r},w.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},w.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=w.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},w.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},w.range=function(n,t,r){1>=arguments.length&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=Array(e);e>u;)i[u++]=n,n+=r;return i},w.bind=function(n,t){if(n.bind===j&&j)return j.apply(n,o.call(arguments,1));var r=o.call(arguments,2);return function(){return n.apply(t,r.concat(o.call(arguments)))}},w.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},w.bindAll=function(n){var t=o.call(arguments,1);return 0===t.length&&(t=w.functions(n)),A(t,function(t){n[t]=w.bind(n[t],n)}),n},w.memoize=function(n,t){var r={};return t||(t=w.identity),function(){var e=t.apply(this,arguments);return w.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},w.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},w.defer=function(n){return w.delay.apply(w,[n,1].concat(o.call(arguments,1)))},w.throttle=function(n,t){var r,e,u,i,a=0,o=function(){a=new Date,u=null,i=n.apply(r,e)};return function(){var c=new Date,l=t-(c-a);return r=this,e=arguments,0>=l?(clearTimeout(u),u=null,a=c,i=n.apply(r,e)):u||(u=setTimeout(o,l)),i}},w.debounce=function(n,t,r){var e,u;return function(){var i=this,a=arguments,o=function(){e=null,r||(u=n.apply(i,a))},c=r&&!e;return clearTimeout(e),e=setTimeout(o,t),c&&(u=n.apply(i,a)),u}},w.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},w.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},w.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},w.after=function(n,t){return 0>=n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},w.keys=_||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)w.has(n,r)&&(t[t.length]=r);return t},w.values=function(n){var t=[];for(var r in n)w.has(n,r)&&t.push(n[r]);return t},w.pairs=function(n){var t=[];for(var r in n)w.has(n,r)&&t.push([r,n[r]]);return t},w.invert=function(n){var t={};for(var r in n)w.has(n,r)&&(t[n[r]]=r);return t},w.functions=w.methods=function(n){var t=[];for(var r in n)w.isFunction(n[r])&&t.push(r);return t.sort()},w.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},w.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},w.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)w.contains(r,u)||(t[u]=n[u]);return t},w.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)null==n[r]&&(n[r]=t[r])}),n},w.clone=function(n){return w.isObject(n)?w.isArray(n)?n.slice():w.extend({},n):n},w.tap=function(n,t){return t(n),n};var I=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof w&&(n=n._wrapped),t instanceof w&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==t+"";case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;r.push(n),e.push(t);var a=0,o=!0;if("[object Array]"==u){if(a=n.length,o=a==t.length)for(;a--&&(o=I(n[a],t[a],r,e)););}else{var c=n.constructor,f=t.constructor;if(c!==f&&!(w.isFunction(c)&&c instanceof c&&w.isFunction(f)&&f instanceof f))return!1;for(var s in n)if(w.has(n,s)&&(a++,!(o=w.has(t,s)&&I(n[s],t[s],r,e))))break;if(o){for(s in t)if(w.has(t,s)&&!a--)break;o=!a}}return r.pop(),e.pop(),o};w.isEqual=function(n,t){return I(n,t,[],[])},w.isEmpty=function(n){if(null==n)return!0;if(w.isArray(n)||w.isString(n))return 0===n.length;for(var t in n)if(w.has(n,t))return!1;return!0},w.isElement=function(n){return!(!n||1!==n.nodeType)},w.isArray=x||function(n){return"[object Array]"==l.call(n)},w.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){w["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),w.isArguments(arguments)||(w.isArguments=function(n){return!(!n||!w.has(n,"callee"))}),"function"!=typeof/./&&(w.isFunction=function(n){return"function"==typeof n}),w.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},w.isNaN=function(n){return w.isNumber(n)&&n!=+n},w.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},w.isNull=function(n){return null===n},w.isUndefined=function(n){return n===void 0},w.has=function(n,t){return f.call(n,t)},w.noConflict=function(){return n._=t,this},w.identity=function(n){return n},w.times=function(n,t,r){for(var e=Array(n),u=0;n>u;u++)e[u]=t.call(r,u);return e},w.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var M={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};M.unescape=w.invert(M.escape);var S={escape:RegExp("["+w.keys(M.escape).join("")+"]","g"),unescape:RegExp("("+w.keys(M.unescape).join("|")+")","g")};w.each(["escape","unescape"],function(n){w[n]=function(t){return null==t?"":(""+t).replace(S[n],function(t){return M[n][t]})}}),w.result=function(n,t){if(null==n)return null;var r=n[t];return w.isFunction(r)?r.call(n):r},w.mixin=function(n){A(w.functions(n),function(t){var r=w[t]=n[t];w.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),D.call(this,r.apply(w,n))}})};var N=0;w.uniqueId=function(n){var t=++N+"";return n?n+t:t},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var T=/(.)^/,q={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},B=/\\|'|\r|\n|\t|\u2028|\u2029/g;w.template=function(n,t,r){var e;r=w.defaults({},r,w.templateSettings);var u=RegExp([(r.escape||T).source,(r.interpolate||T).source,(r.evaluate||T).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(B,function(n){return"\\"+q[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,w);var c=function(n){return e.call(this,n,w)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},w.chain=function(n){return w(n).chain()};var D=function(n){return this._chain?w(n).chain():n};w.mixin(w),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];w.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],D.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];w.prototype[n]=function(){return D.call(this,t.apply(this._wrapped,arguments))}}),w.extend(w.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); |
@@ -5,3 +5,3 @@ { | ||
"description": "An backbone adapter for indexeddb. Useless for most people untile indexeddb is ported to the browser", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
279892
3662
0