| [submodule "test/qunit"] | ||
| path = test/qunit | ||
| url = git://github.com/jquery/qunit.git |
| module('Basics'); | ||
| test('Presence', 2, function () { | ||
| equal(typeof genData, 'function', 'genData is a function.'); | ||
| equal(genData.length, 1, 'genData expects one or more parameters.'); | ||
| }); | ||
| test('Dataset', 5, function () { | ||
| var dataset = genData(); | ||
| ok(dataset instanceof Array, "The dataset returned by genData is an array."); | ||
| ok(dataset[0].hasOwnProperty('name'), 'Each data object has a "name" member.'); | ||
| equal(typeof dataset[0].name, 'string', 'The "name" member is a string.'); | ||
| ok(dataset[0].hasOwnProperty('value'), 'Each data object has a "value" member.'); | ||
| strictEqual(dataset[0].name, '', 'By default, the first data object\'s "name" member is an empty string.'); | ||
| }); | ||
| module('Normalize'); | ||
| test("nothing", 2, function () { | ||
| var dataset = genData(), | ||
| undefSet = genData(undefined); | ||
| equal(dataset.length, 1, 'genData returns a dataset with one item, when passed nothing or "undefined".'); | ||
| deepEqual(dataset, undefSet, 'Passing nothing or undefined, results in the same dataset.'); | ||
| }); | ||
| test("objects", 3, function () { | ||
| var bar = {}, | ||
| stuff = { | ||
| foo: bar, | ||
| ping: 'pong' | ||
| }, | ||
| dataset = genData(stuff); | ||
| equal(dataset.length, (function () { | ||
| var cnt = 0, i; | ||
| for (i in stuff) { | ||
| if (stuff.hasOwnProperty(i)) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt; | ||
| })() + 1, 'The normalized object has the expected number of data objects.'); | ||
| strictEqual(dataset[0].value, stuff, 'The value of the first data object references the first argument passed to genData.'); | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name:'',value:stuff}, {name:'foo',value:bar}, {name:'ping',value:'pong'}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the object into the expected dataset format.'); | ||
| }); | ||
| test('arrays', function () { | ||
| var stuff = ['alpha', 'beta', 'disco', 'theta'], | ||
| dataset = genData(stuff), | ||
| nbrNames = 0, | ||
| i = 0, datasetCnt = dataset.length; | ||
| equal(datasetCnt, stuff.length + 1, 'The normalized array has the expected number of data objects.'); | ||
| for (; i < datasetCnt; i++) { | ||
| if (dataset[i].name == i - 1) { | ||
| nbrNames++; | ||
| } | ||
| } | ||
| equal(nbrNames, stuff.length, 'The array element\'s index becomes the "name" member.'); | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name: '', value: stuff}, {name:'0', value:'alpha'}, {name:'1',value:'beta'}, {name:'2',value:'disco'}, {name:'3',value:'theta'}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the array into the expected dataset format.'); | ||
| }); | ||
| test('associative-arrays', 3, function () { | ||
| var stuff = [], | ||
| assocKeyValue = 'pong', | ||
| assocKeyName = 'ping', | ||
| dataset, | ||
| i = 0, datasetCnt; | ||
| stuff[assocKeyName] = assocKeyValue; | ||
| dataset = genData(stuff); | ||
| datasetCnt = dataset.length; | ||
| equal(datasetCnt, stuff.length + 2, 'The normalized associative-array has the expected number of data objects.'); | ||
| for (; i < datasetCnt; i++) { | ||
| if (dataset[i].name === assocKeyName) { | ||
| equal(dataset[i].value, assocKeyValue, 'genData creates data objects for non-indexed members of an associative array.'); | ||
| break; | ||
| } | ||
| } | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name: '', value: stuff}, {name:assocKeyName, value:assocKeyValue}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the associative-array into the expected dataset format.'); | ||
| }); | ||
| test('functions', 2, function () { | ||
| var stuff = function () {}, | ||
| dataset = genData(stuff); | ||
| equal(dataset.length, 1, 'The normalized function has the expected number of data objects.'); | ||
| strictEqual(dataset[0].value, stuff, 'The first data object value is the function.'); | ||
| }); | ||
| test('mixed object', 2, function () { | ||
| var potAryFnc = function () {}, | ||
| potAry = [ | ||
| 'kettle', | ||
| potAryFnc | ||
| ], | ||
| stuff = { | ||
| foo: 'bar', | ||
| pot: potAry | ||
| }, | ||
| dataset = genData(stuff); | ||
| equal(dataset.length, 5, 'The normalized mixed-object has the expected number of data objects.'); | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name: '', value: stuff}, {name:'foo', value:'bar'}, {name:'pot', value:potAry}, {name:'0', value:'kettle'}, {name:'1', value:potAryFnc}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the mixed-object into the expected dataset format.'); | ||
| }); | ||
| test('depth-first ordered tree', 1, function () { | ||
| var stuff = { | ||
| foo: { | ||
| bop: 10, | ||
| echo: { | ||
| lucky: 20, | ||
| happy: 30 | ||
| }, | ||
| code: [ | ||
| 40, | ||
| 50 | ||
| ] | ||
| }, | ||
| loop: 60 | ||
| }, | ||
| dsOrder = [ | ||
| '', | ||
| 'foo', | ||
| 'bop', | ||
| 'echo', | ||
| 'lucky', | ||
| 'happy', | ||
| 'code', | ||
| '0', | ||
| '1', | ||
| 'loop' | ||
| ], | ||
| dsOrderTest = 0, | ||
| dataset = genData(stuff), | ||
| i = 0; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === dsOrder[i]) { | ||
| dsOrderTest++; | ||
| } | ||
| } | ||
| equal(dsOrder.length, dsOrderTest, 'Each data object occurs in the expected order.'); | ||
| }); | ||
| module('Parsers'); | ||
| test('scope and signature', function () { | ||
| genData('anything', function (name, value, parent, dataset, flags) { | ||
| var args = arguments; | ||
| equal(this.constructor, genData, 'scope is a genData instance'); | ||
| equal(args.length, 6, 'has expected number of arguments'); | ||
| equal(typeof name, 'string', 'name is a string'); | ||
| if (dataset.length) { | ||
| equal(typeof parent, 'object', 'parent is an object'); | ||
| equal(parent.constructor, genData, 'parent is a genData instance'); | ||
| } else { | ||
| ok(!parent, 'the first data object has no parent'); | ||
| } | ||
| equal(typeof flags, 'object', 'flags is an object'); | ||
| ok(flags.hasOwnProperty('omit'), 'omit flag is present'); | ||
| ok(!flags.omit, 'omit flag is false by default'); | ||
| ok(flags.hasOwnProperty('scan'), 'scan flag is present'); | ||
| ok(flags.scan, 'scan flag is true by default'); | ||
| ok(flags.hasOwnProperty('exit'), 'exit flag is present'); | ||
| ok(!flags.exit, 'exit flag is false by default'); | ||
| }); | ||
| }); | ||
| test('one function as second argument', function () { | ||
| genData('anything', function () { | ||
| ok(true, 'parser called'); | ||
| }); | ||
| }); | ||
| test('an array of functions as second argument', function () { | ||
| genData( | ||
| 'anything', | ||
| [ | ||
| function () { | ||
| ok(true, 'first parser called'); | ||
| }, | ||
| function () { | ||
| ok(true, 'second parser called'); | ||
| } | ||
| ] | ||
| ); | ||
| }); | ||
| test('add property', function () { | ||
| var propName = 'id', | ||
| dataset = genData('anything', function () { | ||
| this[propName] = Math.random(); | ||
| }), | ||
| data = dataset[0]; | ||
| ok(data.hasOwnProperty(propName), 'added property'); | ||
| equal(typeof data[propName], 'number', 'property is a number'); | ||
| }); | ||
| test('remove properties', function () { | ||
| var dataset = genData([1,2,3], function () { | ||
| delete this.name; | ||
| delete this.value; | ||
| }), | ||
| i = 0, datasetCnt = dataset.length; | ||
| ok(datasetCnt, 'data objects were returned'); | ||
| for (; i < datasetCnt; i++) { | ||
| ok(!dataset[i].hasOwnProperty('name'), 'the name property was removed'); | ||
| ok(!dataset[i].hasOwnProperty('value'), 'the value property was removed'); | ||
| } | ||
| }); | ||
| test('preserving original value between parsers', function () { | ||
| var originalValue = 'foo'; | ||
| genData( | ||
| originalValue, | ||
| [ | ||
| function (name, value) { | ||
| equal(value, this.value, 'data.value matches the value parameter'); | ||
| equal(value, originalValue, 'value matches the original value'); | ||
| this.value = 'somethingelse'; | ||
| notEqual(value, this.value, 'data.value has been changed'); | ||
| }, | ||
| function (name, value) { | ||
| equal(value, originalValue, 'value still matches the original value'); | ||
| notEqual(value, this.value, 'data.value no longer matches the original value'); | ||
| } | ||
| ] | ||
| ); | ||
| }); | ||
| test('preserving shared object between parsers and iterations', 5, function () { | ||
| var sharedSet = 0, | ||
| sharedRef, | ||
| parser = function (name, value, parent, dataset, flags, shared) { | ||
| if (!sharedSet) { | ||
| sharedSet = 1; | ||
| ok(typeof shared === 'object', 'shared argument is an object'); | ||
| shared.idx = 0; | ||
| sharedRef = shared; | ||
| } else { | ||
| shared.idx++; | ||
| ok(shared === sharedRef, 'shared object is the same'); | ||
| } | ||
| }; | ||
| genData( | ||
| [1], | ||
| [ | ||
| parser, | ||
| parser | ||
| ] | ||
| ); | ||
| equal(sharedRef.idx, 3, 'parsers see same shared object between iterations'); | ||
| }); | ||
| test('flags.parent', function () { | ||
| var passParentFnc = function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = parent; | ||
| }, | ||
| sampleData = [[1]], | ||
| simpleSet = genData(sampleData, passParentFnc), | ||
| genChain = new genData(passParentFnc), | ||
| chainSet = genChain(sampleData), | ||
| model = function () {}, | ||
| modelSet = genData(sampleData, passParentFnc, model), | ||
| failSetFalsy = genData(sampleData, function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = 0; | ||
| }), | ||
| failSetTruthy = genData(sampleData, function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = 1; | ||
| }), | ||
| failSetObject = genData(sampleData, function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = {}; | ||
| }); | ||
| equal(simpleSet[1].parent, simpleSet.pop().parent, 'parent change works'); | ||
| equal(chainSet[1].parent, chainSet.pop().parent, 'parent may be instanceof genData'); | ||
| equal(modelSet[1].parent, modelSet.pop().parent, 'parent may be the substituted model'); | ||
| notEqual(failSetFalsy[1].parent, failSetFalsy.pop().parent, 'flags.parent can not be falsy'); | ||
| notEqual(failSetTruthy[1].parent, failSetTruthy.pop().parent, 'flags.parent can not be truthy'); | ||
| notEqual(failSetObject[1].parent, failSetObject.pop().parent, 'flags.parent can not be any object'); | ||
| }); | ||
| test('flags.omit', function () { | ||
| var dataset = genData([1,2,3], function (name, value, parent, dataset, flags) { | ||
| flags.omit = 1; | ||
| if (parent) { | ||
| ok(parent.hasOwnProperty('_OMIT'), 'omitted data objects are flagged'); | ||
| strictEqual(parent._OMIT, true, 'the _OMIT flag is true'); | ||
| } | ||
| }); | ||
| equal(dataset.length, 0, 'dataset has no data objects'); | ||
| }); | ||
| test('flags.scan', function () { | ||
| var stuff = [1,2,3], | ||
| dataset = genData(stuff, function (name, value, parent, dataset, flags) { | ||
| flags.scan = 0; | ||
| }); | ||
| equal(dataset[0].value, stuff, 'first data object has an enumerable value') | ||
| equal(dataset.length, 1, 'member properties were not scanned'); | ||
| }); | ||
| test('flags.exit', function () { | ||
| var tic = 0; | ||
| genData(1, | ||
| [ | ||
| function (name, value, parent, dataset, flags) { | ||
| flags.exit = 1; | ||
| }, | ||
| function () { | ||
| tic = 1; | ||
| } | ||
| ] | ||
| ), | ||
| stuff = [1,2,3], | ||
| dataset = genData(stuff), | ||
| exitSet = genData(stuff, function (name, value, parent, dataset, flags) { | ||
| flags.exit = 1; | ||
| }); | ||
| ok(!tic, 'second parser was skipped'); | ||
| equal(1, exitSet.length, 'only one data object was created'); | ||
| notEqual(dataset.length, exitSet, 'exit flag reduced the number of data objects created'); | ||
| }); | ||
| test('alter the dataset', function () { | ||
| var stuff = 1, | ||
| fauxValues = ['hello', 'world'], | ||
| dataset = genData(stuff, | ||
| function (name, value, parent, dataset, flags) { | ||
| flags.omit = 1; | ||
| dataset.splice(0, dataset.length, 'hello', 'world'); | ||
| } | ||
| ); | ||
| notEqual(typeof stuff, 'object', 'the parsed value has no enumerable members'); | ||
| deepEqual(dataset, fauxValues, 'final dataset has been augmented'); | ||
| }); | ||
| module('Generator'); | ||
| test('spawning', 7, function () { | ||
| var tic = 0, | ||
| parser = function () { | ||
| ok(1, 'parser passed from generator to genData'); | ||
| }, | ||
| gen = new genData(parser), | ||
| tmp = genData, | ||
| dataset; | ||
| ok(typeof gen === 'function', 'returns a function'); | ||
| genData = function () { | ||
| tic = 1; | ||
| }; | ||
| dataset = gen(1); // should fire assertion in parser() | ||
| equal(tic, 0 , 'generator is a closured call'); | ||
| genData = tmp; | ||
| gen(1, parser); | ||
| gen(1, [parser]); | ||
| }); | ||
| test('signature', 5, function () { | ||
| var val = 8, | ||
| fnc = function () { | ||
| this.id = val; | ||
| }, | ||
| genX = new genData(fnc), | ||
| model = function () {}, | ||
| genXY = new genX(fnc), | ||
| genXYZ = new genX(fnc, fnc); | ||
| equal('function', typeof genXY, 'can spawn generator passing one parser'); | ||
| equal('function', typeof genXYZ, 'can spawn generator passing more parsers'); | ||
| equal(val, genX(1, fnc)[0].id, 'accepts a single parser'); | ||
| equal(val, genX(1, [fnc, fnc])[0].id, 'accepts an array of parsers'); | ||
| ok(genX(1, [], model)[0] instanceof model, 'accepts a base model'); | ||
| }); | ||
| test('compounding', function () { | ||
| var strStart = 'foo', | ||
| strEnd = strStart.toUpperCase(), | ||
| idF = function () { | ||
| this.id = strStart; | ||
| }, | ||
| upperF = function () { | ||
| this.id = this.id.toUpperCase(); | ||
| }, | ||
| genId = new genData(idF), | ||
| genUpper = new genId(upperF), | ||
| dataCompound = genUpper(1)[0], | ||
| dataManual = genData( | ||
| 1, | ||
| [ | ||
| idF, | ||
| upperF | ||
| ] | ||
| )[0]; | ||
| equal(strEnd, dataCompound.id, 'the second generator added to the the first'); | ||
| equal(strEnd, dataManual.id, 'manual result matches compound generator'); | ||
| }); | ||
| module('Prototype'); | ||
| test('chaining', function () { | ||
| var emptyFnc = function () {}, | ||
| genAnimal = new genData(emptyFnc), | ||
| genDog = new genAnimal(emptyFnc), | ||
| genFruit = new genData(emptyFnc), | ||
| dog = genDog(1)[0], | ||
| fruit = genFruit(1)[0]; | ||
| ok(dog instanceof genAnimal, 'dog comes from animal generator'); | ||
| ok(dog instanceof genDog, 'dog comes from dog generator'); | ||
| ok(dog instanceof genData, 'dog comes from genData'); | ||
| ok(fruit instanceof genFruit, 'fruit comes from fruit generator'); | ||
| ok(fruit instanceof genData, 'fruit comes from genData'); | ||
| }); | ||
| test('methods', function () { | ||
| var stuff = {foo:'bar'}, | ||
| gen = new genData(function () {}), | ||
| dataset = gen(stuff); | ||
| ok(typeof dataset[0].getValue === 'undefined', 'no getValue method present'); | ||
| genData.prototype.getValue = function () { | ||
| ok(this instanceof genData, 'scope is a genData instance'); | ||
| return this.value; | ||
| }; | ||
| ok(typeof dataset[0].getValue === 'function', 'getValue method exists now'); | ||
| ok(typeof dataset[0].toUpperCase === 'undefined', 'no spawned method present'); | ||
| gen.prototype.toUpperCase = function () { | ||
| ok(this instanceof gen, 'scope is a gen instance'); | ||
| return this.getValue().toUpperCase(); | ||
| }; | ||
| ok(typeof dataset[0].toUpperCase === 'function', 'spawned method exists now'); | ||
| strictEqual(stuff, dataset[0].getValue(), 'genData prototyped method works'); | ||
| strictEqual(stuff.foo.toUpperCase(), dataset[1].toUpperCase(), 'generator prototyped method sees chained methods'); | ||
| // clean up! | ||
| delete genData.prototype.getValue; | ||
| ok(typeof dataset[0].getValue === 'undefined', 'removed prototyped method from genData'); | ||
| }); | ||
| test('substitute base models', function () { | ||
| var tic = 0, | ||
| emptyFnc = function () {}, | ||
| parser = function () { | ||
| tic++; | ||
| }, | ||
| myModel = function () {}, | ||
| dataModel = genData(1, [parser], myModel), | ||
| gen = new genData(parser), | ||
| dataGen = gen(1,[parser], myModel), | ||
| finalTic = 3; | ||
| myModel.prototype.getValue = function () { | ||
| ok(this instanceof myModel, 'scope is an instance of the substitute constructor'); | ||
| return this.value; | ||
| }; | ||
| gen.prototype.hidden = emptyFnc; | ||
| ok(dataModel[0] instanceof myModel, 'can use prototype of a given constructor'); | ||
| ok(!(dataModel[0] instanceof genData), 'substitution kills link to genData'); | ||
| ok(dataGen[0] instanceof myModel, 'generators support prototype substitution'); | ||
| ok(!(dataGen[0] instanceof genData), 'generator substitutions also kill link to genData'); | ||
| ok(typeof dataModel[0].getValue === 'function', 'substitute prototype methods are accessible'); | ||
| ok(typeof dataGen[0].hidden === 'undefined', 'generator and genData methods not available with custom prototypes'); | ||
| equal(1, dataModel[0].getValue(), 'substitute prototype methods work'); | ||
| equal(finalTic, tic, 'Parsers fire during prototype substitution'); | ||
| }); | ||
| test('with an object instead of a constructor', function () { | ||
| var | ||
| protoObj = { | ||
| getValue: function () { | ||
| return this.value; | ||
| } | ||
| } | ||
| , stuff = { | ||
| first: 'value' | ||
| , second: 'bar' | ||
| } | ||
| , genFoo = new genData(protoObj, []) | ||
| , fooSet = genFoo(stuff).slice(1) | ||
| ; | ||
| protoObj.getName = function () { | ||
| return this.name; | ||
| }; | ||
| equal(typeof fooSet[0].getValue, 'function', 'Methods of the object protoype are available in the data instance prototype.'); | ||
| equal(typeof fooSet[0].getName, 'function', 'Methods added to the prototype are added to data instances.'); | ||
| equal(fooSet[0].getValue(), stuff.first, 'Methods from an object prototype are scoped to the given data instance.'); | ||
| equal(typeof genData(stuff, [], protoObj)[0].getName, 'function', 'Works when passing an object prototype directly to genData.'); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>genData Test Suite</title> | ||
| <link rel="stylesheet" href="qunit/qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="qunit/qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="../gendata-min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h1 id="qunit-header">genData Test Suite</h1> | ||
| <h2 id="qunit-banner"></h2> | ||
| <div id="qunit-testrunner-toolbar"></div> | ||
| <h2 id="qunit-userAgent"></h2> | ||
| <ol id="qunit-tests"></ol> | ||
| <!-- Place below elements required by qunit --> | ||
| <script type="text/javascript" src="gendata_tests.js"></script> | ||
| </body> | ||
| </html> |
Sorry, the diff of this file is not supported yet
| test("Canvas pixels", function () { | ||
| var canvas = document.getElementById('qunit-canvas'), context; | ||
| try { | ||
| context = canvas.getContext('2d'); | ||
| } catch(e) { | ||
| // propably no canvas support, just exit | ||
| return; | ||
| } | ||
| context.fillStyle = 'rgba(0, 0, 0, 0)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(255, 0, 0, 0)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 255, 0, 0)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 255, 0)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 0); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 0, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 0, 0, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(255, 0, 0, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 255, 0, 0, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 255, 0, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 255, 0, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 255, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 0, 0, 0, 0, 255, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 0, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 2, 2, 0, 0, 0, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(255, 0, 0, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 2, 2, 255, 0, 0, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 255, 0, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 2, 2, 0, 255, 0, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 255, 0.5)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 2, 2, 0, 0, 255, 127); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 0, 1)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 4, 4, 0, 0, 0, 255); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(255, 0, 0, 1)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 4, 4, 255, 0, 0, 255); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 255, 0, 1)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 4, 4, 0, 255, 0, 255); | ||
| context.clearRect(0,0,5,5); | ||
| context.fillStyle = 'rgba(0, 0, 255, 1)'; | ||
| context.fillRect(0, 0, 5, 5); | ||
| QUnit.pixelEqual(canvas, 4, 4, 0, 0, 255, 255); | ||
| context.clearRect(0,0,5,5); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Test Suite - Canvas Addon</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="qunit-canvas.js"></script> | ||
| <script type="text/javascript" src="canvas-test.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <canvas id="qunit-canvas" width="5" height="5"></canvas> | ||
| </body> | ||
| </html> |
| QUnit.extend( QUnit, { | ||
| pixelEqual: function(canvas, x, y, r, g, b, a, message) { | ||
| var actual = Array.prototype.slice.apply(canvas.getContext('2d').getImageData(x, y, 1, 1).data), expected = [r, g, b, a]; | ||
| QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); | ||
| } | ||
| }); |
| Canvas - A QUnit Addon For Testing Canvas Rendering | ||
| ================================ | ||
| This addon for QUnit adds a pixelEqual method that allows you to assert | ||
| individual pixel values in a given canvas. | ||
| Usage: | ||
| pixelEqual(canvas, x, y, r, g, b, a, message) | ||
| Where: | ||
| * canvas: Reference to a canvas element | ||
| * x, y: Coordinates of the pixel to test | ||
| * r, g, b, a: The color and opacity value of the pixel that you except | ||
| * message: Optional message, same as for other assertions |
| test("Close Numbers", function () { | ||
| QUnit.close(7, 7, 0); | ||
| QUnit.close(7, 7.1, 0.1); | ||
| QUnit.close(7, 7.1, 0.2); | ||
| QUnit.close(3.141, Math.PI, 0.001); | ||
| QUnit.close(3.1, Math.PI, 0.1); | ||
| var halfPi = Math.PI / 2; | ||
| QUnit.close(halfPi, 1.57, 0.001); | ||
| var sqrt2 = Math.sqrt(2); | ||
| QUnit.close(sqrt2, 1.4142, 0.0001); | ||
| QUnit.close(Infinity, Infinity, 1); | ||
| }); | ||
| test("Distant Numbers", function () { | ||
| QUnit.notClose(6, 7, 0); | ||
| QUnit.notClose(7, 7.2, 0.1); | ||
| QUnit.notClose(7, 7.2, 0.19999999999); | ||
| QUnit.notClose(3.141, Math.PI, 0.0001); | ||
| QUnit.notClose(3.1, Math.PI, 0.001); | ||
| var halfPi = Math.PI / 2; | ||
| QUnit.notClose(halfPi, 1.57, 0.0001); | ||
| var sqrt2 = Math.sqrt(2); | ||
| QUnit.notClose(sqrt2, 1.4142, 0.00001); | ||
| QUnit.notClose(Infinity, -Infinity, 5); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Test Suite - Close Enough Addon</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="qunit-close-enough.js"></script> | ||
| <script type="text/javascript" src="close-enough-test.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| </body> | ||
| </html> |
| QUnit.extend( QUnit, { | ||
| /** | ||
| * Checks that the first two arguments are equal, or are numbers close enough to be considered equal | ||
| * based on a specified maximum allowable difference. | ||
| * | ||
| * @example close(3.141, Math.PI, 0.001); | ||
| * | ||
| * @param Number actual | ||
| * @param Number expected | ||
| * @param Number maxDifference (the maximum inclusive difference allowed between the actual and expected numbers) | ||
| * @param String message (optional) | ||
| */ | ||
| close: function(actual, expected, maxDifference, message) { | ||
| var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference; | ||
| QUnit.push(passes, actual, expected, message); | ||
| }, | ||
| /** | ||
| * Checks that the first two arguments are numbers with differences greater than the specified | ||
| * minimum difference. | ||
| * | ||
| * @example notClose(3.1, Math.PI, 0.001); | ||
| * | ||
| * @param Number actual | ||
| * @param Number expected | ||
| * @param Number minDifference (the minimum exclusive difference allowed between the actual and expected numbers) | ||
| * @param String message (optional) | ||
| */ | ||
| notClose: function(actual, expected, minDifference, message) { | ||
| QUnit.push(Math.abs(actual - expected) > minDifference, actual, expected, message); | ||
| } | ||
| }); |
| Close-Enough - A QUnit Addon For Number Approximations | ||
| ================================ | ||
| This addon for QUnit adds close and notClose assertion methods, to test that | ||
| numbers are close enough (or different enough) from an expected number, with | ||
| a specified accuracy. | ||
| Usage: | ||
| close(actual, expected, maxDifference, message) | ||
| notClose(actual, expected, minDifference, message) | ||
| Where: | ||
| * maxDifference: the maximum inclusive difference allowed between the actual and expected numbers | ||
| * minDifference: the minimum exclusive difference allowed between the actual and expected numbers | ||
| * actual, expected, message: The usual |
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit SubsuiteRunner Test Suite</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <link rel="stylesheet" href="qunit-composite.css"> | ||
| <script src="../../qunit/qunit.js"></script> | ||
| <script src="qunit-composite.js"></script> | ||
| <script> | ||
| QUnit.testSuites([ | ||
| "../../test/index.html", | ||
| "../canvas/canvas.html", | ||
| "../close-enough/close-enough.html", | ||
| "../step/step.html", | ||
| "composite-test.html" | ||
| ]); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture"> | ||
| </div> | ||
| </body> | ||
| </html> |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Core Test Suite</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script src="../../qunit/qunit.js"></script> | ||
| <script src="qunit-composite.js"></script> | ||
| <script src="composite-test.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| module( "testSuites tests", (function(){ | ||
| var asyncTest = QUnit.asyncTest, | ||
| runSuite = QUnit.runSuite; | ||
| return { | ||
| setup: function(){ | ||
| //proxy asyncTest and runSuite | ||
| QUnit.asyncTest = window.asyncTest = function( name, callback ){ | ||
| ok( true, "asyncTestCalled for each suite" ); | ||
| callback(); //don't acutally create tests, just call callback | ||
| }; | ||
| QUnit.runSuite = window.runSuite = function(){ | ||
| ok( true, "runSuite called for each suite" ); | ||
| }; | ||
| //ensure that subsuite's done doesn't run | ||
| this.oldDone = QUnit.done; | ||
| }, | ||
| teardown: function(){ | ||
| //restore | ||
| QUnit.asyncTest = window.asyncTest = asyncTest; | ||
| QUnit.runSuite = window.runSuite = runSuite; | ||
| QUnit.done = this.oldDone; | ||
| } | ||
| }; | ||
| })()); | ||
| test( "proper number of asyncTest and runSuite calls", function(){ | ||
| expect( 6 ); | ||
| QUnit.testSuites( ["one.html", "two.html", "three.html"] ); | ||
| }); | ||
| test( "done callback changed", function(){ | ||
| QUnit.testSuites( ["dummy.html"] ); | ||
| notEqual( this.oldDone, QUnit.done, "done callback should be set" ); | ||
| }); | ||
| module( "testStart tests", (function(){ | ||
| var id = QUnit.id; | ||
| return { | ||
| setup: function(){ | ||
| //proxy id | ||
| var fakeElem = this.fakeElem = document.createElement( "div" ); | ||
| QUnit.id = function(){ | ||
| return fakeElem; | ||
| } | ||
| }, | ||
| teardown: function(){ | ||
| QUnit.id = id; | ||
| } | ||
| }; | ||
| })()); | ||
| test( "running message printed", function(){ | ||
| var hello = "hello world", | ||
| expected = "Running " + hello + "...<br> "; | ||
| QUnit.testStart( {name: hello} ); | ||
| equal( this.fakeElem.innerHTML, expected, "innerHTML was set correctly by testStart" ); | ||
| }); | ||
| module( "testDone tests", (function(){ | ||
| var id = QUnit.id; | ||
| return { | ||
| setup: function(){ | ||
| //proxy id | ||
| var fakeElem = this.fakeElem = document.createElement( "div" ); | ||
| fakeElem.appendChild( document.createElement( "ol" ) ); | ||
| fakeElem.appendChild( document.createElement( "ol" ) ); | ||
| QUnit.id = function(){ | ||
| return fakeElem; | ||
| } | ||
| }, | ||
| teardown: function(){ | ||
| QUnit.id = id; | ||
| } | ||
| }; | ||
| })()); | ||
| test( "test expansions are hidden", function(){ | ||
| QUnit.testDone(); | ||
| equal( this.fakeElem.children[0].style.display, "none", "first ol display is none" ); | ||
| equal( this.fakeElem.children[1].style.display, "none", "second ol display is none" ); | ||
| }); | ||
| test( "non-ol elements aren't hidden", function(){ | ||
| this.fakeElem.appendChild( document.createElement( "span" ) ); | ||
| QUnit.testDone(); | ||
| notEqual( this.fakeElem.children[2].style.display, "none", "first ol display is none" ); | ||
| }); | ||
| module( "runSuite tests", (function(){ | ||
| var getElementsByTagName = document.getElementsByTagName, | ||
| createElement = document.createElement, | ||
| runSuite = QUnit.runSuite; | ||
| return { | ||
| setup: function(){ | ||
| //proxy getElementsByTagName and createElement | ||
| var setAttributeCall = this.setAttributeCall = {}, | ||
| appendChildCall = this.appendChildCall = {called: 0}, | ||
| iframeLoad = this.iframeLoad = {}, | ||
| iframeQUnitObject = this.iframeQUnitObject = {}, | ||
| fakeElement = { | ||
| appendChild: function(){appendChildCall.called++}, | ||
| setAttribute: function(){setAttributeCall.args = arguments}, | ||
| addEventListener: function( type, callback ){iframeLoad.callback = callback;}, | ||
| contentWindow: {QUnit: iframeQUnitObject}, | ||
| className: "", | ||
| }; | ||
| document.getElementsByTagName = function(){ | ||
| return [fakeElement]; | ||
| }; | ||
| document.createElement = function(){ | ||
| return fakeElement; | ||
| } | ||
| }, | ||
| teardown: function(){ | ||
| document.getElementsByTagName = getElementsByTagName; | ||
| document.createElement = createElement; | ||
| //must restore even though we didn't proxy; the runner overwrites upon first call | ||
| QUnit.runSuite = runSuite; | ||
| } | ||
| }; | ||
| })()); | ||
| test( "runSuite different after first run", function(){ | ||
| var before = QUnit.runSuite, | ||
| after; | ||
| QUnit.runSuite(); | ||
| after = QUnit.runSuite; | ||
| notEqual( before, after, "runSuite changed after initial run" ); | ||
| }); | ||
| test( "iframe only created once", function(){ | ||
| QUnit.runSuite(); | ||
| equal( this.appendChildCall.called, 1, "append child called once" ); | ||
| QUnit.runSuite(); | ||
| equal( this.appendChildCall.called, 1, "append child only ever called once" ); | ||
| }); | ||
| test( "iframe's QUnit object is modified when iframe source loads", function(){ | ||
| var before = this.iframeQUnitObject, | ||
| after; | ||
| QUnit.runSuite(); | ||
| this.iframeLoad.callback(); | ||
| notEqual( before, after, "iframe's qunit object is modified upon load"); | ||
| }); | ||
| test( "iframe src set to suite passed", function(){ | ||
| var pages = ["testing.html", "subsuiteRunner.html"]; | ||
| QUnit.runSuite( pages[0] ); | ||
| equal( this.setAttributeCall.args[0], "src", "src attribute set" ); | ||
| equal( this.setAttributeCall.args[1], pages[0], "src attribute set" ); | ||
| QUnit.runSuite( pages[1] ); | ||
| equal( this.setAttributeCall.args[1], pages[1], "src attribute set" ); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Core Test Suite</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script src="../../qunit/qunit.js"></script> | ||
| <script src="../../test/test.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Same Test Suite</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script src="../../qunit/qunit.js"></script> | ||
| <script src="../../test/deepEqual.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>Composite</title> | ||
| </head> | ||
| <body> | ||
| <h1>Composite</h1> | ||
| <h3>A QUnit Addon For Running Multiple Test Files</h3> | ||
| <p>Composite is a QUnit addon that, when handed an array of | ||
| files, will open each of those files inside of an iframe, run | ||
| the tests and display the results as a single suite of QUnit | ||
| tests.</p> | ||
| <h4>Using Composite</h4> | ||
| <p>To use Composite, setup a standard QUnit html page as you | ||
| would with other QUnit tests. Remember to include composite.js | ||
| and composite.css. Then, inside of either an external js file, | ||
| or a script block call the only new method that Composite | ||
| exposes, QUnit.testSuites().</p><p>QUnit.testSuites() is | ||
| passed an array of test files to run as follows:</p> | ||
| <pre> | ||
| QUnit.testSuites([ | ||
| "test-file-1.html", | ||
| "test-file-2.html", | ||
| "test-file-3.html" | ||
| ]); | ||
| </pre> | ||
| <h4>Tests</h4> | ||
| <p>Composite has tests of it's own.</p> | ||
| <p> | ||
| <a href="composite-test.html">Composite Test</a>: A suite which tests the implementation of composite.<br> | ||
| <a href="composite-demo-test.html">Composite Demo</a>: A suite which demoes how Compisite is bootstrapped and run. | ||
| </p> | ||
| </body> | ||
| </html> |
| iframe.qunit-subsuite{ | ||
| position: fixed; | ||
| bottom: 0; | ||
| left: 0; | ||
| margin: 0; | ||
| padding: 0; | ||
| border-width: 1px 0 0; | ||
| height: 45%; | ||
| width: 100%; | ||
| background: #fff; | ||
| } |
| (function( QUnit ) { | ||
| var subsuiteFrame; | ||
| QUnit.extend( QUnit, { | ||
| testSuites: function( suites ) { | ||
| for ( var i = 0; i < suites.length; i++ ) { | ||
| (function( suite ) { | ||
| asyncTest( suite, function() { | ||
| QUnit.runSuite( suite ); | ||
| }); | ||
| }( suites[i] ) ); | ||
| } | ||
| QUnit.done = function() { | ||
| subsuiteFrame.style.display = "none"; | ||
| }; | ||
| }, | ||
| testStart: function( data ) { | ||
| // update the test status to show which test suite is running | ||
| QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br> "; | ||
| }, | ||
| testDone: function() { | ||
| var current = QUnit.id( this.config.current.id ), | ||
| children = current.children; | ||
| // undo the auto-expansion of failed tests | ||
| for ( var i = 0; i < children.length; i++ ) { | ||
| if ( children[i].nodeName === "OL" ) { | ||
| children[i].style.display = "none"; | ||
| } | ||
| } | ||
| }, | ||
| runSuite: function( suite ) { | ||
| var body = document.getElementsByTagName( "body" )[0], | ||
| iframe = subsuiteFrame = document.createElement( "iframe" ), | ||
| iframeWin; | ||
| iframe.className = "qunit-subsuite"; | ||
| body.appendChild( iframe ); | ||
| function onIframeLoad() { | ||
| var module, test, | ||
| count = 0; | ||
| QUnit.extend( iframeWin.QUnit, { | ||
| moduleStart: function( data ) { | ||
| // capture module name for messages | ||
| module = data.name; | ||
| }, | ||
| testStart: function( data ) { | ||
| // capture test name for messages | ||
| test = data.name; | ||
| }, | ||
| log: function( data ) { | ||
| // pass all test details through to the main page | ||
| var message = module + ": " + test + ": " + data.message; | ||
| expect( ++count ); | ||
| QUnit.push( data.result, data.actual, data.expected, message ); | ||
| }, | ||
| done: function() { | ||
| // start the wrapper test from the main page | ||
| start(); | ||
| } | ||
| }); | ||
| } | ||
| QUnit.addEvent( iframe, "load", onIframeLoad ); | ||
| iframeWin = iframe.contentWindow; | ||
| iframe.setAttribute( "src", suite ); | ||
| this.runSuite = function( suite ) { | ||
| iframe.setAttribute( "src", suite ); | ||
| }; | ||
| } | ||
| }); | ||
| }( QUnit ) ); |
| Composite - A QUnit Addon For Running Multiple Test Files | ||
| ================================ | ||
| Composite is a QUnit addon that, when handed an array of files, will | ||
| open each of those files inside of an iframe, run the tests and | ||
| display the results as a single suite of QUnit tests. | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Test Suite - JUnit report</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="junitlogger.js"></script> | ||
| <script type="text/javascript"> | ||
| QUnit.jUnitReport = function(data) { | ||
| console.log(data.xml); | ||
| }; | ||
| module('Module 1'); | ||
| test("test 1", 2, function () { | ||
| equal(1, 1, "Assert 1 = 1"); | ||
| equal(1, 2, "Assert fail 1 = 2"); | ||
| }); | ||
| test("test 2", 3, function () { | ||
| equal(1, 1, "Assert 1 = 1"); | ||
| equal(1, 2, "Assert fail 1 = 2"); | ||
| equal(1, 1, "Assert 1 = 1"); | ||
| }); | ||
| module('Module 2'); | ||
| test("test 3", 2, function () { | ||
| equal(1, 1, "Assert 1 = 1"); | ||
| equal(1, 2, "Assert fail 1 = 2"); | ||
| }); | ||
| test("test 4", 3, function () { | ||
| equal(1, 1, "Assert 1 = 1"); | ||
| equal(1, 2, "Assert fail 1 = 2"); | ||
| equal(1, 3, "Assert fail 1 = 3"); | ||
| }); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| </body> | ||
| </html> |
| (function() { | ||
| var count = 0, suiteCount = 0, currentSuite, currentTest, suites = [], assertCount, start, results = {failed:0, passed:0, total:0, time:0}; | ||
| QUnit.jUnitReport = function(data) { | ||
| // Gets called when a report is generated | ||
| }; | ||
| QUnit.moduleStart(function(data) { | ||
| currentSuite = { | ||
| name: data.name, | ||
| tests: [], | ||
| failures: 0, | ||
| time: 0, | ||
| stdout : '', | ||
| stderr : '' | ||
| }; | ||
| suites.push(currentSuite); | ||
| }); | ||
| QUnit.moduleDone(function(data) { | ||
| }); | ||
| QUnit.testStart(function(data) { | ||
| if(!start){ start = new Date(); } | ||
| assertCount = 0; | ||
| currentTest = { | ||
| name: data.name, | ||
| failures: [], | ||
| start: new Date | ||
| }; | ||
| // Setup default suite if no module was specified | ||
| if (!currentSuite) { | ||
| currentSuite = { | ||
| name: "default", | ||
| tests: [], | ||
| failures: 0, | ||
| time: 0, | ||
| stdout : '', | ||
| stderr : '' | ||
| }; | ||
| suites.push(currentSuite); | ||
| } | ||
| currentSuite.tests.push(currentTest); | ||
| }); | ||
| QUnit.testDone(function(data) { | ||
| currentTest.failed = data.failed; | ||
| currentTest.total = data.total; | ||
| currentSuite.failures += data.failed; | ||
| results.failed += data.failed; | ||
| results.passed += data.passed; | ||
| results.total += data.total; | ||
| }); | ||
| QUnit.log(function(data) { | ||
| assertCount++; | ||
| if (!data.result) { | ||
| currentTest.failures.push(data.message); | ||
| // Add log message of failure to make it easier to find in jenkins UI | ||
| currentSuite.stdout += '[' + currentSuite.name + ', ' + currentTest.name + ', ' + assertCount + '] ' + data.message + '\n'; | ||
| } | ||
| }); | ||
| QUnit.done(function(data) { | ||
| function ISODateString(d) { | ||
| function pad(n) { | ||
| return n < 10 ? '0' + n : n | ||
| }; | ||
| return d.getUTCFullYear() + '-' | ||
| + pad(d.getUTCMonth() + 1)+'-' | ||
| + pad(d.getUTCDate()) + 'T' | ||
| + pad(d.getUTCHours()) + ':' | ||
| + pad(d.getUTCMinutes()) + ':' | ||
| + pad(d.getUTCSeconds()) + 'Z' | ||
| }; | ||
| // Generate XML report | ||
| var xmlWriter = new XmlWriter({ | ||
| linebreak_at : "testsuites,testsuite,testcase,failure,system-out,system-err" | ||
| }); | ||
| xmlWriter.start('testsuites'); | ||
| var now = new Date(); | ||
| for (var i = 0; i < suites.length; i++) { | ||
| var suite = suites[i]; | ||
| // Calculate time | ||
| for (var ti = 0; ti < suite.tests.length; ti++) { | ||
| var test = suite.tests[ti]; | ||
| test.time = (now.getTime() - test.start.getTime()) / 1000; | ||
| suite.time += test.time; | ||
| } | ||
| xmlWriter.start('testsuite', { | ||
| id: "" + i, | ||
| name: suite.name, | ||
| errors: "0", | ||
| failures: suite.failures, | ||
| hostname: "localhost", | ||
| tests: suite.tests.length, | ||
| time: Math.round(suite.time * 1000) / 1000, | ||
| timestamp: ISODateString(now) | ||
| }); | ||
| for (var ti = 0; ti < suite.tests.length; ti++) { | ||
| var test = suite.tests[ti]; | ||
| xmlWriter.start('testcase', { | ||
| name: test.name, | ||
| total: test.total, | ||
| failed: test.failed, | ||
| time: Math.round(test.time * 1000) / 1000 | ||
| }); | ||
| for (var fi = 0; fi < test.failures.length; fi++) { | ||
| xmlWriter.start('failure', {type: "AssertionFailedError", message: test.failures[fi]}, true); | ||
| } | ||
| xmlWriter.end('testcase'); | ||
| } | ||
| if (suite.stdout) { | ||
| xmlWriter.start('system-out'); | ||
| xmlWriter.cdata('\n' + suite.stdout); | ||
| xmlWriter.end('system-out'); | ||
| } | ||
| if (suite.stderr) { | ||
| xmlWriter.start('system-err'); | ||
| xmlWriter.cdata('\n' + suite.stderr); | ||
| xmlWriter.end('system-err'); | ||
| } | ||
| xmlWriter.end('testsuite'); | ||
| } | ||
| xmlWriter.end('testsuites'); | ||
| results.time = new Date() - start; | ||
| QUnit.jUnitReport({ | ||
| results:results, | ||
| xml: xmlWriter.getString() | ||
| }); | ||
| }); | ||
| function XmlWriter(settings) { | ||
| var data = [], stack = [], lineBreakAt; | ||
| settings = settings || {}; | ||
| lineBreakAt = makeMap(settings.linebreak_at || 'mytag'); | ||
| function addLineBreak(name) { | ||
| if (lineBreakAt[name] && data[data.length - 1] !== '\n') { | ||
| data.push('\n'); | ||
| } | ||
| }; | ||
| function makeMap(items, delim, map) { | ||
| var i; | ||
| items = items || []; | ||
| if (typeof(items) == "string") { | ||
| items = items.split(','); | ||
| } | ||
| map = map || {}; | ||
| i = items.length; | ||
| while (i--) { | ||
| map[items[i]] = {}; | ||
| } | ||
| return map; | ||
| }; | ||
| function encode(text) { | ||
| var baseEntities = { | ||
| '"' : '"', | ||
| "'" : ''', | ||
| '<' : '<', | ||
| '>' : '>', | ||
| '&' : '&' | ||
| }; | ||
| return ('' + text).replace(/[<>&\"\']/g, function(chr) { | ||
| return baseEntities[chr] || chr; | ||
| }); | ||
| }; | ||
| this.start = function(name, attrs, empty) { | ||
| if (!empty) { | ||
| stack.push(name); | ||
| } | ||
| data.push('<', name); | ||
| for (var aname in attrs) { | ||
| data.push(" " + encode(aname), '="', encode(attrs[aname]), '"'); | ||
| } | ||
| data.push(empty ? ' />' : '>'); | ||
| addLineBreak(name); | ||
| }; | ||
| this.end = function(name) { | ||
| stack.pop(); | ||
| addLineBreak(name); | ||
| data.push('</', name, '>'); | ||
| addLineBreak(name); | ||
| }; | ||
| this.text = function(text) { | ||
| data.push(encode(text)); | ||
| }; | ||
| this.cdata = function(text) { | ||
| data.push('<![CDATA[', text, ']]>'); | ||
| }; | ||
| this.comment = function(text) { | ||
| data.push('<!--', text, '-->'); | ||
| }; | ||
| this.pi = function(name, text) { | ||
| if (text) { | ||
| data.push('<?', name, ' ', text, '?>\n'); | ||
| } else { | ||
| data.push('<?', name, '?>\n'); | ||
| } | ||
| }; | ||
| this.doctype = function(text) { | ||
| data.push('<!DOCTYPE', text, '>\n'); | ||
| }; | ||
| this.getString = function() { | ||
| for (var i = stack.length - 1; i >= 0; i--) { | ||
| this.end(stack[i]); | ||
| } | ||
| stack = []; | ||
| return data.join('').replace(/\n$/, ''); | ||
| }; | ||
| this.reset = function() { | ||
| data = []; | ||
| stack = []; | ||
| }; | ||
| this.pi(settings.xmldecl || 'xml version="1.0" encoding="UTF-8"'); | ||
| }; | ||
| })(); |
| QUnit.extend( QUnit, { | ||
| /** | ||
| * Check the sequence/order | ||
| * | ||
| * @example step(1); setTimeout(function () { step(3); }, 100); step(2); | ||
| * @param Number expected The excepted step within the test() | ||
| * @param String message (optional) | ||
| */ | ||
| step: function (expected, message) { | ||
| this.config.current.step++; // increment internal step counter. | ||
| if (typeof message == "undefined") { | ||
| message = "step " + expected; | ||
| } | ||
| var actual = this.config.current.step; | ||
| QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); | ||
| } | ||
| }); | ||
| /** | ||
| * Reset the step counter for every test() | ||
| */ | ||
| QUnit.testStart(function () { | ||
| this.config.current.step = 0; | ||
| }); |
| QUnit.step() - A QUnit Addon For Testing execution in order | ||
| ============================================================ | ||
| This addon for QUnit adds a step method that allows you to assert | ||
| the proper sequence in which the code should execute. | ||
| Example: | ||
| test("example test", function () { | ||
| function x() { | ||
| QUnit.step(2, "function y should be called first"); | ||
| } | ||
| function y() { | ||
| QUnit.step(1); | ||
| } | ||
| y(); | ||
| x(); | ||
| }); |
| module('Step Addon'); | ||
| test("step", 3, function () { | ||
| QUnit.step(1, "step starts at 1"); | ||
| setTimeout(function () { | ||
| start(); | ||
| QUnit.step(3); | ||
| }, 100); | ||
| QUnit.step(2, "before the setTimeout callback is run"); | ||
| stop(); | ||
| }); | ||
| test("step counter", 1, function () { | ||
| QUnit.step(1, "each test has its own step counter"); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Test Suite - Step Addon</title> | ||
| <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="qunit-step.js"></script> | ||
| <script type="text/javascript" src="step-test.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <canvas id="qunit-canvas" width="5" height="5"></canvas> | ||
| </body> | ||
| </html> |
| /** | ||
| * QUnit Theme by Gabe Hendry | ||
| * | ||
| * http://docs.jquery.com/QUnit | ||
| * | ||
| * Copyright (c) 2012 John Resig, Jörn Zaefferer | ||
| * Dual licensed under the MIT (MIT-LICENSE.txt) | ||
| * or GPL (GPL-LICENSE.txt) licenses. | ||
| */ | ||
| /** General Styles and Page Sturcture */ | ||
| body { | ||
| font-family:Arial, 'sans serif'; | ||
| padding:20px 20px 0 20px; | ||
| position:relative; | ||
| } | ||
| h1, h2, h3, h4, h5, h6, #qunit-header, #qunit-banner { | ||
| font-family:Calibri, Arial, 'sans-serif'; | ||
| } | ||
| h2 #qunit-tests, h2 #qunit-testrunner-toolbar, h2 #qunit-userAgent, #qunit-testresult { | ||
| font-family: Arial, 'sans-serif'; | ||
| } | ||
| #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } | ||
| #qunit-tests { font-size: smaller; } | ||
| /** Resets */ | ||
| #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| /** Headers */ | ||
| #qunit-header { | ||
| padding: 10px 0px 25px 0px; | ||
| color: #3B73B9; | ||
| font-size: 1.8em; | ||
| font-weight: normal; | ||
| height:2em; | ||
| } | ||
| #qunit-header a { | ||
| text-decoration: none; | ||
| color: #3B73B9; | ||
| font-weight:bold; | ||
| padding-right:22px; | ||
| float:left; | ||
| } | ||
| #qunit-header label { | ||
| font-size:14px; | ||
| color:#6BC9ED; | ||
| float:right; | ||
| font-family:Arial, 'sans-serif'; | ||
| display: inline-block; | ||
| } | ||
| #qunit-header a + label:after { | ||
| content: ' }'; | ||
| } | ||
| #qunit-header label + label { | ||
| margin-right:8px; | ||
| } | ||
| #qunit-header a:hover, #qunit-header a:focus { | ||
| color: #3B73B9; | ||
| background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAcCAYAAABoMT8aAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpERkFDNTFBMjMwREYxMUUxQTA3RjlDQkNDQzY3MkI4MCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpERkFDNTFBMTMwREYxMUUxQTA3RjlDQkNDQzY3MkI4MCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PjKftvwAAAFqSURBVHja5NTNKwVRHMbxey9X3rrXStlY2ljJRiQLGytLIkUpIks7lIUFC9laCX+DhUiSlMRdsFBSdkqSt4u8ju+vnqkxZriZheTUp1NzzvxmzjnPTNxxnFiUlohFbL9fIL9xeOUf7EEiSgEbf8XUTwv04A59mIuyB2VowyqKvytQjkU8YwaFul6CJmQ+5MB38zSGUIAs8vCi3loc6bA3mECvJl2o0Jhn/B47qAorMIgU9lGJBc/YDZbQgNugAt1I4gGtepq1ZTxiHu2B34L6LpRiD6ee8UPUqfe2lPbl0i1Qoz4T8JCgm89hf6IKdwnX6tM5ZGIEb1py1i2wporNORToUDa2LStugVntdPKr3GvMUnmFUe8p2No3FNOBkCIWsn7NOcC6Pwd2EicoUiZsnVvYxZNutpM601F/CpIFpNazH5bIel1LqOAmqrWEwG/BirQorp3KgL3yMSZxFBYkf7OJ43/jp/ouwAB8JktCUeXXIAAAAABJRU5ErkJggg==') center right no-repeat; | ||
| } | ||
| h2, p { | ||
| padding: 10px 0 10px 0; | ||
| margin:0; | ||
| font-size:1.3em; | ||
| } | ||
| p { | ||
| padding-top:0; | ||
| font-size:small; | ||
| color:#7B7979; | ||
| line-height:1.6em; | ||
| } | ||
| h2#qunit-banner { | ||
| height: 16px; | ||
| padding:5px 5px 5px 25px; | ||
| line-height:16px; | ||
| margin:0px 0 15px 0; | ||
| border-radius: 5px; | ||
| -moz-border-radius: 5px; | ||
| -webkit-border-radius: 5px; | ||
| background-position:0px; | ||
| background-repeat:no-repeat; | ||
| font-size:1em; | ||
| font-weight:normal; | ||
| } | ||
| h2#qunit-banner.qunit-pass { | ||
| background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjc1RjgyNEY5MzE2NzExRTFCQTA0RTIzMEVFNkY4ODM2IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjc1RjgyNEZBMzE2NzExRTFCQTA0RTIzMEVFNkY4ODM2Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NzVGODI0RjczMTY3MTFFMUJBMDRFMjMwRUU2Rjg4MzYiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NzVGODI0RjgzMTY3MTFFMUJBMDRFMjMwRUU2Rjg4MzYiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz4C94F5AAAAwklEQVR42mL8//8/AyWAiYFCQLEBLOW7GEnVYwzEaUC8B4hXs5CoWRCIVwGxEtQQE1K9ANMMN5AUAzqA2AWJ/x6IzxJrAMi55WhiriBDYAYoEQi0DjSxdJDtsGgESd4F4jNYDAIF2m4oDQOzoBieDsqRbDoDpWEAXfMeqO0oCWkPmo1noH6eiWbYPSAOw5YSQYKr0cRnQg1BDvEwKI1hAEyyAk9AVsACDV9e6MRhSydyoBHKTKuh8bsHSTM+lzEABBgAXD0oIFydPtEAAAAASUVORK5CYII='); | ||
| color:#76B900; | ||
| } | ||
| h2#qunit-banner.qunit-pass:after { | ||
| content:'Congrats! All of your tests passed!'; | ||
| } | ||
| h2#qunit-banner.qunit-fail { | ||
| background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjU5QUIzNEU2MzE2NzExRTE4ODc3OEVFNEY2NzhDMjM4IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjU5QUIzNEU3MzE2NzExRTE4ODc3OEVFNEY2NzhDMjM4Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6NTlBQjM0RTQzMTY3MTFFMTg4Nzc4RUU0RjY3OEMyMzgiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NTlBQjM0RTUzMTY3MTFFMTg4Nzc4RUU0RjY3OEMyMzgiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz46NEjgAAAAzElEQVR42mL8//8/AyWABUS8N1EFUS5AfA+KcQFBIE6DsjsFz9yGGAAEu6EGgEA6EM/CoRmkzhiJX8EE5bggKZyJZAsuzQwwNhMOp6IbsgpNM9jn8DCAOnsmFkNgNrlg0dyJbMAsNE0MOPgwza5AfBbdC7OgLsEHUDRjCwNChqBoxhWIxngMQI8dDAPKsSlCM2AmLgNAkh04/I3TECZcJiNFrys+Q2AGhOLQPAsaaLgMwZkS0fMDLkPgBqzGoxnZEBMg3gM1CBzdAAEGABpTMr+umvCXAAAAAElFTkSuQmCC'); | ||
| color:#ee3324; | ||
| } | ||
| h2#qunit-banner.qunit-fail:after { | ||
| content:'Oops! One or more tests failed!'; | ||
| } | ||
| /** Test Runner Result Styles */ | ||
| #qunit-testrunner-toolbar { | ||
| position:absolute; | ||
| top:55px; | ||
| right:20px; | ||
| color:#6BC9ED; | ||
| font-size:14px; | ||
| } | ||
| #qunit-testrunner-toolbar:after { | ||
| content:' }'; | ||
| } | ||
| h2#qunit-userAgent { | ||
| padding: 0; | ||
| color: #7B7979; | ||
| border:0; | ||
| font-size:small; | ||
| font-family: Arial, 'sans-serif'; | ||
| font-weight:normal; | ||
| font-style:italic; | ||
| } | ||
| h2#qunit-userAgent:before { | ||
| content:'User Agents: '; | ||
| } | ||
| /** Tests: Pass/Fail */ | ||
| #qunit-tests { | ||
| list-style-position: inside; | ||
| list-style-type:none; | ||
| } | ||
| #qunit-tests li { | ||
| padding: 4px 10px; | ||
| list-style-position:outside; | ||
| border-radius: 5px; | ||
| -moz-border-radius: 5px; | ||
| -webkit-border-radius: 5px; | ||
| margin-bottom:5px; | ||
| position:relative; | ||
| *zoom:1; | ||
| list-style-type:none; | ||
| } | ||
| #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { | ||
| display: none; | ||
| } | ||
| #qunit-tests li strong { | ||
| cursor: pointer; | ||
| } | ||
| #qunit-tests li a { | ||
| display:block; | ||
| position:absolute; | ||
| right:10px; | ||
| padding:0px 16px 0 0; | ||
| font-size:0.8em; | ||
| background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAYCAYAAADOMhxqAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpENEZDRDdDQTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpENEZDRDdDOTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MDRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PpE8SAQAAAD3SURBVHjaYsw5+YYBC5gGxN+BuBhdgoUBO1AFYlMgFgXiOGQJJjSFrEDcC8RaQMwPxEFAvBuXDSDFP6D4F1SMG4gtgFgBiB+g2/ATiL8C8UIgPgMV+wvEujDFyBoWQRVPB+IsqOa3QCyFrBhZgysQMwLxFCjfB4hFgPgVlH8DiOcha/jHgBu0ALEMEH9G1rAXqikHi4ZkIP4DxEuQNaQBMReUngjEdkAcDPU8KKROAPFp5GAFBSUPNHZToZEFM+wsEHtgiziQJmYg7gPiy0B8HIiTgNgRX0yD/FFzYdXZK0B8Fchei5GWgBI40xJQbjQtjdi0BBBgAAsUYVWmfe1CAAAAAElFTkSuQmCC') bottom right no-repeat; | ||
| color: #3b73b9; | ||
| text-decoration: none; | ||
| height:12px; | ||
| top:5px; | ||
| } | ||
| #qunit-tests li a:hover, | ||
| #qunit-tests li a:focus { | ||
| color: #6bc9ed; | ||
| background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAYCAYAAADOMhxqAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpENEZDRDdDQTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpENEZDRDdDOTMxODUxMUUxOTc3NEQ0OTUxNjc4REFEQiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MDRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4RjRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PpE8SAQAAAD3SURBVHjaYsw5+YYBC5gGxN+BuBhdgoUBO1AFYlMgFgXiOGQJJjSFrEDcC8RaQMwPxEFAvBuXDSDFP6D4F1SMG4gtgFgBiB+g2/ATiL8C8UIgPgMV+wvEujDFyBoWQRVPB+IsqOa3QCyFrBhZgysQMwLxFCjfB4hFgPgVlH8DiOcha/jHgBu0ALEMEH9G1rAXqikHi4ZkIP4DxEuQNaQBMReUngjEdkAcDPU8KKROAPFp5GAFBSUPNHZToZEFM+wsEHtgiziQJmYg7gPiy0B8HIiTgNgRX0yD/FFzYdXZK0B8Fchei5GWgBI40xJQbjQtjdi0BBBgAAsUYVWmfe1CAAAAAElFTkSuQmCC') top right no-repeat; | ||
| } | ||
| #qunit-tests li.pass strong > span {color:#76B900;} | ||
| #qunit-tests li.pass strong:first-child { | ||
| padding-left:20px; | ||
| background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozODgyNDY5QzMxN0ExMUUxOTdFMkVCQkNENjFBMjc3RSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozODgyNDY5QjMxN0ExMUUxOTdFMkVCQkNENjFBMjc3RSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/Pv7qI08AAAClSURBVHjaYvz//z8DKYClfBcjMeqUgFgQiM+yEKEYpHA3VFMYExEaVkEVg20ipKEDiF2g7LNAPIsJaqUgFsVpQFwOZb8H4nQQzQR13zuoAhgwhpoOA2FQGxiYkNw3E4phnoTZWgHEe2A6maC63yM54y6S4llA3InsTiaobhOYlUiKz0JNZ0DXAAL3gNgViFcjeRLZZkRMI7FhioyhBrzHFs4AAQYAz08iXvWgossAAAAASUVORK5CYII=') center left no-repeat; | ||
| } | ||
| #qunit-tests li.fail strong > span {color:#EE3324;} | ||
| #qunit-tests li.fail strong:first-child { | ||
| padding-left:20px; | ||
| background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo0MzNBNEM0QzMxN0ExMUUxQjk0MUYyOEJCODA0OTM1OSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo0MzNBNEM0QjMxN0ExMUUxQjk0MUYyOEJCODA0OTM1OSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5MTRENzREMkRFMzBFMTExQkZCM0YxOUI1MEUyRUQ0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PnO7dSIAAACtSURBVHjaYnxnrMIABEpA/B6K0YEgEBsD8VnBM7ffM0E5d6HYGIvi3UiYgQkqiCyJrAmZbwzTcBaKYZrOAHEaEM9E05wOIlig7nZFM20mmtM6gXgWzAYGJE1nsXgapLACxmFCkniPQwOKGLKGmVC3owMUcZiGDjTFs9BMhmuCxUM5muJ0qJ9Wo2lCcRII7IEFH9RPYbDQgaUCFqjVYdDkMQuLH9Khau6BOAABBgDmhyuetyQ3ywAAAABJRU5ErkJggg==') center left no-repeat; | ||
| } | ||
| #qunit-tests li ol { | ||
| margin:0; | ||
| padding:10px 0 0 0; | ||
| background-color: #fff; | ||
| } | ||
| #qunit-tests li ol li { | ||
| list-style-position: inside; | ||
| list-style-type:decimal; | ||
| *list-style-position: outside; | ||
| } | ||
| #qunit-tests table { | ||
| border-collapse: collapse; | ||
| margin-top: .2em; | ||
| } | ||
| #qunit-tests th { | ||
| text-align: right; | ||
| vertical-align: top; | ||
| padding: 0 .5em 0 0; | ||
| } | ||
| #qunit-tests td { | ||
| vertical-align: top; | ||
| } | ||
| #qunit-tests pre { | ||
| margin: 0; | ||
| white-space: pre-wrap; | ||
| word-wrap: break-word; | ||
| } | ||
| #qunit-tests del { | ||
| background-color: #add566; | ||
| color: #555; | ||
| text-decoration: none; | ||
| } | ||
| #qunit-tests ins { | ||
| background-color: #f5857c; | ||
| color: #555; | ||
| text-decoration: none; | ||
| } | ||
| /*** Test Counts */ | ||
| #qunit-tests b.counts { | ||
| color: #7B7979; | ||
| font-size:0.8em; | ||
| margin-left:10px; | ||
| } | ||
| b.counts b.passed, b.counts b.failed { | ||
| display:inline-block; | ||
| padding:0px 1px; | ||
| border-radius: 3px; | ||
| -moz-border-radius: 3px; | ||
| -webkit-border-radius: 3px; | ||
| color:#FFF; | ||
| } | ||
| b.counts b.passed { | ||
| background:#76b900; | ||
| } | ||
| b.counts b.failed { | ||
| background:#ee3324; | ||
| } | ||
| #qunit-tests li li { | ||
| margin:0 0 5px; | ||
| padding: 0.4em 0.5em 0.4em 0.5em; | ||
| background-color: #fff; | ||
| border-bottom: none; | ||
| border-radius: 3px; | ||
| -moz-border-radius: 3px; | ||
| -webkit-border-radius: 3px; | ||
| overflow:auto; | ||
| } | ||
| /*** Passing Styles */ | ||
| #qunit-tests li li.pass { | ||
| color: #7B7979; | ||
| background-color: #fff; | ||
| border-left: 20px solid #76B900; | ||
| } | ||
| #qunit-tests .pass { color: #76B900; background-color: #FFF; border: 1px solid #add566; } | ||
| #qunit-tests .pass .test-actual, | ||
| #qunit-tests .pass .test-expected { color: #999999; } | ||
| /*** Failing Styles */ | ||
| #qunit-tests li.fail ol { | ||
| background:#f7f7f7; | ||
| } | ||
| #qunit-tests li li.fail { | ||
| color: #7B7979; | ||
| background-color: #fff; | ||
| border-left: 20px solid #EE3324; | ||
| white-space: pre; | ||
| } | ||
| #qunit-tests .fail { color: #EE3324; border: 1px solid #f5857c; background-color: #f7f7f7; } | ||
| #qunit-tests .fail .test-actual, | ||
| #qunit-tests .fail .test-expected { color: #999999; } | ||
| /** Result */ | ||
| p#qunit-testresult { | ||
| padding: 10px 0; | ||
| font-weight:bold; | ||
| line-height:1.6em; | ||
| color: #7B7979; | ||
| } | ||
| p#qunit-testresult span.passed, p#qunit-testresult span.failed { | ||
| font-size:1.5em; | ||
| font-weight:bold; | ||
| display:inline-block; | ||
| padding:3px; | ||
| border-radius: 5px; | ||
| -moz-border-radius: 5px; | ||
| -webkit-border-radius: 5px; | ||
| } | ||
| p#qunit-testresult span.passed { | ||
| color:#FFF; | ||
| background:#76b900 | ||
| } | ||
| p#qunit-testresult span.failed { | ||
| color:#FFF; | ||
| background:#ee3324; | ||
| } | ||
| /** Fixture */ | ||
| #qunit-fixture { | ||
| position: absolute; | ||
| top: -10000px; | ||
| left: -10000px; | ||
| width: 1000px; | ||
| height: 1000px; | ||
| } |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>QUnit Test Suite - Gabe Theme</title> | ||
| <link rel="stylesheet" href="gabe.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="../../test/test.js"></script> | ||
| <script type="text/javascript" src="../../test/deepEqual.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| /** | ||
| * QUnit Theme by NV | ||
| * | ||
| * http://docs.jquery.com/QUnit | ||
| * | ||
| * Copyright (c) 2012 John Resig, Jörn Zaefferer | ||
| * Dual licensed under the MIT (MIT-LICENSE.txt) | ||
| * or GPL (GPL-LICENSE.txt) licenses. | ||
| */ | ||
| /** Font Family and Sizes */ | ||
| #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { | ||
| font-family: "Helvetica Neue", Helvetica, sans-serif; | ||
| } | ||
| #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } | ||
| #qunit-tests { font-size: smaller; } | ||
| /** Resets */ | ||
| #qunit-wrapper, #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| /** Header */ | ||
| #qunit-header { | ||
| font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Helvetica, sans-serif; | ||
| padding: 0.5em 0 0.5em 1.3em; | ||
| color: #8699a4; | ||
| background-color: #0d3349; | ||
| font-size: 1.5em; | ||
| line-height: 1em; | ||
| font-weight: normal; | ||
| } | ||
| #qunit-header a { | ||
| text-decoration: none; | ||
| color: #c2ccd1; | ||
| } | ||
| #qunit-header a:hover, | ||
| #qunit-header a:focus { | ||
| color: #fff; | ||
| } | ||
| #qunit-header label { | ||
| display: inline-block; | ||
| } | ||
| #qunit-banner.qunit-pass { | ||
| height: 3px; | ||
| } | ||
| #qunit-banner.qunit-fail { | ||
| height: 5px; | ||
| } | ||
| #qunit-testrunner-toolbar { | ||
| padding: 0 0 0.5em 2em; | ||
| } | ||
| #qunit-testrunner-toolbar label { | ||
| margin-right: 1em; | ||
| } | ||
| #qunit-userAgent { | ||
| padding: 0.5em 0 0.5em 2.5em; | ||
| font-weight: normal; | ||
| color: #666; | ||
| } | ||
| /** Tests: Pass/Fail */ | ||
| #qunit-tests { | ||
| list-style-type: none; | ||
| background-color: #D2E0E6; | ||
| } | ||
| #qunit-tests li { | ||
| padding: 0.4em 0.5em 0.4em 2.5em; | ||
| } | ||
| #qunit-tests li strong { | ||
| font-weight: normal; | ||
| cursor: pointer; | ||
| } | ||
| #qunit-tests ol { | ||
| margin: 0.5em 0 1em; | ||
| background-color: #fff; | ||
| } | ||
| #qunit-tests table { | ||
| border-collapse: collapse; | ||
| margin-top: .2em; | ||
| } | ||
| #qunit-tests th { | ||
| text-align: right; | ||
| vertical-align: top; | ||
| padding: 0 .5em 0 0; | ||
| } | ||
| #qunit-tests td { | ||
| vertical-align: top; | ||
| } | ||
| #qunit-tests pre { | ||
| margin: 0; | ||
| white-space: pre-wrap; | ||
| word-wrap: break-word; | ||
| } | ||
| #qunit-tests del { | ||
| background-color: #e0f2be; | ||
| color: #374e0c; | ||
| text-decoration: none; | ||
| } | ||
| #qunit-tests ins { | ||
| background-color: #ffcaca; | ||
| color: #500; | ||
| text-decoration: none; | ||
| } | ||
| /*** Test Counts */ | ||
| #qunit-tests b.passed { color: #5E740B; } | ||
| #qunit-tests b.failed { | ||
| color: #710909; | ||
| } | ||
| #qunit-tests li.fail .failed { | ||
| color: #E48989; | ||
| } | ||
| #qunit-tests li.fail .passed { | ||
| color: #E3C987; | ||
| } | ||
| #qunit-tests li li { | ||
| margin-left: 2.5em; | ||
| padding: 0.7em 0.5em 0.7em 0; | ||
| background-color: #fff; | ||
| border-bottom: none; | ||
| } | ||
| #qunit-tests b.counts { | ||
| font-weight: normal; | ||
| } | ||
| /*** Passing Styles */ | ||
| #qunit-tests li li.pass { | ||
| color: #5E740B; | ||
| background-color: #fff; | ||
| } | ||
| #qunit-tests .pass { color: #2f3424; background-color: #d9dec3; } | ||
| #qunit-tests .pass .module-name { color: #636b51; } | ||
| #qunit-tests .pass .test-actual, | ||
| #qunit-tests .pass .test-expected { color: #999999; } | ||
| #qunit-banner.qunit-pass { background-color: #C6E746; } | ||
| /*** Failing Styles */ | ||
| #qunit-tests li li.fail { | ||
| color: #710909; | ||
| background-color: #fff; | ||
| } | ||
| #qunit-tests .fail { color: #fff; background-color: #962323; } | ||
| #qunit-tests .fail .module-name, | ||
| #qunit-tests .fail .counts { color: #DEC1C1; } | ||
| #qunit-tests .fail .test-actual { color: #B72F2F; } | ||
| #qunit-tests .fail .test-expected { color: green; } | ||
| #qunit-banner.qunit-fail, | ||
| #qunit-testrunner-toolbar { color: #dec1c1; background-color: #962323; } | ||
| /** Footer */ | ||
| #qunit-testresult { | ||
| padding: 0.5em 0.5em 0.5em 2.5em; | ||
| color: #333; | ||
| } | ||
| #qunit-testresult .module-name { | ||
| font-weight: bold; | ||
| } | ||
| /** Fixture */ | ||
| #qunit-fixture { | ||
| position: absolute; | ||
| top: -10000px; | ||
| left: -10000px; | ||
| width: 1000px; | ||
| height: 1000px; | ||
| } |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>QUnit Test Suite - NV Theme</title> | ||
| <link rel="stylesheet" href="nv.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="../../test/test.js"></script> | ||
| <script type="text/javascript" src="../../test/deepEqual.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| Themes | ||
| ====== | ||
| These custom themes fully replace the default qunit.css file and should work | ||
| with the default markup. To see them in action, open the html file for each. | ||
| They'll run the QUnit testsuite itself. |
| /*global config:true, task:true*/ | ||
| module.exports = function( grunt ) { | ||
| grunt.initConfig({ | ||
| pkg: '<json:package.json>', | ||
| qunit: { | ||
| // TODO include 'test/logs.html' as well | ||
| files: ['test/index.html'] | ||
| }, | ||
| lint: { | ||
| qunit: 'qunit/qunit.js', | ||
| grunt: 'grunt.js' | ||
| // TODO need to figure out which warnings to fix and which to disable | ||
| // tests: 'test/*.js' | ||
| }, | ||
| jshint: { | ||
| qunit: { | ||
| options: { | ||
| onevar: true, | ||
| browser: true, | ||
| bitwise: true, | ||
| curly: true, | ||
| trailing: true, | ||
| immed: true, | ||
| latedef: false, | ||
| newcap: true, | ||
| noarg: false, | ||
| noempty: true, | ||
| nonew: true, | ||
| sub: true, | ||
| undef: true, | ||
| eqnull: true, | ||
| proto: true | ||
| }, | ||
| globals: { | ||
| jQuery: true, | ||
| exports: true | ||
| } | ||
| }, | ||
| tests: { | ||
| tests: { | ||
| globals: { | ||
| module: true, | ||
| test: true, | ||
| ok: true, | ||
| equal: true, | ||
| deepEqual: true, | ||
| QUnit: true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| // Default task. | ||
| grunt.registerTask('default', 'lint qunit'); | ||
| }; |
| 1.5.0 / 2012-04-04 | ||
| ================== | ||
| * Modify "Running..." to display test name. Fixes #220 | ||
| * Fixed clearing of sessionStorage in Firefox 3.6. | ||
| * Fixes #217 by calling "block" with config.current.testEnvironment | ||
| * Add stats results to data. QUnit.jUnitReport function take one argument { xml:'<?xml ...', results:{failed:0, passed:0, total:0, time:0} } | ||
| * Add link to MDN about stack property | ||
| 1.4.0 / 2012-03-10 | ||
| ================== | ||
| * Prefix test-related session-storage items to make removal more specific. Fixes #213 - Keep hide-passed state when clearing session storage | ||
| * Update grunt.js with seperate configs for qunit.js and grunt.js, also add tests but disable for now, not passing yet. Add grunt to devDependencies | ||
| * typo | ||
| * Cleanup grunt.js, no need for the banner | ||
| * Fix lint errors and some formatting issues. Use QUnit.pushFailure for noglobals and global error handler. | ||
| * Fix a missing expect in logs test | ||
| * Add grunt.js configuration and include some usage instructions in the readme | ||
| * Update package.json | ||
| * Partially revert af27eae841c3e1c01c46de72d676f1047e1ee375 - can't move reset around, so also don't wrap in try-catch, as the result of that is effectively swallowed. Can't output the result as the outputting is already done. | ||
| * Add QUnit.pushFailure to log error conditions like exceptions. Accepts stacktrace as second argument, allowing extraction with catched exceptions (useful even in Safari). Remove old fail() function that would just log to console, not useful anymore as regular test output is much more useful by now. Move up QUnit.reset() call to just make that another failed assertion. Used to not make a test fail. Fixes #210 | ||
| * Update equals and same deprecations to use QUnit.push to provide correct source lines. Fixes #211 | ||
| * Add a test file for narwhal integration. Has to use print instead of console.log. Fails when an assertion fails, something about setInterval... | ||
| * Apply notrycatch option to setup and teardown as well. Fixes #203. Reorder noglobals check to allow teardown to remove globals that were introduced intentionally. Fixes #204 | ||
| * Extend exports object with QUnit properties at the end of the file to export everything. | ||
| * Output source line for ok() assertions. Fixes #202 | ||
| * Make test fail if no assertions run. Fixes #178 | ||
| * Sort object output alphabetically in order to improve diffs of objects where properties were set in a different order. Fixes #206 | ||
| * Revert "Change fixture reset behavior", changing #194 and #195 to wontfix. | ||
| 1.3.0 / 2012-02-26 | ||
| ================== | ||
| * Cleanup test markup | ||
| * Fix the jQuery branch of fixture reset. Would break when no fixture exists. | ||
| * Added initial version of a junitlogger addon. | ||
| * Escape document.title before inserting into markup. Extends fix for #127 | ||
| * Catch assertions running outside of test() context, make sure source is provided even for ok(). Fixes #98 | ||
| * Improve global object access, based on comments for 1a9120651d5464773256d8a1f2cf2eabe38ea5b3 | ||
| * Clear all sessionStorage entries once all tests passed. Helps getting rid of items from renamed tests. Fixes #101 | ||
| * Set fixed dimensions for #qunit-fixture. Fixes #114 | ||
| * Extend nodejs test runner to check for stacktrace output, twice | ||
| * Extend nodejs test runner to check for stacktrace output | ||
| * Generate more base markup, but allow the user to exclude that completelty or choose their own. Fixes #127 | ||
| * Add a simple test file to check basic nodejs integration works | ||
| * Check for global object to find setTimeout in node | ||
| * Fix CommonJS export by assigning QUnit to module.exports. | ||
| * Remove the testEnviromentArg to test(). Most obscure, never used anywhere. test() is still heavily overloaded with argument shifting, this makes it a little more sane. Fixes #172 | ||
| * Serialize expected and actual values only when test fails. Speeds up output of valid tests, especially for lots of large objects. Fixes #183 | ||
| * Fix sourceFromsTacktrace to get the right line in Firefox. Shift the 'error' line away in Chrome to get a match. | ||
| * Fix references to test/deepEqual.js | ||
| * In autorun mode, moduleDone is called without matching moduleStart. Fix issue #184 | ||
| * Fixture test: allow anything falsy in test as getAttribute in oldIE will return empty string instead of null. We don't really care. | ||
| * Keep label and checkbox together ( http://i.imgur.com/5Wk3A.png ) | ||
| * Add readme for themes | ||
| * Fix bad global in reset() | ||
| * Some cleanup in theme addons | ||
| * Update headers | ||
| * Update nv.html, add gabe theme based on https://github.com/jquery/qunit/pull/188 | ||
| * Experiemental custom theme based on https://github.com/jquery/qunit/pull/62 by NV | ||
| * Replace deprecated same and equals aliases with placeholders that just throw errors, providing a hint at what to use instead. Rename test file to match that. | ||
| * Can't rely on outerHTML for Firefox < 11. Use cloneNode instead. | ||
| * Merge remote branch 'conzett/master' | ||
| * Cleanup whitespace | ||
| * Update sessionStorage support test to latest version from Modernizr, trying to setItem to avoid QUOTA_EXCEEDED_EXCEPTION | ||
| * Change fixture reset behavior | ||
| * Merge pull request #181 from simonz/development | ||
| * Escaping test names | ||
| * Show exception stack when test failed | ||
| 1.2.0 / 2011-11-24 | ||
| ================== | ||
| * remove uses of equals(), as it's deprecated in favor of equal() | ||
| * Code review of "Allow objects with no prototype to be tested against object literals." | ||
| * Allow objects with no prototype to tested against object literals. | ||
| * Fix IE8 "Member not found" error | ||
| * Using node-qunit port, the start/stop function are not exposed so we need to prefix any call to them with 'QUnit'. Aka: start() -> QUnit.start() | ||
| * Remove the 'let teardown clean up globals test' - IE<9 doesn't support (==buggy) deleting window properties, and that's not worth the trouble, as everything else passes just fine. Fixes #155 | ||
| * Fix globals in test.js, part 2 | ||
| * Fix globals in test.js. ?tell wwalser to use ?noglobals everyonce in a while | ||
| * Extend readme regarding release process | ||
| 1.1.0 / 2011-10-11 | ||
| ================== | ||
| * Fixes #134 - Add a window.onerror handler. Makes uncaught errors actually fail the testsuite, instead of going by unnoticed. | ||
| * Whitespace cleanup | ||
| * Merge remote branch 'trevorparscal/master' | ||
| * Fixed IE compatibility issues with using toString on NodeList objects, which in some browsers results in [object Object] rather than [object NodeList]. Now using duck typing for NodeList objects based on the presence of length, length being a number, presence of item method (which will be typeof string in IE and function in others, so we just check that it's not undefined) and that item(0) returns the same value as [0], unless it's empty, in which case item(0) will return 0, while [0] would return undefined. Tested in IE6, IE8, Firefox 6, Safari 5 and Chrome 16. | ||
| * Update readme with basic notes on releases | ||
| * More whitespace/parens cleanup | ||
| * Check if setTimeout is available before trying to delay running the next task. Fixes #160 | ||
| * Whitespace/formatting fix, remove unnecessary parens | ||
| * Use alias for Object.prototype.toString | ||
| * Merge remote branch 'trevorparscal/master' | ||
| * Merge remote branch 'wwalser/recursionBug' | ||
| * Default 'expected' to null in asyncTest(), same as in test() itself. | ||
| * Whitespace cleanup | ||
| * Merge remote branch 'mmchaney/master' | ||
| * Merge remote branch 'Krinkle/master' | ||
| * Using === instead of == | ||
| * Added more strict array type detection for dump output, and allowed NodeList objects to be output as arrays | ||
| * Fixes a bug where after an async test, assertions could move between test cases because of internal state (config.current) being incorrectly set | ||
| * Simplified check for assertion count and adjusted whitespace | ||
| * Redo of fixing issue #156 (Support Object.prototype extending environment). * QUnit.diff: Throws exception without this if Object.prototype is set (Property 'length' of undefined. Since Object.prototype.foo doesn't have a property 'rows') * QUnit.url: Without this fix, if Object.prototype.foo is set, the url will be set to ?foo=...&the=rest. * saveGlobals: Without this fix, whenever a member is added to Object.prototype, saveGlobals will think it was a global variable in this loop. --- This time using the call method instead of obj.hasOwnProperty(key), which may fail if the object has that as it's own property (touché!). | ||
| * Handle expect(0) as expected, i.e. expect(0); ok(true, foo); will cause a test to fail | ||
| 1.0.0 / 2011-10-06 | ||
| ================== | ||
| * Make QUnit work with TestSwarm | ||
| * Run other addons tests as composite addon demo. Need to move that to /test folder once this setup actually works | ||
| * Add-on: New assertion-type: step() | ||
| * added parameter to start and stop allowing a user to increment/decrement the semaphore more than once per call | ||
| * Update readmes with .md extension for GitHub to render them as markdown | ||
| * Update close-enough addon to include readme and match (new) naming convetions | ||
| * Merge remote branch 'righi/close-enough-addon' | ||
| * Canvas addon: Update file referneces | ||
| * Update canvas addon: Rename files and add README | ||
| * Merge remote branch 'wwalser/composite' | ||
| * Fix #142 - Backslash characters in messages should not be escaped | ||
| * Add module name to testStart and testDone callbacks | ||
| * Removed extra columns in object literals. Closes #153 | ||
| * Remove dead links in comments. | ||
| * Merge remote branch 'wwalser/multipleCallbacks' | ||
| * Fixed syntax error and CommonJS incompatibilities in package.json | ||
| * Allow multiple callbacks to be registered. | ||
| * Add placeholder for when Safari may end up providing useful error handling | ||
| * changed file names to match addon naming convention | ||
| * Whitespace | ||
| * Created the composite addon. | ||
| * Using array and object literals. | ||
| * Issue #140: Make toggle system configurable. | ||
| * Merge remote branch 'tweetdeck/master' | ||
| * Adds the 'close enough' addon to determine if numbers are acceptably close enough in value. | ||
| * Fix recursion support in jsDump, along with tests. Fixes #63 and #100 | ||
| * Adding a QUnit.config.altertitle flag which will allow users to opt-out of the functionality introduced in 60147ca0164e3d810b8a9bf46981c3d9cc569efc | ||
| * Refactor window.load handler into QUnit.load, makes it possible to call it manually. | ||
| * More whitespace cleanup | ||
| * Merge remote branch 'erikvold/one-chk-in-title' | ||
| * Whitespace | ||
| * Merge remote branch 'wwalser/syncStopCalls' | ||
| * Introducing the first QUnit addon, based on https://github.com/jquery/qunit/pull/84 - adds QUnit.pixelEqual assertion method, along with example tests. | ||
| * Remove config.hidepassed setting in test.js, wasn't intended to land in master. | ||
| * Expose QUnit.config.hidepassed setting. Overrides sessionStorage and enables enabling the feature programmatically. Fixes #133 | ||
| * Fix formatting (css whitespace) for tracebacks. | ||
| * Expose extend, id, and addEvent methods. | ||
| * minor comment typo correction | ||
| * Ignore Eclipse WTP .settings | ||
| * Set 'The jQuery Project' as author in package.json | ||
| * Fixes a bug where synchronous calls to stop would cause tests to end before start was called again | ||
| * Point to planning testing wiki in readme | ||
| * only add one checkmark to the document.title | ||
| * Escape the stacktrace output before setting it as innerHTML, since it tends to contain `<` and `>` characters. | ||
| * Cleanup whitespace | ||
| * Run module.teardown before checking for pollution. Fixes #109 - noglobals should run after module teardown | ||
| * Fix accidental global variable "not" | ||
| * Update document.title status to use more robust unicode escape sequences, works even when served with non-utf-8-charset. | ||
| * Modify document.title when suite is done to show success/failure in tab, allows you to see the overall result without seeing the tab content. | ||
| * Merge pull request #107 from sexyprout/master | ||
| * Set a generic font | ||
| * Add/update headers | ||
| * Drop support for deprecated #main in favor of #qunit-fixture. If this breaks your testsuite, replace id="main" with id="qunit-fixture". Fixes #103 | ||
| * Remove the same key as the one being set. Partial fix for #101 | ||
| * Don't modify expected-count when checking pollution. The failing assertion isn't expected, so shouldn't be counted. And if expect wasn't used, the count is misleading. | ||
| * Fix order of noglobals check to produce correct introduced/delete error messages | ||
| * Prepend module name to sessionStorage keys to avoid conflicts | ||
| * Store filter-tests only when checked | ||
| * Write to sessionStorage only bad tests | ||
| * Moved QUnit.url() defintion after QUnit properties are merged into the global scope. Fixes #93 - QUnit url/extend function breaking urls in jQuery ajax test component | ||
| * Add a "Rerun" link to each test to replce the dblclick (still supported, for now). | ||
| * Fixed the regex for parsing the name of a test when double clicking to filter. | ||
| * Merge remote branch 'scottgonzalez/url' | ||
| * Added checkboxes to show which flags are currently on and allow toggling them. | ||
| * Retain all querystring parameters when filtering a test via double click. | ||
| * Added better querystring parsing. Now storing all querystring params in QUnit.urlParams so that we can carry the params forward when filtering to a specific test. This removes the ability to specify multiple filters. | ||
| * Make reordering optional (QUnit.config.reorder = false) and optimize "Hide passed tests" mode by also hiding "Running [testname]" entries. | ||
| * Added missing semicolons and wrapped undefined key in quotes. | ||
| * Optimize test hiding, add class on page load if stored in sessionStorage | ||
| * Optimize the hiding of passed tests. | ||
| * Position test results above test list, making it visible without ever having to scroll. Create a placeholder to avoid pushing down results later. | ||
| * Don't check for existing qunit-testresult element, it gets killed on init anyway. | ||
| * Added URL flag ?notrycatch (ala ?noglobals) for debugging exceptions. Won't try/catch test code, giving better debugging changes on the original exceptions. Fixes #72 | ||
| * Always show quni-toolbar (if at all specified), persist checkbox via sessionStorage. Fixes #47 | ||
| * Use non-html testname for calls to fail(). Fixes #77 | ||
| * Overhaul of QUnit.callbacks. Consistent single argument with related properties, with additonal runtime property for QUnit.done | ||
| * Extended test/logs.html to capture more of the callbacks. | ||
| * Fixed moduleStart/Done callbacks. Added test/logs.html to test these callbacks. To be extended. | ||
| * Update copyright and license header. Fixes #61 | ||
| * Formatting fix. | ||
| * Use a semaphore to synchronize stop() and start() calls. Fixes #76 | ||
| * Merge branch 'master' of https://github.com/paulirish/qunit into paulirish-master | ||
| * Added two tests for previous QUnit.raises behaviour. For #69 | ||
| * add optional 2. arg to QUnit.raises #69. | ||
| * fix references inside Complex Instances Nesting to what was originally intended. | ||
| * Qualify calls to ok() in raises() for compability with CLI enviroments. | ||
| * Fix done() handling, check for blocking, not block property | ||
| * Fix moduleStart/Done and done callbacks. | ||
| * Replacing sessionStorage test with the one from Modernizr/master (instead of current release). Here's hoping it'll work for some time. | ||
| * Updated test for availibility of sessionStorage, based on test from Modernizr. Fixes #64 | ||
| * Defer test execution when previous run passed, persisted via sessionStorage. Fixes #49 | ||
| * Refactored module handling and queuing to enable selective defer of test runs. | ||
| * Move assertions property from config to Test | ||
| * Move expected-tests property from config to Test | ||
| * Refactored test() method to delegate to a Test object to encapsulate all properties and methods of a single test, allowing further modifications. | ||
| * Adding output of sourcefile and linenumber of failed assertions (except ok()). Only limited cross-browser support for now. Fixes #60 | ||
| * Drop 'hide missing tests' feature. Fixes #48 | ||
| * Adding readme. Fixes #58 | ||
| * Merge branch 'prettydiff' | ||
| * Improve jsDump output with formatted diffs. | ||
| * Cleanup whitespace | ||
| * Cleanup whitespace | ||
| * Added additional guards around browser specific code and cleaned up jsDump code | ||
| * Added guards around tests which are only for browsers | ||
| * cleaned up setTimeout undefined checking and double done on test finish | ||
| * fixing .gitignore | ||
| * making window setTimeout query more consistent | ||
| * Moved expect-code back to beginning of function, where it belongs. Fixes #52 | ||
| * Bread crumb in header: Link to suite without filters, add link to current page based on the filter, if present. Fixes #50 | ||
| * Make the toolbar element optional when checking for show/hide of test results. Fixes #46 | ||
| * Adding headless.html to manually test logging and verify that QUnit works without output elements. Keeping #qunit-fixture as a few tests actually use that. | ||
| * Fix for QUnit.moduleDone, get rid of initial bogus log. Fixes #33 | ||
| * Pass raw data (result, message, actual, expected) as third argument to QUnit.log. Fixes #32 | ||
| * Dump full exception. Not pretty, but functional (see issue Pretty diff for pretty output). Fixes #31 | ||
| * Don't let QUnit.reset() cause assertions to run. Manually applied from Scott Gonzalez branch. Fixes #34 | ||
| * Added missing semicolons. Fixes #37 | ||
| * Show okay/failed instead of undefined. Fixes #38 | ||
| * Expose push as QUnit.push to build custom assertions. Fixes #39 | ||
| * Respect filter pass selection when writing new results. Fixes #43 | ||
| * Cleanup tests, removing asyncTest-undefined check and formatting | ||
| * Reset: Fall back to innerHTML when jQuery isn't available. Fixes #44 | ||
| * Merge branch 'master' of github.com:jquery/qunit | ||
| * reset doesn't exist here - fixes #28. | ||
| * - less css cruft, better readability - replaced inline style for test counts with "counts" class - test counts now use a "failed"/"passed" vs "pass"/"fail", shorter/more distinct selectors - pulled all test counts styling together and up (they're always the same regardless of section pass/fail state) | ||
| * Adding .gitignore file | ||
| * Removing diff test - diffing works fine, as the browser collapses whitespace in its output, but the test can't do that and isn't worth fixing. | ||
| * Always synchronize the done-step (it'll set the timeout when necessary), fixes timing race conditions. | ||
| * Insert location.href as an anchor around the header. Fixes issue #29 | ||
| * - kill double ;; in escapeHtml. oops | ||
| * Removed html escaping from QUnit.diff, as input is already escaped, only leads to double escaping. Replaced newlines with single whitespace. | ||
| * Optimized and cleaned up CSS file | ||
| * Making the reset-method non-global (only module, test and assertions should be global), and fixing the fixture reset by using jQuery's html() method again, doesn't work with innerHTML, yet | ||
| * Introducing #qunit-fixture element, deprecating the (never documented) #main element. Doesn't require inline styles and is now independent of jQuery. | ||
| * Ammending previous commit: Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers | ||
| * Remove jQuery-core specific resets (will be replaced within jQuery testsuite). Fixes issue #19 - QUnit.reset() removes global jQuery ajax event handlers | ||
| * Cleaning up rubble from the previous commit. | ||
| * Added raises assertion, reusing some of kennsnyder's code. | ||
| * Merged kensnyder's object detection code. Original message: Streamlined object detection and exposed QUnit.objectType as a function. | ||
| * Fixed some bad formatting. | ||
| * Move various QUnit properties below the globals-export to avoid init becoming a global method. Fixes issue #11 - Remove 'init' function from a global namespace | ||
| * Improved output when expected != actual: Output both only then, and add a diff. Fixes issue #10 - Show diff if equal() or deepEqual() failed | ||
| * Expand failed tests on load. Fixes issue #8 - Failed tests expanded on load | ||
| * Set location.search for url-filtering instead of location.href. Fixes issue #7 - Modify location.search instead of location.href on test double-click | ||
| * Add QUnit.begin() callback. Fixes issue #6 - Add 'start' callback. | ||
| * add css style for result (".test-actual") in passed tests | ||
| * Fixed output escaping by using leeoniya's custom escaping along with innerHTML. Also paves the way for outputting diffs. | ||
| * Cleanup | ||
| * Revert "Revert part of bad merge, back to using createTextNode" | ||
| * Revert part of bad merge, back to using createTextNode | ||
| * Fixed doubleclick-handler and filtering to rerun only a single test. | ||
| * Add ability to css style a test's messages, expected and actual results. Merged from Leon Sorokin (leeoniya). | ||
| * Remove space between module name and colon | ||
| * - removed "module" wording from reports (unneeded and cluttery) - added and modified css to make module & test names styleable | ||
| * Logging support for Each test can extend the module testEnvironment | ||
| * Fixing whitespace | ||
| * Update tests to use equal() and deepEqual() rather than the deprecated equals() and same() | ||
| * Consistent argument names for deepEqual | ||
| * Skip DOM part of jsDump test if using a SSJS environment without a DOM | ||
| * Improve async testing by creating the result element before running the test, updating it later. If the test fails, its clear which test is the culprit. | ||
| * Add autostart option to config. Set via QUnit.config.autostart = false; start later via QUnit.start() | ||
| * Expose QUnit.config, but don't make config a global | ||
| * Expose QUnit.config as global to make external workarounds easier | ||
| * Merge branch 'asyncsetup' | ||
| * Allowing async setup and teardown. Fixes http://github.com/jquery/qunit/issues#issue/20 | ||
| * Always output expected and actual result (no reason not to). Fixes http://github.com/jquery/qunit/issues#issue/21 | ||
| * More changes to the detection of types in jsDump's typeOf. | ||
| * Change the typeOf checks in QUnit to be more accurate. | ||
| * Added test for jsDump and modified its options to properly output results when document.createTextNode is used; currently tests for DOM elements cause a stackoverflow error in IEs, works fine, with the correct output, elsewhere | ||
| * Always use jsDump to output result objects into messages, making the output for passing assertions more useful | ||
| * Make it so that the display is updated, at least, once a second - also prevents scripts from executing for too long and causing problems. | ||
| * added tests and patch for qunit.equiv to avoid circular references in objects and arrays | ||
| * No reason to continue looping, we can stop at this point. Thanks to Chris Thatcher for the suggestion. | ||
| * Use createTextNode instead of innerHTML for showing test result since expected and actual might be something that looks like a tag. | ||
| * 'Test card' design added | ||
| * switched green to blue for top-level pass + reduced padding | ||
| * Bringing the QUnit API in line with the CommonJS API. | ||
| * Explicitly set list-style-position: inside on result LIs. | ||
| * Madness with border-radius. | ||
| * Corrected banner styles for new class names | ||
| * Added rounded corners and removed body rules for embedded tests | ||
| * Resolving merge conflicts. | ||
| * added colouring for value summary | ||
| * adding some extra text colours | ||
| * added styles for toolbar | ||
| * added new styles | ||
| * IE 6 and 7 weren't respecting the CSS rules for the banner, used a different technique instead. | ||
| * Went a bit further and made extra-sure that the target was specified correctly. | ||
| * Fixed problem where double-clicking an entry in IE caused an error to occur. | ||
| * Path for http://dev.jquery.com/ticket/5426 - fix the microformat test result | ||
| * Fixed test() to use 'expected' 2nd param | ||
| * Remove the named function expressions, to stop Safari 2 from freaking out. Fixes #5. | ||
| * Each test can extend the module testEnvironment | ||
| * Extra test for current test environment | ||
| * Make the current testEnvironment available to utility functions | ||
| * typeOf in QUnit.jsDump now uses QUnit.is | ||
| * hoozit in QUnit.equiv now uses QUnit.is | ||
| * Properly set label attributes. | ||
| * Some minor tweaks to RyanS' GETParams change. | ||
| * left a console.log in :( | ||
| * Took into account a fringe case when using qunit with testswarm. Trying to run all the tests with the extra url params from testswarm would make qunit look for a testsuite that did not exist | ||
| * need to set config.currentModule to have correct names and working filters | ||
| * Support logging of testEnvironment | ||
| * async tests aren't possible on rhino | ||
| * Fixed a missing QUnit.reset(). | ||
| * The QUnit. prefix was missing from the uses of the start() method. | ||
| * Merged lifecycle object into testEnvironment | ||
| * "replacing totally wrong diff algorithm with a working one" Patch from kassens (manually applied). | ||
| * fixing jslint errors in test.js | ||
| * Fixed: testDone() was always called with 0 failures in CommonJS mode | ||
| * Fixed: moduleDone() was invoked on first call to module() | ||
| * Added a new asyncTest method - removes the need for having to call start() at the beginning of an asynchronous test. | ||
| * Added support for expected numbers in the test method. | ||
| * Fixed broken dynamic loading of tests (can now dynamically load tests and done still works properly). | ||
| * Simplified the logic for calling 'done' and pushing off new tests - was causing too many inconsistencies otherwise. | ||
| * Simplified the markup for the QUnit test test suite. | ||
| * Realized that it's really easy to handle the case where stop() has been called and then an exception is thrown. | ||
| * Added in better logging support. Now handle moduleStart/moduleDone and testStart/testDone. Also make sure that done only fires once at the end. | ||
| * Made it so that you can reset the suite to an initial state (at which point tests can be dynamically loaded and run, for example). | ||
| * Re-worked QUnit to handle dynamic loading of additional code (the 'done' code will be re-run after additional code is loaded). | ||
| * Removed the old SVN version stuff. | ||
| * Moved the QUnit source into a separate directory and updated the test suite/packages files. | ||
| * Added in CommonJS support for exporting the QUnit functionality. | ||
| * Missing quote from package.json. | ||
| * Fixed trailing comma in package.json. | ||
| * Added a CommonJS/Narwhal package.json file. | ||
| * Accidentally reverted the jsDump/equiv changes that had been made. | ||
| * Hide the filter toolbar if it's not needed. Also exposed the jsDump and equiv objects on QUnit. | ||
| * Retooled the QUnit CSS to be more generic. | ||
| * Renamed the QUnit files from testrunner/testsuite to QUnit. | ||
| * Expose QUnit.equiv and QUnit.jsDump in QUnit. | ||
| * Moved the QUnit test directory into the QUnit directory. | ||
| * Reworked the QUnit CSS (moved jQuery-specific stuff out, made all the other selectors more specific). | ||
| * Removed the #main reset for non-jQuery code (QUnit.reset can be overwritten with your own reset code). | ||
| * Moved the QUnit toolbar inline. | ||
| * Switched to using a qunit- prefix for special elements (banner, userAgent, and tests). | ||
| * Missed a case in QUnit where an element was assumed to exist. | ||
| * QUnit's isSet and isObj are no longer needed - you should use same instead. | ||
| * Make sure that QUnit's equiv entity escaping is enabled by default (otherwise the output gets kind of crazy). | ||
| * Refactored QUnit, completely reorganized the structure of the file. Additionally made it so that QUnit can run outside of a browser (inside Rhino, for example). | ||
| * Removed some legacy and jQuery-specific test methods. | ||
| * Added callbacks for tests and modules. It's now possible to reproduce the full display of the testrunner without using the regular rendering. | ||
| * QUnit no longer depends upon rendering the results (it can work simply by using the logging callbacks). | ||
| * Made QUnit no longer require jQuery (it is now a standalone, framework independent, test runner). | ||
| * Reverted the noglobals changed from QUnit - causing chaos in the jQuery test suite. | ||
| * qunit: removed noglobals flag, instead always check for globals after teardown; if a test has to introduce a global "myVar", use delete window.myVar in teardown or at the end of a test | ||
| * qunit: don't child selectors when IE should behave nicely, too | ||
| * qunit: improvment for the test-scope: create a new object and call setup, the test, and teardown in the scope of that object - allows you to provide test fixtures to each test without messing with global data; kudos to Martin Häcker for the contribution | ||
| * qunit: added missing semicolons | ||
| * qunit: fixed a semicolon, that should have been a comma | ||
| * QUnit: implemented error handling for Opera as proposed by #3628 | ||
| * qunit: fix for http://dev.jquery.com/ticket/3215 changing wording of testresults, to something more positive (x of y passed, z failed) | ||
| * QUnit: testrunner.js: Ensures equality of types (String, Boolean, Number) declared with the 'new' prefix. See comments #3, #4 and #5 on http://philrathe.com/articles/equiv | ||
| * qunit: wrap name of test in span when a module is used for better styling | ||
| * qunit: auto-prepend default mark (#header, #banner, #userAgent, #tests) when not present | ||
| * Landing some changes to add logging to QUnit (so that it's easier to hook in to when a test finishes). | ||
| * Added checkbox for hiding missing tests (tests that fail with the text 'missing test - untested code is broken code') | ||
| * qunit: eol-style:native and mime-type | ||
| * HTML being injected for the test result wasn't valid HTML. | ||
| * qunit: setting mimetype for testsuite.css | ||
| * qunit: update to Ariel's noglobals patch to support async tests as well | ||
| * Landing Ariel's change - checks for global variable leakage. | ||
| * qunit: run module-teardown in its own synchronize block to synchronize with async tests (ugh) | ||
| * qunit: same: equiv - completely refactored in the testrunner. | ||
| * testrunner.js: - Update equiv to support Date and RegExp. - Change behavior when comparing function: - abort when in an instance of Object (when references comparison failed) - skip otherwise (like before) | ||
| * qunit: code refactoring and cleanup | ||
| * QUnit: update equiv to latest version, handling multiple arguments and NaN, see http://philrathe.com/articles/equiv | ||
| * QUnit: cleanup, deprecating compare, compare2 and serialArray: usage now throws an error with a helpful message | ||
| * QUnit: optional timeout argument for stop, while making tests undetermined, useful for debugging | ||
| * QUnit: added toolbar with "hide passed tests" checkbox to help focus on failed tests | ||
| * QUnit: minor output formatting | ||
| * QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests | ||
| * QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests | ||
| * QUnit: adding same-assertion for a recursive comparsion of primite values, arrays and objects, thanks to Philippe Rathé for the contribution, including tests | ||
| * qunit: use window.load to initialize tests, allowing other code to run on document-ready before starting to run tests | ||
| * qunit: allow either setup or teardown, instead of both or nothing | ||
| * qunit: make everything private by default, expose only public API; removed old timeout-option (non-deterministic, disabled for a long time anyway); use local $ reference instead of global jQuery reference; minor code cleanup (var config instead of _config; queue.shift instead of slice) | ||
| * qunit: added support for module level setup/teardown callbacks | ||
| * qunit: modified example for equals to avoid confusion with parameter ordering | ||
| * qunit: added id/classes to result element to enable integration with browser automation tools, see http://docs.jquery.com/QUnit#Integration_into_Browser_Automation_Tools | ||
| * qunit: replaced $ alias with jQuery (merged from jquery/test/data/testrunner.js) | ||
| * qunit: fixed inline documentation for equals | ||
| * qunit testrunner - catch and log possible error during reset() | ||
| * QUnit: Switched out Date and Rev for Id. | ||
| * qunit: when errors are thrown in a test, the message is successfully show on all browsers. | ||
| * qunit: added license header | ||
| * qunit: moved jquery testrunner to top-level project, see http://docs.jquery.com/QUnit | ||
| * Share project 'qunit' into 'https://jqueryjs.googlecode.com/svn' |
| { | ||
| "name": "qunit", | ||
| "title": "QUnit", | ||
| "description": "An easy-to-use JavaScript Unit Testing framework.", | ||
| "version": "1.6.0pre", | ||
| "author": "The jQuery Project", | ||
| "contributors": [ | ||
| "John Resig <jeresig@gmail.com> (http://ejohn.org/)", | ||
| "Jörn Zaefferer <joern.zaefferer@googlemail.com> (http://bassistance.de/)" | ||
| ], | ||
| "homepage": "http://docs.jquery.com/QUnit", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git://github.com/jquery/qunit.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/jquery/qunit/issues" | ||
| }, | ||
| "license": { | ||
| "name": "MIT", | ||
| "url": "http://www.opensource.org/licenses/mit-license.php" | ||
| }, | ||
| "keywords": [ | ||
| "testing", | ||
| "unit", | ||
| "jquery" | ||
| ], | ||
| "main": "qunit/qunit.js", | ||
| "devDependencies": { | ||
| "grunt": "0.3.x" | ||
| } | ||
| } |
| /** | ||
| * QUnit v1.6.0pre - A JavaScript Unit Testing Framework | ||
| * | ||
| * http://docs.jquery.com/QUnit | ||
| * | ||
| * Copyright (c) 2012 John Resig, Jörn Zaefferer | ||
| * Dual licensed under the MIT (MIT-LICENSE.txt) | ||
| * or GPL (GPL-LICENSE.txt) licenses. | ||
| */ | ||
| /** Font Family and Sizes */ | ||
| #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { | ||
| font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; | ||
| } | ||
| #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } | ||
| #qunit-tests { font-size: smaller; } | ||
| /** Resets */ | ||
| #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| /** Header */ | ||
| #qunit-header { | ||
| padding: 0.5em 0 0.5em 1em; | ||
| color: #8699a4; | ||
| background-color: #0d3349; | ||
| font-size: 1.5em; | ||
| line-height: 1em; | ||
| font-weight: normal; | ||
| border-radius: 15px 15px 0 0; | ||
| -moz-border-radius: 15px 15px 0 0; | ||
| -webkit-border-top-right-radius: 15px; | ||
| -webkit-border-top-left-radius: 15px; | ||
| } | ||
| #qunit-header a { | ||
| text-decoration: none; | ||
| color: #c2ccd1; | ||
| } | ||
| #qunit-header a:hover, | ||
| #qunit-header a:focus { | ||
| color: #fff; | ||
| } | ||
| #qunit-header label { | ||
| display: inline-block; | ||
| } | ||
| #qunit-banner { | ||
| height: 5px; | ||
| } | ||
| #qunit-testrunner-toolbar { | ||
| padding: 0.5em 0 0.5em 2em; | ||
| color: #5E740B; | ||
| background-color: #eee; | ||
| } | ||
| #qunit-userAgent { | ||
| padding: 0.5em 0 0.5em 2.5em; | ||
| background-color: #2b81af; | ||
| color: #fff; | ||
| text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; | ||
| } | ||
| /** Tests: Pass/Fail */ | ||
| #qunit-tests { | ||
| list-style-position: inside; | ||
| } | ||
| #qunit-tests li { | ||
| padding: 0.4em 0.5em 0.4em 2.5em; | ||
| border-bottom: 1px solid #fff; | ||
| list-style-position: inside; | ||
| } | ||
| #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { | ||
| display: none; | ||
| } | ||
| #qunit-tests li strong { | ||
| cursor: pointer; | ||
| } | ||
| #qunit-tests li a { | ||
| padding: 0.5em; | ||
| color: #c2ccd1; | ||
| text-decoration: none; | ||
| } | ||
| #qunit-tests li a:hover, | ||
| #qunit-tests li a:focus { | ||
| color: #000; | ||
| } | ||
| #qunit-tests ol { | ||
| margin-top: 0.5em; | ||
| padding: 0.5em; | ||
| background-color: #fff; | ||
| border-radius: 15px; | ||
| -moz-border-radius: 15px; | ||
| -webkit-border-radius: 15px; | ||
| box-shadow: inset 0px 2px 13px #999; | ||
| -moz-box-shadow: inset 0px 2px 13px #999; | ||
| -webkit-box-shadow: inset 0px 2px 13px #999; | ||
| } | ||
| #qunit-tests table { | ||
| border-collapse: collapse; | ||
| margin-top: .2em; | ||
| } | ||
| #qunit-tests th { | ||
| text-align: right; | ||
| vertical-align: top; | ||
| padding: 0 .5em 0 0; | ||
| } | ||
| #qunit-tests td { | ||
| vertical-align: top; | ||
| } | ||
| #qunit-tests pre { | ||
| margin: 0; | ||
| white-space: pre-wrap; | ||
| word-wrap: break-word; | ||
| } | ||
| #qunit-tests del { | ||
| background-color: #e0f2be; | ||
| color: #374e0c; | ||
| text-decoration: none; | ||
| } | ||
| #qunit-tests ins { | ||
| background-color: #ffcaca; | ||
| color: #500; | ||
| text-decoration: none; | ||
| } | ||
| /*** Test Counts */ | ||
| #qunit-tests b.counts { color: black; } | ||
| #qunit-tests b.passed { color: #5E740B; } | ||
| #qunit-tests b.failed { color: #710909; } | ||
| #qunit-tests li li { | ||
| margin: 0.5em; | ||
| padding: 0.4em 0.5em 0.4em 0.5em; | ||
| background-color: #fff; | ||
| border-bottom: none; | ||
| list-style-position: inside; | ||
| } | ||
| /*** Passing Styles */ | ||
| #qunit-tests li li.pass { | ||
| color: #5E740B; | ||
| background-color: #fff; | ||
| border-left: 26px solid #C6E746; | ||
| } | ||
| #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } | ||
| #qunit-tests .pass .test-name { color: #366097; } | ||
| #qunit-tests .pass .test-actual, | ||
| #qunit-tests .pass .test-expected { color: #999999; } | ||
| #qunit-banner.qunit-pass { background-color: #C6E746; } | ||
| /*** Failing Styles */ | ||
| #qunit-tests li li.fail { | ||
| color: #710909; | ||
| background-color: #fff; | ||
| border-left: 26px solid #EE5757; | ||
| white-space: pre; | ||
| } | ||
| #qunit-tests > li:last-child { | ||
| border-radius: 0 0 15px 15px; | ||
| -moz-border-radius: 0 0 15px 15px; | ||
| -webkit-border-bottom-right-radius: 15px; | ||
| -webkit-border-bottom-left-radius: 15px; | ||
| } | ||
| #qunit-tests .fail { color: #000000; background-color: #EE5757; } | ||
| #qunit-tests .fail .test-name, | ||
| #qunit-tests .fail .module-name { color: #000000; } | ||
| #qunit-tests .fail .test-actual { color: #EE5757; } | ||
| #qunit-tests .fail .test-expected { color: green; } | ||
| #qunit-banner.qunit-fail { background-color: #EE5757; } | ||
| /** Result */ | ||
| #qunit-testresult { | ||
| padding: 0.5em 0.5em 0.5em 2.5em; | ||
| color: #2b81af; | ||
| background-color: #D2E0E6; | ||
| border-bottom: 1px solid white; | ||
| } | ||
| #qunit-testresult .module-name { | ||
| font-weight: bold; | ||
| } | ||
| /** Fixture */ | ||
| #qunit-fixture { | ||
| position: absolute; | ||
| top: -10000px; | ||
| left: -10000px; | ||
| width: 1000px; | ||
| height: 1000px; | ||
| } |
| /** | ||
| * QUnit v1.6.0pre - A JavaScript Unit Testing Framework | ||
| * | ||
| * http://docs.jquery.com/QUnit | ||
| * | ||
| * Copyright (c) 2012 John Resig, Jörn Zaefferer | ||
| * Dual licensed under the MIT (MIT-LICENSE.txt) | ||
| * or GPL (GPL-LICENSE.txt) licenses. | ||
| */ | ||
| (function( window ) { | ||
| var QUnit, | ||
| config, | ||
| testId = 0, | ||
| toString = Object.prototype.toString, | ||
| hasOwn = Object.prototype.hasOwnProperty, | ||
| defined = { | ||
| setTimeout: typeof window.setTimeout !== "undefined", | ||
| sessionStorage: (function() { | ||
| var x = "qunit-test-string"; | ||
| try { | ||
| sessionStorage.setItem( x, x ); | ||
| sessionStorage.removeItem( x ); | ||
| return true; | ||
| } catch( e ) { | ||
| return false; | ||
| } | ||
| }()) | ||
| }; | ||
| function Test( name, testName, expected, async, callback ) { | ||
| this.name = name; | ||
| this.testName = testName; | ||
| this.expected = expected; | ||
| this.async = async; | ||
| this.callback = callback; | ||
| this.assertions = []; | ||
| } | ||
| Test.prototype = { | ||
| init: function() { | ||
| var b, li, | ||
| tests = id( "qunit-tests" ); | ||
| if ( tests ) { | ||
| b = document.createElement( "strong" ); | ||
| b.innerHTML = "Running " + this.name; | ||
| li = document.createElement( "li" ); | ||
| li.appendChild( b ); | ||
| li.className = "running"; | ||
| li.id = this.id = "test-output" + testId++; | ||
| tests.appendChild( li ); | ||
| } | ||
| }, | ||
| setup: function() { | ||
| if ( this.module !== config.previousModule ) { | ||
| if ( config.previousModule ) { | ||
| runLoggingCallbacks( "moduleDone", QUnit, { | ||
| name: config.previousModule, | ||
| failed: config.moduleStats.bad, | ||
| passed: config.moduleStats.all - config.moduleStats.bad, | ||
| total: config.moduleStats.all | ||
| }); | ||
| } | ||
| config.previousModule = this.module; | ||
| config.moduleStats = { all: 0, bad: 0 }; | ||
| 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 ); | ||
| runLoggingCallbacks( "testStart", QUnit, { | ||
| name: this.testName, | ||
| module: this.module | ||
| }); | ||
| // allow utility functions to access the current test environment | ||
| // TODO why?? | ||
| QUnit.current_testEnvironment = this.testEnvironment; | ||
| if ( !config.pollution ) { | ||
| saveGlobal(); | ||
| } | ||
| if ( config.notrycatch ) { | ||
| this.testEnvironment.setup.call( this.testEnvironment ); | ||
| return; | ||
| } | ||
| try { | ||
| this.testEnvironment.setup.call( this.testEnvironment ); | ||
| } catch( e ) { | ||
| QUnit.pushFailure( "Setup failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) ); | ||
| } | ||
| }, | ||
| run: function() { | ||
| config.current = this; | ||
| var running = id( "qunit-testresult" ); | ||
| if ( running ) { | ||
| running.innerHTML = "Running: <br/>" + this.name; | ||
| } | ||
| if ( this.async ) { | ||
| QUnit.stop(); | ||
| } | ||
| if ( config.notrycatch ) { | ||
| this.callback.call( this.testEnvironment ); | ||
| return; | ||
| } | ||
| try { | ||
| this.callback.call( this.testEnvironment ); | ||
| } catch( e ) { | ||
| QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + ": " + e.message, extractStacktrace( e, 1 ) ); | ||
| // else next test will carry the responsibility | ||
| saveGlobal(); | ||
| // Restart the tests if they're blocking | ||
| if ( config.blocking ) { | ||
| QUnit.start(); | ||
| } | ||
| } | ||
| }, | ||
| teardown: function() { | ||
| config.current = this; | ||
| if ( config.notrycatch ) { | ||
| 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, extractStacktrace( e, 1 ) ); | ||
| } | ||
| } | ||
| checkPollution(); | ||
| }, | ||
| finish: function() { | ||
| config.current = this; | ||
| if ( this.expected != null && this.expected != this.assertions.length ) { | ||
| QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" ); | ||
| } 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." ); | ||
| } | ||
| var assertion, a, b, i, li, ol, | ||
| good = 0, | ||
| bad = 0, | ||
| tests = id( "qunit-tests" ); | ||
| config.stats.all += this.assertions.length; | ||
| config.moduleStats.all += this.assertions.length; | ||
| if ( tests ) { | ||
| ol = document.createElement( "ol" ); | ||
| for ( i = 0; i < this.assertions.length; i++ ) { | ||
| assertion = this.assertions[i]; | ||
| li = document.createElement( "li" ); | ||
| li.className = assertion.result ? "pass" : "fail"; | ||
| li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); | ||
| ol.appendChild( li ); | ||
| if ( assertion.result ) { | ||
| good++; | ||
| } else { | ||
| bad++; | ||
| config.stats.bad++; | ||
| config.moduleStats.bad++; | ||
| } | ||
| } | ||
| // store result when possible | ||
| if ( QUnit.config.reorder && defined.sessionStorage ) { | ||
| if ( bad ) { | ||
| sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); | ||
| } else { | ||
| sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
| } | ||
| } | ||
| if ( bad === 0 ) { | ||
| ol.style.display = "none"; | ||
| } | ||
| // `b` initialized at top of scope | ||
| 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>"; | ||
| // `a` initialized at top of scope | ||
| 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"; | ||
| }); | ||
| addEvent(b, "dblclick", function( e ) { | ||
| var target = e && e.target ? e.target : window.event.srcElement; | ||
| 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, "" ) | ||
| }); | ||
| } | ||
| }); | ||
| // `li` initialized at top of scope | ||
| li = id( this.id ); | ||
| li.className = bad ? "fail" : "pass"; | ||
| li.removeChild( li.firstChild ); | ||
| li.appendChild( b ); | ||
| li.appendChild( a ); | ||
| li.appendChild( ol ); | ||
| } else { | ||
| for ( i = 0; i < this.assertions.length; i++ ) { | ||
| if ( !this.assertions[i].result ) { | ||
| bad++; | ||
| config.stats.bad++; | ||
| config.moduleStats.bad++; | ||
| } | ||
| } | ||
| } | ||
| QUnit.reset(); | ||
| runLoggingCallbacks( "testDone", QUnit, { | ||
| name: this.testName, | ||
| module: this.module, | ||
| failed: bad, | ||
| passed: this.assertions.length - bad, | ||
| total: this.assertions.length | ||
| }); | ||
| }, | ||
| queue: function() { | ||
| var bad, | ||
| test = this; | ||
| synchronize(function() { | ||
| test.init(); | ||
| }); | ||
| function run() { | ||
| // each of these can by async | ||
| synchronize(function() { | ||
| test.setup(); | ||
| }); | ||
| synchronize(function() { | ||
| test.run(); | ||
| }); | ||
| synchronize(function() { | ||
| test.teardown(); | ||
| }); | ||
| synchronize(function() { | ||
| test.finish(); | ||
| }); | ||
| } | ||
| // `bad` initialized at top of scope | ||
| // defer when previous test run passed, if storage is available | ||
| bad = QUnit.config.reorder && defined.sessionStorage && | ||
| +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); | ||
| if ( bad ) { | ||
| run(); | ||
| } else { | ||
| synchronize( run, true ); | ||
| } | ||
| } | ||
| }; | ||
| // `QUnit` initialized at top of scope | ||
| QUnit = { | ||
| // call on start of module test to prepend name to all tests | ||
| module: function( name, testEnvironment ) { | ||
| config.currentModule = name; | ||
| config.currentModuleTestEnviroment = testEnvironment; | ||
| }, | ||
| asyncTest: function( testName, expected, callback ) { | ||
| if ( arguments.length === 2 ) { | ||
| callback = expected; | ||
| expected = null; | ||
| } | ||
| QUnit.test( testName, expected, callback, true ); | ||
| }, | ||
| test: function( testName, expected, callback, async ) { | ||
| var test, | ||
| name = "<span class='test-name'>" + escapeInnerText( testName ) + "</span>"; | ||
| if ( arguments.length === 2 ) { | ||
| callback = expected; | ||
| expected = null; | ||
| } | ||
| if ( config.currentModule ) { | ||
| name = "<span class='module-name'>" + config.currentModule + "</span>: " + name; | ||
| } | ||
| if ( !validTest(config.currentModule + ": " + testName) ) { | ||
| return; | ||
| } | ||
| test = new Test( name, testName, expected, 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; | ||
| }, | ||
| // Asserts true. | ||
| // @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); | ||
| ok: function( result, msg ) { | ||
| if ( !config.current ) { | ||
| throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); | ||
| } | ||
| result = !!result; | ||
| var source, | ||
| details = { | ||
| result: result, | ||
| message: msg | ||
| }; | ||
| msg = escapeInnerText( 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>" + escapeInnerText( source ) + "</pre></td></tr></table>"; | ||
| } | ||
| } | ||
| runLoggingCallbacks( "log", QUnit, details ); | ||
| config.current.assertions.push({ | ||
| result: result, | ||
| message: msg | ||
| }); | ||
| }, | ||
| // Checks that the first two arguments are equal, with an optional message. Prints out both actual and expected values. | ||
| // @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes." ); | ||
| equal: function( actual, expected, message ) { | ||
| QUnit.push( expected == actual, actual, expected, message ); | ||
| }, | ||
| notEqual: function( actual, expected, message ) { | ||
| QUnit.push( expected != actual, actual, expected, message ); | ||
| }, | ||
| deepEqual: function( actual, expected, message ) { | ||
| QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); | ||
| }, | ||
| notDeepEqual: function( actual, expected, message ) { | ||
| QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); | ||
| }, | ||
| strictEqual: function( actual, expected, message ) { | ||
| QUnit.push( expected === actual, actual, expected, message ); | ||
| }, | ||
| notStrictEqual: function( actual, expected, message ) { | ||
| QUnit.push( expected !== actual, actual, expected, message ); | ||
| }, | ||
| raises: function( block, expected, message ) { | ||
| var actual, | ||
| ok = false; | ||
| if ( typeof expected === "string" ) { | ||
| message = expected; | ||
| expected = null; | ||
| } | ||
| try { | ||
| block.call( config.current.testEnvironment ); | ||
| } catch (e) { | ||
| actual = e; | ||
| } | ||
| if ( actual ) { | ||
| // we don't want to validate thrown error | ||
| if ( !expected ) { | ||
| ok = true; | ||
| // expected is a regexp | ||
| } else if ( QUnit.objectType( expected ) === "regexp" ) { | ||
| ok = expected.test( actual ); | ||
| // expected is a constructor | ||
| } else if ( actual instanceof expected ) { | ||
| ok = true; | ||
| // expected is a validation function which returns true is validation passed | ||
| } else if ( expected.call( {}, actual ) === true ) { | ||
| ok = true; | ||
| } | ||
| } | ||
| QUnit.ok( ok, message ); | ||
| }, | ||
| start: function( count ) { | ||
| 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; | ||
| } | ||
| // 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 ); | ||
| } | ||
| } | ||
| }; | ||
| // We want access to the constructor's prototype | ||
| (function() { | ||
| function F() {} | ||
| F.prototype = QUnit; | ||
| QUnit = new F(); | ||
| // Make F QUnit's constructor so that we can add to the prototype later | ||
| QUnit.constructor = F; | ||
| }()); | ||
| // deprecated; still export them to window to provide clear error messages | ||
| // next step: remove entirely | ||
| 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" ); | ||
| }; | ||
| // Maintain internal state | ||
| // `config` initialized at top of scope | ||
| config = { | ||
| // The queue of tests to run | ||
| queue: [], | ||
| // block until document ready | ||
| blocking: true, | ||
| // when enabled, show only failing tests | ||
| // gets persisted through sessionStorage and can be changed in UI via checkbox | ||
| hidepassed: false, | ||
| // by default, run previously failed tests first | ||
| // very useful in combination with "Hide passed tests" checked | ||
| reorder: true, | ||
| // by default, modify document.title when suite is done | ||
| altertitle: true, | ||
| urlConfig: [ "noglobals", "notrycatch" ], | ||
| // logging callback queues | ||
| begin: [], | ||
| done: [], | ||
| log: [], | ||
| testStart: [], | ||
| testDone: [], | ||
| moduleStart: [], | ||
| moduleDone: [] | ||
| }; | ||
| // Load paramaters | ||
| (function() { | ||
| var i, | ||
| location = window.location || { search: "", protocol: "file:" }, | ||
| params = location.search.slice( 1 ).split( "&" ), | ||
| length = params.length, | ||
| urlParams = {}, | ||
| current; | ||
| if ( params[ 0 ] ) { | ||
| for ( i = 0; i < length; i++ ) { | ||
| current = params[ i ].split( "=" ); | ||
| current[ 0 ] = decodeURIComponent( current[ 0 ] ); | ||
| // allow just a key to turn on a flag, e.g., test.html?noglobals | ||
| current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; | ||
| urlParams[ current[ 0 ] ] = current[ 1 ]; | ||
| } | ||
| } | ||
| QUnit.urlParams = urlParams; | ||
| config.filter = urlParams.filter; | ||
| // Figure out if we're running the tests from a server or not | ||
| 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 - export everything at the end | ||
| if ( typeof exports === "undefined" || typeof require === "undefined" ) { | ||
| extend( window, QUnit ); | ||
| window.QUnit = QUnit; | ||
| } | ||
| // define these after exposing globals to keep them in these QUnit namespace only | ||
| extend( QUnit, { | ||
| config: config, | ||
| // Initialize the configuration options | ||
| init: function() { | ||
| extend( config, { | ||
| stats: { all: 0, bad: 0 }, | ||
| moduleStats: { all: 0, bad: 0 }, | ||
| started: +new Date(), | ||
| updateRate: 1000, | ||
| blocking: false, | ||
| autostart: true, | ||
| autorun: false, | ||
| filter: "", | ||
| queue: [], | ||
| semaphore: 0 | ||
| }); | ||
| var tests, banner, result, | ||
| qunit = id( "qunit" ); | ||
| if ( qunit ) { | ||
| qunit.innerHTML = | ||
| "<h1 id='qunit-header'>" + escapeInnerText( 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 ) { | ||
| tests.innerHTML = ""; | ||
| } | ||
| if ( banner ) { | ||
| banner.className = ""; | ||
| } | ||
| if ( result ) { | ||
| result.parentNode.removeChild( result ); | ||
| } | ||
| if ( tests ) { | ||
| result = document.createElement( "p" ); | ||
| result.id = "qunit-testresult"; | ||
| result.className = "result"; | ||
| tests.parentNode.insertBefore( result, tests ); | ||
| 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. | ||
| reset: function() { | ||
| var fixture; | ||
| if ( window.jQuery ) { | ||
| jQuery( "#qunit-fixture" ).html( config.fixture ); | ||
| } else { | ||
| fixture = id( "qunit-fixture" ); | ||
| if ( fixture ) { | ||
| fixture.innerHTML = config.fixture; | ||
| } | ||
| } | ||
| }, | ||
| // Trigger an event on an element. | ||
| // @example triggerEvent( document.body, "click" ); | ||
| triggerEvent: function( elem, type, event ) { | ||
| if ( document.createEvent ) { | ||
| 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 ); | ||
| } | ||
| }, | ||
| // Safe object type checking | ||
| is: function( type, obj ) { | ||
| return QUnit.objectType( obj ) == type; | ||
| }, | ||
| objectType: function( obj ) { | ||
| if ( typeof obj === "undefined" ) { | ||
| return "undefined"; | ||
| // consider: typeof null === object | ||
| } | ||
| if ( obj === null ) { | ||
| return "null"; | ||
| } | ||
| var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || ""; | ||
| 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"; | ||
| } | ||
| return undefined; | ||
| }, | ||
| push: function( result, actual, expected, message ) { | ||
| if ( !config.current ) { | ||
| throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); | ||
| } | ||
| var output, source, | ||
| details = { | ||
| result: result, | ||
| message: message, | ||
| actual: actual, | ||
| expected: expected | ||
| }; | ||
| message = escapeInnerText( message ) || ( result ? "okay" : "failed" ); | ||
| message = "<span class='test-message'>" + message + "</span>"; | ||
| output = message; | ||
| if ( !result ) { | ||
| expected = escapeInnerText( QUnit.jsDump.parse(expected) ); | ||
| actual = escapeInnerText( 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 += "</table>"; | ||
| } | ||
| runLoggingCallbacks( "log", QUnit, details ); | ||
| config.current.assertions.push({ | ||
| result: !!result, | ||
| message: output | ||
| }); | ||
| }, | ||
| pushFailure: function( message, source ) { | ||
| var output, | ||
| details = { | ||
| result: false, | ||
| message: message | ||
| }; | ||
| message = escapeInnerText(message ) || "error"; | ||
| message = "<span class='test-message'>" + message + "</span>"; | ||
| output = message; | ||
| if ( source ) { | ||
| details.source = source; | ||
| output += "<table><tr class='test-source'><th>Source: </th><td><pre>" + escapeInnerText( source ) + "</pre></td></tr></table>"; | ||
| } | ||
| runLoggingCallbacks( "log", QUnit, details ); | ||
| config.current.assertions.push({ | ||
| result: false, | ||
| message: output | ||
| }); | ||
| }, | ||
| url: function( params ) { | ||
| params = extend( extend( {}, QUnit.urlParams ), params ); | ||
| 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 ); | ||
| }, | ||
| extend: extend, | ||
| id: id, | ||
| addEvent: addEvent | ||
| }); | ||
| // 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, { | ||
| // Logging callbacks; all receive a single argument with the listed properties | ||
| // run test/logs.html for any related changes | ||
| begin: registerLoggingCallback( "begin" ), | ||
| // done: { failed, passed, total, runtime } | ||
| done: registerLoggingCallback( "done" ), | ||
| // log: { result, actual, expected, message } | ||
| log: registerLoggingCallback( "log" ), | ||
| // testStart: { name } | ||
| testStart: registerLoggingCallback( "testStart" ), | ||
| // testDone: { name, failed, passed, total } | ||
| testDone: registerLoggingCallback( "testDone" ), | ||
| // moduleStart: { name } | ||
| moduleStart: registerLoggingCallback( "moduleStart" ), | ||
| // moduleDone: { name, failed, passed, total } | ||
| moduleDone: registerLoggingCallback( "moduleDone" ) | ||
| }); | ||
| if ( typeof document === "undefined" || document.readyState === "complete" ) { | ||
| config.autorun = true; | ||
| } | ||
| QUnit.load = function() { | ||
| runLoggingCallbacks( "begin", QUnit, {} ); | ||
| // Initialize the config, saving the execution queue | ||
| var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, | ||
| urlConfigHtml = "", | ||
| oldconfig = extend( {}, config ); | ||
| QUnit.init(); | ||
| extend(config, oldconfig); | ||
| config.blocking = false; | ||
| len = config.urlConfig.length; | ||
| for ( i = 0; i < len; i++ ) { | ||
| val = config.urlConfig[i]; | ||
| config[val] = QUnit.urlParams[val]; | ||
| urlConfigHtml += "<label><input name='" + val + "' type='checkbox'" + ( config[val] ? " checked='checked'" : "" ) + ">" + val + "</label>"; | ||
| } | ||
| // `userAgent` initialized at top of scope | ||
| userAgent = id( "qunit-userAgent" ); | ||
| if ( userAgent ) { | ||
| userAgent.innerHTML = navigator.userAgent; | ||
| } | ||
| // `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 ); | ||
| }); | ||
| } | ||
| // `toolbar` initialized at top of scope | ||
| toolbar = id( "qunit-testrunner-toolbar" ); | ||
| if ( toolbar ) { | ||
| // `filter` initialized at top of scope | ||
| filter = document.createElement( "input" ); | ||
| filter.type = "checkbox"; | ||
| filter.id = "qunit-filter-pass"; | ||
| addEvent( filter, "click", function() { | ||
| var tmp, | ||
| ol = document.getElementById( "qunit-tests" ); | ||
| if ( filter.checked ) { | ||
| ol.className = ol.className + " hidepass"; | ||
| } else { | ||
| 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" ); | ||
| } else { | ||
| sessionStorage.removeItem( "qunit-filter-passed-tests" ); | ||
| } | ||
| } | ||
| }); | ||
| if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { | ||
| filter.checked = true; | ||
| // `ol` initialized at top of scope | ||
| ol = document.getElementById( "qunit-tests" ); | ||
| ol.className = ol.className + " hidepass"; | ||
| } | ||
| toolbar.appendChild( filter ); | ||
| // `label` initialized at top of scope | ||
| label = document.createElement( "label" ); | ||
| label.setAttribute( "for", "qunit-filter-pass" ); | ||
| label.innerHTML = "Hide passed tests"; | ||
| toolbar.appendChild( label ); | ||
| } | ||
| // `main` initialized at top of scope | ||
| main = id( "qunit-fixture" ); | ||
| if ( main ) { | ||
| config.fixture = main.innerHTML; | ||
| } | ||
| if ( config.autostart ) { | ||
| QUnit.start(); | ||
| } | ||
| }; | ||
| addEvent( window, "load", QUnit.load ); | ||
| // addEvent(window, "error" ) gives us a useless event object | ||
| window.onerror = function( message, file, line ) { | ||
| if ( QUnit.config.current ) { | ||
| QUnit.pushFailure( message, file + ":" + line ); | ||
| } else { | ||
| QUnit.test( "global failure", function() { | ||
| QUnit.pushFailure( message, file + ":" + line ); | ||
| }); | ||
| } | ||
| }; | ||
| function done() { | ||
| config.autorun = true; | ||
| // Log the last module results | ||
| if ( config.currentModule ) { | ||
| runLoggingCallbacks( "moduleDone", QUnit, { | ||
| name: config.currentModule, | ||
| failed: config.moduleStats.bad, | ||
| passed: config.moduleStats.all - config.moduleStats.bad, | ||
| total: config.moduleStats.all | ||
| }); | ||
| } | ||
| 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 ", | ||
| runtime, | ||
| " milliseconds.<br/>", | ||
| "<span class='passed'>", | ||
| passed, | ||
| "</span> tests of <span class='total'>", | ||
| config.stats.all, | ||
| "</span> passed, <span class='failed'>", | ||
| config.stats.bad, | ||
| "</span> failed." | ||
| ].join( "" ); | ||
| if ( banner ) { | ||
| banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); | ||
| } | ||
| if ( tests ) { | ||
| id( "qunit-testresult" ).innerHTML = html; | ||
| } | ||
| if ( config.altertitle && typeof document !== "undefined" && document.title ) { | ||
| // show ✖ for good, ✔ for bad suite result in title | ||
| // use escape sequences in case file gets loaded with non-utf-8-charset | ||
| document.title = [ | ||
| ( config.stats.bad ? "\u2716" : "\u2714" ), | ||
| document.title.replace( /^[\u2714\u2716] /i, "" ) | ||
| ].join( " " ); | ||
| } | ||
| // 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 ); | ||
| } | ||
| } | ||
| } | ||
| runLoggingCallbacks( "done", QUnit, { | ||
| failed: config.stats.bad, | ||
| passed: passed, | ||
| total: config.stats.all, | ||
| runtime: runtime | ||
| }); | ||
| } | ||
| function validTest( name ) { | ||
| var not, | ||
| filter = config.filter, | ||
| run = false; | ||
| if ( !filter ) { | ||
| return true; | ||
| } | ||
| not = filter.charAt( 0 ) === "!"; | ||
| if ( not ) { | ||
| filter = filter.slice( 1 ); | ||
| } | ||
| if ( name.indexOf( filter ) !== -1 ) { | ||
| return !not; | ||
| } | ||
| if ( not ) { | ||
| run = true; | ||
| } | ||
| return run; | ||
| } | ||
| // 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 || 3; | ||
| var stack; | ||
| 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(); | ||
| } | ||
| 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; | ||
| } | ||
| } | ||
| function sourceFromStacktrace( offset ) { | ||
| try { | ||
| throw new Error(); | ||
| } catch ( e ) { | ||
| return extractStacktrace( e, offset ); | ||
| } | ||
| } | ||
| function escapeInnerText( s ) { | ||
| if ( !s ) { | ||
| return ""; | ||
| } | ||
| s = s + ""; | ||
| return s.replace( /[\&<>]/g, function( s ) { | ||
| switch( s ) { | ||
| case "&": return "&"; | ||
| case "<": return "<"; | ||
| case ">": return ">"; | ||
| default: return s; | ||
| } | ||
| }); | ||
| } | ||
| function synchronize( callback, last ) { | ||
| config.queue.push( callback ); | ||
| if ( config.autorun && !config.blocking ) { | ||
| process( last ); | ||
| } | ||
| } | ||
| 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 ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { | ||
| config.queue.shift()(); | ||
| } else { | ||
| window.setTimeout( next, 13 ); | ||
| break; | ||
| } | ||
| } | ||
| config.depth--; | ||
| if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { | ||
| done(); | ||
| } | ||
| } | ||
| function saveGlobal() { | ||
| config.pollution = []; | ||
| if ( config.noglobals ) { | ||
| for ( var key in window ) { | ||
| if ( !hasOwn.call( window, key ) ) { | ||
| continue; | ||
| } | ||
| config.pollution.push( key ); | ||
| } | ||
| } | ||
| } | ||
| function checkPollution( name ) { | ||
| var newGlobals, | ||
| deletedGlobals, | ||
| old = config.pollution; | ||
| saveGlobal(); | ||
| newGlobals = diff( config.pollution, old ); | ||
| if ( newGlobals.length > 0 ) { | ||
| QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); | ||
| } | ||
| deletedGlobals = diff( old, config.pollution ); | ||
| if ( deletedGlobals.length > 0 ) { | ||
| QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); | ||
| } | ||
| } | ||
| // returns a new Array with the elements that are in a but not in b | ||
| function diff( a, b ) { | ||
| var i, j, | ||
| result = a.slice(); | ||
| for ( i = 0; i < result.length; i++ ) { | ||
| for ( j = 0; j < b.length; j++ ) { | ||
| if ( result[i] === b[j] ) { | ||
| result.splice( i, 1 ); | ||
| i--; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function extend( a, b ) { | ||
| for ( var prop in b ) { | ||
| if ( b[ prop ] === undefined ) { | ||
| delete a[ prop ]; | ||
| // Avoid "Member not found" error in IE8 caused by setting window.constructor | ||
| } else if ( prop !== "constructor" || a !== window ) { | ||
| a[ prop ] = b[ prop ]; | ||
| } | ||
| } | ||
| return a; | ||
| } | ||
| function addEvent( elem, type, fn ) { | ||
| if ( elem.addEventListener ) { | ||
| elem.addEventListener( type, fn, false ); | ||
| } else if ( elem.attachEvent ) { | ||
| elem.attachEvent( "on" + type, fn ); | ||
| } else { | ||
| fn(); | ||
| } | ||
| } | ||
| function id( name ) { | ||
| return !!( typeof document !== "undefined" && document && document.getElementById ) && | ||
| document.getElementById( name ); | ||
| } | ||
| function registerLoggingCallback( key ) { | ||
| return function( callback ) { | ||
| config[key].push( callback ); | ||
| }; | ||
| } | ||
| // Supports deprecated method of completely overwriting logging callbacks | ||
| function runLoggingCallbacks( key, scope, args ) { | ||
| //debugger; | ||
| var i, callbacks; | ||
| if ( QUnit.hasOwnProperty( key ) ) { | ||
| QUnit[ key ].call(scope, args ); | ||
| } else { | ||
| callbacks = config[ key ]; | ||
| for ( i = 0; i < callbacks.length; i++ ) { | ||
| callbacks[ i ].call( scope, args ); | ||
| } | ||
| } | ||
| } | ||
| // Test for equality any JavaScript type. | ||
| // Author: Philippe Rathé <prathe@gmail.com> | ||
| QUnit.equiv = (function() { | ||
| // 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 ); | ||
| } else { | ||
| return callbacks[ prop ]; // or undefined | ||
| } | ||
| } | ||
| } | ||
| // the real equiv function | ||
| var innerEquiv, | ||
| // stack to decide between skip/abort functions | ||
| callers = [], | ||
| // stack to avoiding loops from circular referencing | ||
| parents = [], | ||
| getProto = Object.getPrototypeOf || function ( obj ) { | ||
| return obj.__proto__; | ||
| }, | ||
| callbacks = (function () { | ||
| // 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; | ||
| } | ||
| } | ||
| return { | ||
| "string": useStrictEquality, | ||
| "boolean": useStrictEquality, | ||
| "number": useStrictEquality, | ||
| "null": useStrictEquality, | ||
| "undefined": useStrictEquality, | ||
| "nan": function( b ) { | ||
| return isNaN( b ); | ||
| }, | ||
| "date": function( b, a ) { | ||
| return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); | ||
| }, | ||
| "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; | ||
| }, | ||
| // - 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, len, loop; | ||
| // 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; | ||
| } | ||
| // 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; | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
| } | ||
| // 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] ) { | ||
| // don't go down the same path twice | ||
| loop = true; | ||
| } | ||
| } | ||
| 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 | ||
| } | ||
| // Ensures identical properties name | ||
| return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); | ||
| } | ||
| }; | ||
| }()); | ||
| innerEquiv = function() { // can take multiple arguments | ||
| var args = [].slice.apply( arguments ); | ||
| if ( args.length < 2 ) { | ||
| return true; // end transition | ||
| } | ||
| 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) ) { | ||
| return false; // don't lose time with error prone cases | ||
| } else { | ||
| return bindCallbacks(a, callbacks, [ b, a ]); | ||
| } | ||
| // apply transition with (1..n) arguments | ||
| }( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) ); | ||
| }; | ||
| return innerEquiv; | ||
| }()); | ||
| /** | ||
| * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | | ||
| * http://flesler.blogspot.com Licensed under BSD | ||
| * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 | ||
| * | ||
| * @projectDescription Advanced and extensible data dumping for Javascript. | ||
| * @version 1.0.0 | ||
| * @author Ariel Flesler | ||
| * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} | ||
| */ | ||
| QUnit.jsDump = (function() { | ||
| function quote( str ) { | ||
| return '"' + str.toString().replace( /"/g, '\\"' ) + '"'; | ||
| } | ||
| function literal( o ) { | ||
| return o + ""; | ||
| } | ||
| function join( pre, arr, post ) { | ||
| var s = jsDump.separator(), | ||
| base = jsDump.indent(), | ||
| inner = jsDump.indent(1); | ||
| 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 = new Array(i); | ||
| this.up(); | ||
| while ( i-- ) { | ||
| ret[i] = this.parse( arr[i] , undefined , stack); | ||
| } | ||
| this.down(); | ||
| return join( "[", ret, "]" ); | ||
| } | ||
| var reName = /^function (\w+)/, | ||
| jsDump = { | ||
| parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance | ||
| stack = stack || [ ]; | ||
| var inStack, res, | ||
| parser = this.parsers[ type || this.typeOf(obj) ]; | ||
| type = typeof parser; | ||
| inStack = inArray( obj, stack ); | ||
| if ( inStack != -1 ) { | ||
| return "recursion(" + (inStack - stack.length) + ")"; | ||
| } | ||
| //else | ||
| if ( type == "function" ) { | ||
| stack.push( obj ); | ||
| res = parser.call( this, obj, stack ); | ||
| stack.pop(); | ||
| return res; | ||
| } | ||
| // else | ||
| return ( type == "string" ) ? parser : this.parsers.error; | ||
| }, | ||
| typeOf: function( obj ) { | ||
| var type; | ||
| if ( obj === null ) { | ||
| type = "null"; | ||
| } else if ( typeof obj === "undefined" ) { | ||
| type = "undefined"; | ||
| } else if ( QUnit.is( "RegExp", obj) ) { | ||
| type = "regexp"; | ||
| } else if ( QUnit.is( "Date", obj) ) { | ||
| type = "date"; | ||
| } else if ( QUnit.is( "Function", obj) ) { | ||
| type = "function"; | ||
| } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { | ||
| type = "window"; | ||
| } else if ( obj.nodeType === 9 ) { | ||
| type = "document"; | ||
| } else if ( obj.nodeType ) { | ||
| type = "node"; | ||
| } else if ( | ||
| // native arrays | ||
| toString.call( obj ) === "[object Array]" || | ||
| // NodeList objects | ||
| ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) | ||
| ) { | ||
| type = "array"; | ||
| } else { | ||
| type = typeof obj; | ||
| } | ||
| return type; | ||
| }, | ||
| separator: function() { | ||
| return this.multiline ? this.HTML ? "<br />" : "\n" : this.HTML ? " " : " "; | ||
| }, | ||
| 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 new Array( this._depth_ + (extra||0) ).join(chr); | ||
| }, | ||
| up: function( a ) { | ||
| this._depth_ += a || 1; | ||
| }, | ||
| down: function( a ) { | ||
| this._depth_ -= a || 1; | ||
| }, | ||
| setParser: function( name, parser ) { | ||
| this.parsers[name] = parser; | ||
| }, | ||
| // The next 3 are exposed so you can use them | ||
| quote: quote, | ||
| literal: literal, | ||
| join: join, | ||
| // | ||
| _depth_: 1, | ||
| // This is the list of parsers, to modify them, use jsDump.setParser | ||
| parsers: { | ||
| window: "[Window]", | ||
| document: "[Document]", | ||
| error: "[ERROR]", //when no parser is found, shouldn"t happen | ||
| unknown: "[Unknown]", | ||
| "null": "null", | ||
| "undefined": "undefined", | ||
| "function": function( fn ) { | ||
| var ret = "function", | ||
| name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE | ||
| if ( name ) { | ||
| ret += " " + name; | ||
| } | ||
| ret += "( "; | ||
| ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); | ||
| return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); | ||
| }, | ||
| array: array, | ||
| nodelist: array, | ||
| "arguments": array, | ||
| object: function( map, stack ) { | ||
| var ret = [ ], keys, key, val, i; | ||
| QUnit.jsDump.up(); | ||
| if ( Object.keys ) { | ||
| keys = Object.keys( map ); | ||
| } else { | ||
| keys = []; | ||
| for ( key in map ) { | ||
| keys.push( key ); | ||
| } | ||
| } | ||
| keys.sort(); | ||
| for ( i = 0; i < keys.length; i++ ) { | ||
| key = keys[ i ]; | ||
| val = map[ key ]; | ||
| ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); | ||
| } | ||
| QUnit.jsDump.down(); | ||
| return join( "{", ret, "}" ); | ||
| }, | ||
| node: function( node ) { | ||
| var a, val, | ||
| open = QUnit.jsDump.HTML ? "<" : "<", | ||
| close = QUnit.jsDump.HTML ? ">" : ">", | ||
| tag = node.nodeName.toLowerCase(), | ||
| ret = open + tag; | ||
| for ( a in QUnit.jsDump.DOMAttrs ) { | ||
| val = node[ QUnit.jsDump.DOMAttrs[a] ]; | ||
| if ( val ) { | ||
| ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" ); | ||
| } | ||
| } | ||
| return ret + close + open + "/" + tag + close; | ||
| }, | ||
| functionArgs: function( fn ) {//function calls it internally, it's the arguments part of the function | ||
| var args, | ||
| l = fn.length; | ||
| if ( !l ) { | ||
| return ""; | ||
| } | ||
| args = new Array(l); | ||
| while ( l-- ) { | ||
| args[l] = String.fromCharCode(97+l);//97 is 'a' | ||
| } | ||
| return " " + args.join( ", " ) + " "; | ||
| }, | ||
| key: quote, //object calls it internally, the key part of an item in a map | ||
| functionCode: "[code]", //function calls it internally, it's the content of the function | ||
| attribute: quote, //node calls it internally, it's an html attribute value | ||
| string: quote, | ||
| date: quote, | ||
| regexp: literal, //regex | ||
| number: literal, | ||
| "boolean": literal | ||
| }, | ||
| DOMAttrs: { | ||
| //attributes to dump from nodes, name=>realName | ||
| id: "id", | ||
| name: "name", | ||
| "class": "className" | ||
| }, | ||
| HTML: false,//if true, entities are escaped ( <, >, \t, space and \n ) | ||
| indentChar: " ",//indentation unit | ||
| multiline: true //if true, items in a collection, are separated by a \n, else just a space. | ||
| }; | ||
| return jsDump; | ||
| }()); | ||
| // from Sizzle.js | ||
| function getText( elems ) { | ||
| var i, elem, | ||
| ret = ""; | ||
| for ( i = 0; elems[i]; i++ ) { | ||
| elem = elems[i]; | ||
| // Get the text from text nodes and CDATA nodes | ||
| if ( elem.nodeType === 3 || elem.nodeType === 4 ) { | ||
| ret += elem.nodeValue; | ||
| // Traverse everything else, except comment nodes | ||
| } else if ( elem.nodeType !== 8 ) { | ||
| ret += getText( elem.childNodes ); | ||
| } | ||
| } | ||
| return ret; | ||
| } | ||
| // from jquery.js | ||
| function inArray( elem, array ) { | ||
| if ( array.indexOf ) { | ||
| return array.indexOf( elem ); | ||
| } | ||
| for ( var i = 0, length = array.length; i < length; i++ ) { | ||
| if ( array[ i ] === elem ) { | ||
| return i; | ||
| } | ||
| } | ||
| return -1; | ||
| } | ||
| /* | ||
| * Javascript Diff Algorithm | ||
| * By John Resig (http://ejohn.org/) | ||
| * Modified by Chu Alan "sprite" | ||
| * | ||
| * Released under the MIT license. | ||
| * | ||
| * More Info: | ||
| * http://ejohn.org/projects/javascript-diff-algorithm/ | ||
| * | ||
| * Usage: QUnit.diff(expected, actual) | ||
| * | ||
| * 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 i, | ||
| ns = {}, | ||
| os = {}; | ||
| for ( i = 0; i < n.length; i++ ) { | ||
| if ( ns[ n[i] ] == null ) { | ||
| ns[ n[i] ] = { | ||
| rows: [], | ||
| o: null | ||
| }; | ||
| } | ||
| ns[ n[i] ].rows.push( i ); | ||
| } | ||
| for ( i = 0; i < o.length; i++ ) { | ||
| if ( os[ o[i] ] == null ) { | ||
| os[ o[i] ] = { | ||
| rows: [], | ||
| n: null | ||
| }; | ||
| } | ||
| os[ o[i] ].rows.push( i ); | ||
| } | ||
| for ( i in ns ) { | ||
| if ( !hasOwn.call( ns, i ) ) { | ||
| continue; | ||
| } | ||
| 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] ], | ||
| row: os[i].rows[0] | ||
| }; | ||
| o[ os[i].rows[0] ] = { | ||
| text: o[ os[i].rows[0] ], | ||
| row: ns[i].rows[0] | ||
| }; | ||
| } | ||
| } | ||
| 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 ], | ||
| row: 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 ], | ||
| row: i - 1 | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| o: o, | ||
| n: n | ||
| }; | ||
| } | ||
| return function( o, n ) { | ||
| o = o.replace( /\s+$/, "" ); | ||
| n = n.replace( /\s+$/, "" ); | ||
| var i, pre, | ||
| str = "", | ||
| out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), | ||
| oSpace = o.match(/\s+/g), | ||
| nSpace = n.match(/\s+/g); | ||
| if ( oSpace == null ) { | ||
| oSpace = [ " " ]; | ||
| } | ||
| else { | ||
| oSpace.push( " " ); | ||
| } | ||
| if ( nSpace == null ) { | ||
| nSpace = [ " " ]; | ||
| } | ||
| else { | ||
| nSpace.push( " " ); | ||
| } | ||
| 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>"; | ||
| } | ||
| } | ||
| for ( i = 0; i < out.n.length; i++ ) { | ||
| if (out.n[i].text == null) { | ||
| str += "<ins>" + out.n[i] + nSpace[i] + "</ins>"; | ||
| } | ||
| else { | ||
| // `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>"; | ||
| } | ||
| str += " " + out.n[i].text + nSpace[i] + pre; | ||
| } | ||
| } | ||
| } | ||
| return str; | ||
| }; | ||
| }()); | ||
| // for CommonJS enviroments, export everything | ||
| if ( typeof exports !== "undefined" || typeof require !== "undefined" ) { | ||
| extend(exports, QUnit); | ||
| } | ||
| // get at whatever the global object is, like window in browsers | ||
| }( (function() {return this;}.call()) )); |
| [QUnit](http://docs.jquery.com/QUnit) - A JavaScript Unit Testing framework. | ||
| ================================ | ||
| QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery | ||
| project to test its code and plugins but is capable of testing any generic | ||
| JavaScript code (and even capable of testing JavaScript code on the server-side). | ||
| QUnit is especially useful for regression testing: Whenever a bug is reported, | ||
| write a test that asserts the existence of that particular bug. Then fix it and | ||
| commit both. Every time you work on the code again, run the tests. If the bug | ||
| comes up again - a regression - you'll spot it immediately and know how to fix | ||
| it, because you know what code you just changed. | ||
| Having good unit test coverage makes safe refactoring easy and cheap. You can | ||
| run the tests after each small refactoring step and always know what change | ||
| broke something. | ||
| QUnit is similar to other unit testing frameworks like JUnit, but makes use of | ||
| the features JavaScript provides and helps with testing code in the browser, e.g. | ||
| with its stop/start facilities for testing asynchronous code. | ||
| If you are interested in helping developing QUnit, you are in the right place. | ||
| For related discussions, visit the | ||
| [QUnit and Testing forum](http://forum.jquery.com/qunit-and-testing). | ||
| Planning for a qunitjs.com site and other testing tools related work now happens | ||
| on the [jQuery Testing Team planning wiki](http://jquerytesting.pbworks.com/w/page/41556026/FrontPage). | ||
| Development | ||
| ----------- | ||
| To submit patches, fork the repository, create a branch for the change. Then implement | ||
| the change, run `grunt` to lint and test it, then commit, push and create a pull request. | ||
| Include some background for the change in the commit message and `Fixes #nnn`, referring | ||
| to the issue number you're addressing. | ||
| To run `grunt`, you need `node` and `npm`, then `npm install grunt -g`. | ||
| Releases | ||
| -------- | ||
| Install git-extras and run `git changelog` to update History.md. | ||
| Update qunit/qunit.js|css to the release version, commit and tag, update them | ||
| again to the next version, commit and push commits and tags. | ||
| Put the 'v' in front of the tag (unlike the 1.1.0 release). Clean up the changelog, | ||
| removing merge commits or whitespace cleanups. |
| module("equiv"); | ||
| test("Primitive types and constants", function () { | ||
| equal(QUnit.equiv(null, null), true, "null"); | ||
| equal(QUnit.equiv(null, {}), false, "null"); | ||
| equal(QUnit.equiv(null, undefined), false, "null"); | ||
| equal(QUnit.equiv(null, 0), false, "null"); | ||
| equal(QUnit.equiv(null, false), false, "null"); | ||
| equal(QUnit.equiv(null, ''), false, "null"); | ||
| equal(QUnit.equiv(null, []), false, "null"); | ||
| equal(QUnit.equiv(undefined, undefined), true, "undefined"); | ||
| equal(QUnit.equiv(undefined, null), false, "undefined"); | ||
| equal(QUnit.equiv(undefined, 0), false, "undefined"); | ||
| equal(QUnit.equiv(undefined, false), false, "undefined"); | ||
| equal(QUnit.equiv(undefined, {}), false, "undefined"); | ||
| equal(QUnit.equiv(undefined, []), false, "undefined"); | ||
| equal(QUnit.equiv(undefined, ""), false, "undefined"); | ||
| // Nan usually doest not equal to Nan using the '==' operator. | ||
| // Only isNaN() is able to do it. | ||
| equal(QUnit.equiv(0/0, 0/0), true, "NaN"); // NaN VS NaN | ||
| equal(QUnit.equiv(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity | ||
| equal(QUnit.equiv(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity | ||
| equal(QUnit.equiv(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity | ||
| equal(QUnit.equiv(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity | ||
| equal(QUnit.equiv(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity | ||
| equal(QUnit.equiv(0/0, null), false, "NaN"); | ||
| equal(QUnit.equiv(0/0, undefined), false, "NaN"); | ||
| equal(QUnit.equiv(0/0, 0), false, "NaN"); | ||
| equal(QUnit.equiv(0/0, false), false, "NaN"); | ||
| equal(QUnit.equiv(0/0, function () {}), false, "NaN"); | ||
| equal(QUnit.equiv(1/0, null), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(1/0, undefined), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(1/0, 0), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(1/0, 1), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(1/0, false), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(1/0, true), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(1/0, function () {}), false, "NaN, Infinity"); | ||
| equal(QUnit.equiv(0, 0), true, "number"); | ||
| equal(QUnit.equiv(0, 1), false, "number"); | ||
| equal(QUnit.equiv(1, 0), false, "number"); | ||
| equal(QUnit.equiv(1, 1), true, "number"); | ||
| equal(QUnit.equiv(1.1, 1.1), true, "number"); | ||
| equal(QUnit.equiv(0.0000005, 0.0000005), true, "number"); | ||
| equal(QUnit.equiv(0, ''), false, "number"); | ||
| equal(QUnit.equiv(0, '0'), false, "number"); | ||
| equal(QUnit.equiv(1, '1'), false, "number"); | ||
| equal(QUnit.equiv(0, false), false, "number"); | ||
| equal(QUnit.equiv(1, true), false, "number"); | ||
| equal(QUnit.equiv(true, true), true, "boolean"); | ||
| equal(QUnit.equiv(true, false), false, "boolean"); | ||
| equal(QUnit.equiv(false, true), false, "boolean"); | ||
| equal(QUnit.equiv(false, 0), false, "boolean"); | ||
| equal(QUnit.equiv(false, null), false, "boolean"); | ||
| equal(QUnit.equiv(false, undefined), false, "boolean"); | ||
| equal(QUnit.equiv(true, 1), false, "boolean"); | ||
| equal(QUnit.equiv(true, null), false, "boolean"); | ||
| equal(QUnit.equiv(true, undefined), false, "boolean"); | ||
| equal(QUnit.equiv('', ''), true, "string"); | ||
| equal(QUnit.equiv('a', 'a'), true, "string"); | ||
| equal(QUnit.equiv("foobar", "foobar"), true, "string"); | ||
| equal(QUnit.equiv("foobar", "foo"), false, "string"); | ||
| equal(QUnit.equiv('', 0), false, "string"); | ||
| equal(QUnit.equiv('', false), false, "string"); | ||
| equal(QUnit.equiv('', null), false, "string"); | ||
| equal(QUnit.equiv('', undefined), false, "string"); | ||
| // Short annotation VS new annotation | ||
| equal(QUnit.equiv(0, new Number()), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Number(), 0), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(1, new Number(1)), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Number(1), 1), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Number(0), 1), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(0, new Number(1)), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new String(), ""), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv("", new String()), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new String("My String"), "My String"), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv("My String", new String("My String")), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv("Bad String", new String("My String")), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new String("Bad String"), "My String"), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(false, new Boolean()), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Boolean(), false), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(true, new Boolean(true)), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Boolean(true), true), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(true, new Boolean(1)), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(false, new Boolean(false)), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Boolean(false), false), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(false, new Boolean(0)), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(true, new Boolean(false)), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Boolean(false), true), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Object(), {}), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv({}, new Object()), true, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Object(), {a:1}), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv({a:1}, new Object()), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv({a:undefined}, new Object()), false, "short annotation VS new annotation"); | ||
| equal(QUnit.equiv(new Object(), {a:undefined}), false, "short annotation VS new annotation"); | ||
| }); | ||
| test("Objects Basics.", function() { | ||
| equal(QUnit.equiv({}, {}), true); | ||
| equal(QUnit.equiv({}, null), false); | ||
| equal(QUnit.equiv({}, undefined), false); | ||
| equal(QUnit.equiv({}, 0), false); | ||
| equal(QUnit.equiv({}, false), false); | ||
| // This test is a hard one, it is very important | ||
| // REASONS: | ||
| // 1) They are of the same type "object" | ||
| // 2) [] instanceof Object is true | ||
| // 3) Their properties are the same (doesn't exists) | ||
| equal(QUnit.equiv({}, []), false); | ||
| equal(QUnit.equiv({a:1}, {a:1}), true); | ||
| equal(QUnit.equiv({a:1}, {a:"1"}), false); | ||
| equal(QUnit.equiv({a:[]}, {a:[]}), true); | ||
| equal(QUnit.equiv({a:{}}, {a:null}), false); | ||
| equal(QUnit.equiv({a:1}, {}), false); | ||
| equal(QUnit.equiv({}, {a:1}), false); | ||
| // Hard ones | ||
| equal(QUnit.equiv({a:undefined}, {}), false); | ||
| equal(QUnit.equiv({}, {a:undefined}), false); | ||
| equal(QUnit.equiv( | ||
| { | ||
| a: [{ bar: undefined }] | ||
| }, | ||
| { | ||
| a: [{ bat: undefined }] | ||
| } | ||
| ), false); | ||
| // Objects with no prototype, created via Object.create(null), are used e.g. as dictionaries. | ||
| // Being able to test equivalence against object literals is quite useful. | ||
| if (typeof Object.create === 'function') { | ||
| equal(QUnit.equiv(Object.create(null), {}), true, "empty object without prototype VS empty object"); | ||
| var nonEmptyWithNoProto = Object.create(null); | ||
| nonEmptyWithNoProto.foo = "bar"; | ||
| equal(QUnit.equiv(nonEmptyWithNoProto, { foo: "bar" }), true, "object without prototype VS object"); | ||
| } | ||
| }); | ||
| test("Arrays Basics.", function() { | ||
| equal(QUnit.equiv([], []), true); | ||
| // May be a hard one, can invoke a crash at execution. | ||
| // because their types are both "object" but null isn't | ||
| // like a true object, it doesn't have any property at all. | ||
| equal(QUnit.equiv([], null), false); | ||
| equal(QUnit.equiv([], undefined), false); | ||
| equal(QUnit.equiv([], false), false); | ||
| equal(QUnit.equiv([], 0), false); | ||
| equal(QUnit.equiv([], ""), false); | ||
| // May be a hard one, but less hard | ||
| // than {} with [] (note the order) | ||
| equal(QUnit.equiv([], {}), false); | ||
| equal(QUnit.equiv([null],[]), false); | ||
| equal(QUnit.equiv([undefined],[]), false); | ||
| equal(QUnit.equiv([],[null]), false); | ||
| equal(QUnit.equiv([],[undefined]), false); | ||
| equal(QUnit.equiv([null],[undefined]), false); | ||
| equal(QUnit.equiv([[]],[[]]), true); | ||
| equal(QUnit.equiv([[],[],[]],[[],[],[]]), true); | ||
| equal(QUnit.equiv( | ||
| [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], | ||
| [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), | ||
| true); | ||
| equal(QUnit.equiv( | ||
| [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], | ||
| [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter | ||
| false); | ||
| equal(QUnit.equiv( | ||
| [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], | ||
| [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array | ||
| false); | ||
| // same multidimensional | ||
| equal(QUnit.equiv( | ||
| [1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,[ | ||
| [6,7,8,9, [ | ||
| [ | ||
| 1,2,3,4,[ | ||
| 2,3,4,[ | ||
| 1,2,[ | ||
| 1,2,3,4,[ | ||
| 1,2,3,4,5,6,7,8,9,[ | ||
| 0 | ||
| ],1,2,3,4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],5,6,7 | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ]]], | ||
| [1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,[ | ||
| [6,7,8,9, [ | ||
| [ | ||
| 1,2,3,4,[ | ||
| 2,3,4,[ | ||
| 1,2,[ | ||
| 1,2,3,4,[ | ||
| 1,2,3,4,5,6,7,8,9,[ | ||
| 0 | ||
| ],1,2,3,4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],5,6,7 | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ]]]), | ||
| true, "Multidimensional"); | ||
| // different multidimensional | ||
| equal(QUnit.equiv( | ||
| [1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,[ | ||
| [6,7,8,9, [ | ||
| [ | ||
| 1,2,3,4,[ | ||
| 2,3,4,[ | ||
| 1,2,[ | ||
| 1,2,3,4,[ | ||
| 1,2,3,4,5,6,7,8,9,[ | ||
| 0 | ||
| ],1,2,3,4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],5,6,7 | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ]]], | ||
| [1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,[ | ||
| [6,7,8,9, [ | ||
| [ | ||
| 1,2,3,4,[ | ||
| 2,3,4,[ | ||
| 1,2,[ | ||
| '1',2,3,4,[ // string instead of number | ||
| 1,2,3,4,5,6,7,8,9,[ | ||
| 0 | ||
| ],1,2,3,4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],5,6,7 | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ]]]), | ||
| false, "Multidimensional"); | ||
| // different multidimensional | ||
| equal(QUnit.equiv( | ||
| [1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,[ | ||
| [6,7,8,9, [ | ||
| [ | ||
| 1,2,3,4,[ | ||
| 2,3,4,[ | ||
| 1,2,[ | ||
| 1,2,3,4,[ | ||
| 1,2,3,4,5,6,7,8,9,[ | ||
| 0 | ||
| ],1,2,3,4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],5,6,7 | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ]]], | ||
| [1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,6,7,8,9, [ | ||
| 1,2,3,4,5,[ | ||
| [6,7,8,9, [ | ||
| [ | ||
| 1,2,3,4,[ | ||
| 2,3,[ // missing an element (4) | ||
| 1,2,[ | ||
| 1,2,3,4,[ | ||
| 1,2,3,4,5,6,7,8,9,[ | ||
| 0 | ||
| ],1,2,3,4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],4,5,6,7,8,9 | ||
| ],5,6,7,8,9 | ||
| ],5,6,7 | ||
| ] | ||
| ] | ||
| ] | ||
| ] | ||
| ]]]), | ||
| false, "Multidimensional"); | ||
| }); | ||
| test("Functions.", function() { | ||
| var f0 = function () {}; | ||
| var f1 = function () {}; | ||
| // f2 and f3 have the same code, formatted differently | ||
| var f2 = function () {var i = 0;}; | ||
| var f3 = function () { | ||
| var i = 0 // this comment and no semicoma as difference | ||
| }; | ||
| equal(QUnit.equiv(function() {}, function() {}), false, "Anonymous functions"); // exact source code | ||
| equal(QUnit.equiv(function() {}, function() {return true;}), false, "Anonymous functions"); | ||
| equal(QUnit.equiv(f0, f0), true, "Function references"); // same references | ||
| equal(QUnit.equiv(f0, f1), false, "Function references"); // exact source code, different references | ||
| equal(QUnit.equiv(f2, f3), false, "Function references"); // equivalent source code, different references | ||
| equal(QUnit.equiv(f1, f2), false, "Function references"); // different source code, different references | ||
| equal(QUnit.equiv(function() {}, true), false); | ||
| equal(QUnit.equiv(function() {}, undefined), false); | ||
| equal(QUnit.equiv(function() {}, null), false); | ||
| equal(QUnit.equiv(function() {}, {}), false); | ||
| }); | ||
| test("Date instances.", function() { | ||
| // Date, we don't need to test Date.parse() because it returns a number. | ||
| // Only test the Date instances by setting them a fix date. | ||
| // The date use is midnight January 1, 1970 | ||
| var d1 = new Date(); | ||
| d1.setTime(0); // fix the date | ||
| var d2 = new Date(); | ||
| d2.setTime(0); // fix the date | ||
| var d3 = new Date(); // The very now | ||
| // Anyway their types differs, just in case the code fails in the order in which it deals with date | ||
| equal(QUnit.equiv(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different | ||
| // test same values date and different instances equality | ||
| equal(QUnit.equiv(d1, d2), true); | ||
| // test different date and different instances difference | ||
| equal(QUnit.equiv(d1, d3), false); | ||
| }); | ||
| test("RegExp.", function() { | ||
| // Must test cases that imply those traps: | ||
| // var a = /./; | ||
| // a instanceof Object; // Oops | ||
| // a instanceof RegExp; // Oops | ||
| // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object") | ||
| // Tests same regex with same modifiers in different order | ||
| var r = /foo/; | ||
| var r5 = /foo/gim; | ||
| var r6 = /foo/gmi; | ||
| var r7 = /foo/igm; | ||
| var r8 = /foo/img; | ||
| var r9 = /foo/mig; | ||
| var r10 = /foo/mgi; | ||
| var ri1 = /foo/i; | ||
| var ri2 = /foo/i; | ||
| var rm1 = /foo/m; | ||
| var rm2 = /foo/m; | ||
| var rg1 = /foo/g; | ||
| var rg2 = /foo/g; | ||
| equal(QUnit.equiv(r5, r6), true, "Modifier order"); | ||
| equal(QUnit.equiv(r5, r7), true, "Modifier order"); | ||
| equal(QUnit.equiv(r5, r8), true, "Modifier order"); | ||
| equal(QUnit.equiv(r5, r9), true, "Modifier order"); | ||
| equal(QUnit.equiv(r5, r10), true, "Modifier order"); | ||
| equal(QUnit.equiv(r, r5), false, "Modifier"); | ||
| equal(QUnit.equiv(ri1, ri2), true, "Modifier"); | ||
| equal(QUnit.equiv(r, ri1), false, "Modifier"); | ||
| equal(QUnit.equiv(ri1, rm1), false, "Modifier"); | ||
| equal(QUnit.equiv(r, rm1), false, "Modifier"); | ||
| equal(QUnit.equiv(rm1, ri1), false, "Modifier"); | ||
| equal(QUnit.equiv(rm1, rm2), true, "Modifier"); | ||
| equal(QUnit.equiv(rg1, rm1), false, "Modifier"); | ||
| equal(QUnit.equiv(rm1, rg1), false, "Modifier"); | ||
| equal(QUnit.equiv(rg1, rg2), true, "Modifier"); | ||
| // Different regex, same modifiers | ||
| var r11 = /[a-z]/gi; | ||
| var r13 = /[0-9]/gi; // oops! different | ||
| equal(QUnit.equiv(r11, r13), false, "Regex pattern"); | ||
| var r14 = /0/ig; | ||
| var r15 = /"0"/ig; // oops! different | ||
| equal(QUnit.equiv(r14, r15), false, "Regex pattern"); | ||
| var r1 = /[\n\r\u2028\u2029]/g; | ||
| var r2 = /[\n\r\u2028\u2029]/g; | ||
| var r3 = /[\n\r\u2028\u2028]/g; // differs from r1 | ||
| var r4 = /[\n\r\u2028\u2029]/; // differs from r1 | ||
| equal(QUnit.equiv(r1, r2), true, "Regex pattern"); | ||
| equal(QUnit.equiv(r1, r3), false, "Regex pattern"); | ||
| equal(QUnit.equiv(r1, r4), false, "Regex pattern"); | ||
| // More complex regex | ||
| var regex1 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; | ||
| var regex2 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; | ||
| // regex 3 is different: '.' not escaped | ||
| var regex3 = "^[-_.a-z0-9]+@([-_a-z0-9]+.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; | ||
| var r21 = new RegExp(regex1); | ||
| var r22 = new RegExp(regex2); | ||
| var r23 = new RegExp(regex3); // diff from r21, not same pattern | ||
| var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier | ||
| var r24a = new RegExp(regex3, "ig"); // same as r23a | ||
| equal(QUnit.equiv(r21, r22), true, "Complex Regex"); | ||
| equal(QUnit.equiv(r21, r23), false, "Complex Regex"); | ||
| equal(QUnit.equiv(r23, r23a), false, "Complex Regex"); | ||
| equal(QUnit.equiv(r23a, r24a), true, "Complex Regex"); | ||
| // typeof r1 is "function" in some browsers and "object" in others so we must cover this test | ||
| var re = / /; | ||
| equal(QUnit.equiv(re, function () {}), false, "Regex internal"); | ||
| equal(QUnit.equiv(re, {}), false, "Regex internal"); | ||
| }); | ||
| test("Complex Objects.", function() { | ||
| function fn1() { | ||
| return "fn1"; | ||
| } | ||
| function fn2() { | ||
| return "fn2"; | ||
| } | ||
| // Try to invert the order of some properties to make sure it is covered. | ||
| // It can failed when properties are compared between unsorted arrays. | ||
| equal(QUnit.equiv( | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| s: [1,2,3], | ||
| t: undefined, | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| q: [], | ||
| p: 1/0, | ||
| o: 99 | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| d: 0, | ||
| i: true, | ||
| h: "false" | ||
| } | ||
| }, | ||
| e: undefined, | ||
| g: "", | ||
| h: "h", | ||
| f: {}, | ||
| i: [] | ||
| }, | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| b: false, | ||
| a: 3.14159, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| t: undefined, | ||
| u: 0, | ||
| s: [1,2,3], | ||
| v: { | ||
| w: { | ||
| x: { | ||
| z: null, | ||
| y: "Yahoo!" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| i: true, | ||
| h: "false" | ||
| } | ||
| }, | ||
| e: undefined, | ||
| g: "", | ||
| f: {}, | ||
| h: "h", | ||
| i: [] | ||
| } | ||
| ), true); | ||
| equal(QUnit.equiv( | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| //r: "r", // different: missing a property | ||
| s: [1,2,3], | ||
| t: undefined, | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| h: "false", | ||
| i: true | ||
| } | ||
| }, | ||
| e: undefined, | ||
| f: {}, | ||
| g: "", | ||
| h: "h", | ||
| i: [] | ||
| }, | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| s: [1,2,3], | ||
| t: undefined, | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| h: "false", | ||
| i: true | ||
| } | ||
| }, | ||
| e: undefined, | ||
| f: {}, | ||
| g: "", | ||
| h: "h", | ||
| i: [] | ||
| } | ||
| ), false); | ||
| equal(QUnit.equiv( | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| s: [1,2,3], | ||
| t: undefined, | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| h: "false", | ||
| i: true | ||
| } | ||
| }, | ||
| e: undefined, | ||
| f: {}, | ||
| g: "", | ||
| h: "h", | ||
| i: [] | ||
| }, | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| s: [1,2,3], | ||
| //t: undefined, // different: missing a property with an undefined value | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| h: "false", | ||
| i: true | ||
| } | ||
| }, | ||
| e: undefined, | ||
| f: {}, | ||
| g: "", | ||
| h: "h", | ||
| i: [] | ||
| } | ||
| ), false); | ||
| equal(QUnit.equiv( | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| s: [1,2,3], | ||
| t: undefined, | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| h: "false", | ||
| i: true | ||
| } | ||
| }, | ||
| e: undefined, | ||
| f: {}, | ||
| g: "", | ||
| h: "h", | ||
| i: [] | ||
| }, | ||
| { | ||
| a: 1, | ||
| b: null, | ||
| c: [{}], | ||
| d: { | ||
| a: 3.14159, | ||
| b: false, | ||
| c: { | ||
| d: 0, | ||
| e: fn1, | ||
| f: [[[]]], | ||
| g: { | ||
| j: { | ||
| k: { | ||
| n: { | ||
| r: "r", | ||
| s: [1,2,3], | ||
| t: undefined, | ||
| u: 0, | ||
| v: { | ||
| w: { | ||
| x: { | ||
| y: "Yahoo!", | ||
| z: null | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| o: 99, | ||
| p: 1/0, | ||
| q: {} // different was [] | ||
| }, | ||
| l: undefined, | ||
| m: null | ||
| } | ||
| }, | ||
| h: "false", | ||
| i: true | ||
| } | ||
| }, | ||
| e: undefined, | ||
| f: {}, | ||
| g: "", | ||
| h: "h", | ||
| i: [] | ||
| } | ||
| ), false); | ||
| var same1 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,null,{}, [], [1,2,3]], | ||
| bar: undefined | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ ας" | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| var same2 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,null,{}, [], [1,2,3]], | ||
| bar: undefined | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ ας" | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| var diff1 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array | ||
| bar: undefined | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ ας" | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| var diff2 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,null,{}, [], [1,2,3]], | ||
| newprop: undefined, // different: newprop was added | ||
| bar: undefined | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ ας" | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| var diff3 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,null,{}, [], [1,2,3]], | ||
| bar: undefined | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ α" // different: missing last char | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| var diff4 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null | ||
| bar: undefined | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ ας" | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| var diff5 = { | ||
| a: [ | ||
| "string", null, 0, "1", 1, { | ||
| prop: null, | ||
| foo: [1,2,null,{}, [], [1,2,3]], | ||
| bat: undefined // different: property name not "bar" | ||
| }, 3, "Hey!", "Κάνε πάντα γνω�ίζουμε ας των, μηχανής επιδιό�θωσης επιδιο�θώσεις ώς μια. Κλπ ας" | ||
| ], | ||
| unicode: "è€� 汉è¯ä¸å˜åœ¨ 港澳和海外的å�Žäººåœˆä¸ 贵州 我去了书店 现在尚有争", | ||
| b: "b", | ||
| c: fn1 | ||
| }; | ||
| equal(QUnit.equiv(same1, same2), true); | ||
| equal(QUnit.equiv(same2, same1), true); | ||
| equal(QUnit.equiv(same2, diff1), false); | ||
| equal(QUnit.equiv(diff1, same2), false); | ||
| equal(QUnit.equiv(same1, diff1), false); | ||
| equal(QUnit.equiv(same1, diff2), false); | ||
| equal(QUnit.equiv(same1, diff3), false); | ||
| equal(QUnit.equiv(same1, diff3), false); | ||
| equal(QUnit.equiv(same1, diff4), false); | ||
| equal(QUnit.equiv(same1, diff5), false); | ||
| equal(QUnit.equiv(diff5, diff1), false); | ||
| }); | ||
| test("Complex Arrays.", function() { | ||
| function fn() { | ||
| } | ||
| equal(QUnit.equiv( | ||
| [1, 2, 3, true, {}, null, [ | ||
| { | ||
| a: ["", '1', 0] | ||
| }, | ||
| 5, 6, 7 | ||
| ], "foo"], | ||
| [1, 2, 3, true, {}, null, [ | ||
| { | ||
| a: ["", '1', 0] | ||
| }, | ||
| 5, 6, 7 | ||
| ], "foo"]), | ||
| true); | ||
| equal(QUnit.equiv( | ||
| [1, 2, 3, true, {}, null, [ | ||
| { | ||
| a: ["", '1', 0] | ||
| }, | ||
| 5, 6, 7 | ||
| ], "foo"], | ||
| [1, 2, 3, true, {}, null, [ | ||
| { | ||
| b: ["", '1', 0] // not same property name | ||
| }, | ||
| 5, 6, 7 | ||
| ], "foo"]), | ||
| false); | ||
| var a = [{ | ||
| b: fn, | ||
| c: false, | ||
| "do": "reserved word", | ||
| "for": { | ||
| ar: [3,5,9,"hey!", [], { | ||
| ar: [1,[ | ||
| 3,4,6,9, null, [], [] | ||
| ]], | ||
| e: fn, | ||
| f: undefined | ||
| }] | ||
| }, | ||
| e: 0.43445 | ||
| }, 5, "string", 0, fn, false, null, undefined, 0, [ | ||
| 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 | ||
| ], [], [[[], "foo", null, { | ||
| n: 1/0, | ||
| z: { | ||
| a: [3,4,5,6,"yep!", undefined, undefined], | ||
| b: {} | ||
| } | ||
| }, {}]]]; | ||
| equal(QUnit.equiv(a, | ||
| [{ | ||
| b: fn, | ||
| c: false, | ||
| "do": "reserved word", | ||
| "for": { | ||
| ar: [3,5,9,"hey!", [], { | ||
| ar: [1,[ | ||
| 3,4,6,9, null, [], [] | ||
| ]], | ||
| e: fn, | ||
| f: undefined | ||
| }] | ||
| }, | ||
| e: 0.43445 | ||
| }, 5, "string", 0, fn, false, null, undefined, 0, [ | ||
| 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 | ||
| ], [], [[[], "foo", null, { | ||
| n: 1/0, | ||
| z: { | ||
| a: [3,4,5,6,"yep!", undefined, undefined], | ||
| b: {} | ||
| } | ||
| }, {}]]]), true); | ||
| equal(QUnit.equiv(a, | ||
| [{ | ||
| b: fn, | ||
| c: false, | ||
| "do": "reserved word", | ||
| "for": { | ||
| ar: [3,5,9,"hey!", [], { | ||
| ar: [1,[ | ||
| 3,4,6,9, null, [], [] | ||
| ]], | ||
| e: fn, | ||
| f: undefined | ||
| }] | ||
| }, | ||
| e: 0.43445 | ||
| }, 5, "string", 0, fn, false, null, undefined, 0, [ | ||
| 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]] | ||
| ], [], [[[], "foo", null, { | ||
| n: 1/0, | ||
| z: { | ||
| a: [3,4,5,6,"yep!", undefined, undefined], | ||
| b: {} | ||
| } | ||
| }, {}]]]), false); | ||
| equal(QUnit.equiv(a, | ||
| [{ | ||
| b: fn, | ||
| c: false, | ||
| "do": "reserved word", | ||
| "for": { | ||
| ar: [3,5,9,"hey!", [], { | ||
| ar: [1,[ | ||
| 3,4,6,9, null, [], [] | ||
| ]], | ||
| e: fn, | ||
| f: undefined | ||
| }] | ||
| }, | ||
| e: 0.43445 | ||
| }, 5, "string", 0, fn, false, null, undefined, 0, [ | ||
| 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 | ||
| ], [], [[[], "foo", null, { | ||
| n: -1/0, // different, -Infinity instead of Infinity | ||
| z: { | ||
| a: [3,4,5,6,"yep!", undefined, undefined], | ||
| b: {} | ||
| } | ||
| }, {}]]]), false); | ||
| equal(QUnit.equiv(a, | ||
| [{ | ||
| b: fn, | ||
| c: false, | ||
| "do": "reserved word", | ||
| "for": { | ||
| ar: [3,5,9,"hey!", [], { | ||
| ar: [1,[ | ||
| 3,4,6,9, null, [], [] | ||
| ]], | ||
| e: fn, | ||
| f: undefined | ||
| }] | ||
| }, | ||
| e: 0.43445 | ||
| }, 5, "string", 0, fn, false, null, undefined, 0, [ | ||
| 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 | ||
| ], [], [[[], "foo", { // different: null is missing | ||
| n: 1/0, | ||
| z: { | ||
| a: [3,4,5,6,"yep!", undefined, undefined], | ||
| b: {} | ||
| } | ||
| }, {}]]]), false); | ||
| equal(QUnit.equiv(a, | ||
| [{ | ||
| b: fn, | ||
| c: false, | ||
| "do": "reserved word", | ||
| "for": { | ||
| ar: [3,5,9,"hey!", [], { | ||
| ar: [1,[ | ||
| 3,4,6,9, null, [], [] | ||
| ]], | ||
| e: fn | ||
| // different: missing property f: undefined | ||
| }] | ||
| }, | ||
| e: 0.43445 | ||
| }, 5, "string", 0, fn, false, null, undefined, 0, [ | ||
| 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 | ||
| ], [], [[[], "foo", null, { | ||
| n: 1/0, | ||
| z: { | ||
| a: [3,4,5,6,"yep!", undefined, undefined], | ||
| b: {} | ||
| } | ||
| }, {}]]]), false); | ||
| }); | ||
| test("Prototypal inheritance", function() { | ||
| function Gizmo(id) { | ||
| this.id = id; | ||
| } | ||
| function Hoozit(id) { | ||
| this.id = id; | ||
| } | ||
| Hoozit.prototype = new Gizmo(); | ||
| var gizmo = new Gizmo("ok"); | ||
| var hoozit = new Hoozit("ok"); | ||
| // Try this test many times after test on instances that hold function | ||
| // to make sure that our code does not mess with last object constructor memoization. | ||
| equal(QUnit.equiv(function () {}, function () {}), false); | ||
| // Hoozit inherit from Gizmo | ||
| // hoozit instanceof Hoozit; // true | ||
| // hoozit instanceof Gizmo; // true | ||
| equal(QUnit.equiv(hoozit, gizmo), true); | ||
| Gizmo.prototype.bar = true; // not a function just in case we skip them | ||
| // Hoozit inherit from Gizmo | ||
| // They are equivalent | ||
| equal(QUnit.equiv(hoozit, gizmo), true); | ||
| // Make sure this is still true !important | ||
| // The reason for this is that I forgot to reset the last | ||
| // caller to where it were called from. | ||
| equal(QUnit.equiv(function () {}, function () {}), false); | ||
| // Make sure this is still true !important | ||
| equal(QUnit.equiv(hoozit, gizmo), true); | ||
| Hoozit.prototype.foo = true; // not a function just in case we skip them | ||
| // Gizmo does not inherit from Hoozit | ||
| // gizmo instanceof Gizmo; // true | ||
| // gizmo instanceof Hoozit; // false | ||
| // They are not equivalent | ||
| equal(QUnit.equiv(hoozit, gizmo), false); | ||
| // Make sure this is still true !important | ||
| equal(QUnit.equiv(function () {}, function () {}), false); | ||
| }); | ||
| test("Instances", function() { | ||
| function A() {} | ||
| var a1 = new A(); | ||
| var a2 = new A(); | ||
| function B() { | ||
| this.fn = function () {}; | ||
| } | ||
| var b1 = new B(); | ||
| var b2 = new B(); | ||
| equal(QUnit.equiv(a1, a2), true, "Same property, same constructor"); | ||
| // b1.fn and b2.fn are functions but they are different references | ||
| // But we decided to skip function for instances. | ||
| equal(QUnit.equiv(b1, b2), true, "Same property, same constructor"); | ||
| equal(QUnit.equiv(a1, b1), false, "Same properties but different constructor"); // failed | ||
| function Car(year) { | ||
| var privateVar = 0; | ||
| this.year = year; | ||
| this.isOld = function() { | ||
| return year > 10; | ||
| }; | ||
| } | ||
| function Human(year) { | ||
| var privateVar = 1; | ||
| this.year = year; | ||
| this.isOld = function() { | ||
| return year > 80; | ||
| }; | ||
| } | ||
| var car = new Car(30); | ||
| var carSame = new Car(30); | ||
| var carDiff = new Car(10); | ||
| var human = new Human(30); | ||
| var diff = { | ||
| year: 30 | ||
| }; | ||
| var same = { | ||
| year: 30, | ||
| isOld: function () {} | ||
| }; | ||
| equal(QUnit.equiv(car, car), true); | ||
| equal(QUnit.equiv(car, carDiff), false); | ||
| equal(QUnit.equiv(car, carSame), true); | ||
| equal(QUnit.equiv(car, human), false); | ||
| }); | ||
| test("Complex Instances Nesting (with function value in literals and/or in nested instances)", function() { | ||
| function A(fn) { | ||
| this.a = {}; | ||
| this.fn = fn; | ||
| this.b = {a: []}; | ||
| this.o = {}; | ||
| this.fn1 = fn; | ||
| } | ||
| function B(fn) { | ||
| this.fn = fn; | ||
| this.fn1 = function () {}; | ||
| this.a = new A(function () {}); | ||
| } | ||
| function fnOutside() { | ||
| } | ||
| function C(fn) { | ||
| function fnInside() { | ||
| } | ||
| this.x = 10; | ||
| this.fn = fn; | ||
| this.fn1 = function () {}; | ||
| this.fn2 = fnInside; | ||
| this.fn3 = { | ||
| a: true, | ||
| b: fnOutside // ok make reference to a function in all instances scope | ||
| }; | ||
| this.o1 = {}; | ||
| // This function will be ignored. | ||
| // Even if it is not visible for all instances (e.g. locked in a closures), | ||
| // it is from a property that makes part of an instance (e.g. from the C constructor) | ||
| this.b1 = new B(function () {}); | ||
| this.b2 = new B({ | ||
| x: { | ||
| b2: new B(function() {}) | ||
| } | ||
| }); | ||
| } | ||
| function D(fn) { | ||
| function fnInside() { | ||
| } | ||
| this.x = 10; | ||
| this.fn = fn; | ||
| this.fn1 = function () {}; | ||
| this.fn2 = fnInside; | ||
| this.fn3 = { | ||
| a: true, | ||
| b: fnOutside, // ok make reference to a function in all instances scope | ||
| // This function won't be ingored. | ||
| // It isn't visible for all C insances | ||
| // and it is not in a property of an instance. (in an Object instances e.g. the object literal) | ||
| c: fnInside | ||
| }; | ||
| this.o1 = {}; | ||
| // This function will be ignored. | ||
| // Even if it is not visible for all instances (e.g. locked in a closures), | ||
| // it is from a property that makes part of an instance (e.g. from the C constructor) | ||
| this.b1 = new B(function () {}); | ||
| this.b2 = new B({ | ||
| x: { | ||
| b2: new B(function() {}) | ||
| } | ||
| }); | ||
| } | ||
| function E(fn) { | ||
| function fnInside() { | ||
| } | ||
| this.x = 10; | ||
| this.fn = fn; | ||
| this.fn1 = function () {}; | ||
| this.fn2 = fnInside; | ||
| this.fn3 = { | ||
| a: true, | ||
| b: fnOutside // ok make reference to a function in all instances scope | ||
| }; | ||
| this.o1 = {}; | ||
| // This function will be ignored. | ||
| // Even if it is not visible for all instances (e.g. locked in a closures), | ||
| // it is from a property that makes part of an instance (e.g. from the C constructor) | ||
| this.b1 = new B(function () {}); | ||
| this.b2 = new B({ | ||
| x: { | ||
| b1: new B({a: function() {}}), | ||
| b2: new B(function() {}) | ||
| } | ||
| }); | ||
| } | ||
| var a1 = new A(function () {}); | ||
| var a2 = new A(function () {}); | ||
| equal(QUnit.equiv(a1, a2), true); | ||
| equal(QUnit.equiv(a1, a2), true); // different instances | ||
| var b1 = new B(function () {}); | ||
| var b2 = new B(function () {}); | ||
| equal(QUnit.equiv(b1, b2), true); | ||
| var c1 = new C(function () {}); | ||
| var c2 = new C(function () {}); | ||
| equal(QUnit.equiv(c1, c2), true); | ||
| var d1 = new D(function () {}); | ||
| var d2 = new D(function () {}); | ||
| equal(QUnit.equiv(d1, d2), false); | ||
| var e1 = new E(function () {}); | ||
| var e2 = new E(function () {}); | ||
| equal(QUnit.equiv(e1, e2), false); | ||
| }); | ||
| test('object with references to self wont loop', function(){ | ||
| var circularA = { | ||
| abc:null | ||
| }, circularB = { | ||
| abc:null | ||
| }; | ||
| circularA.abc = circularA; | ||
| circularB.abc = circularB; | ||
| equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)"); | ||
| circularA.def = 1; | ||
| circularB.def = 1; | ||
| equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object (ambigous test)"); | ||
| circularA.def = 1; | ||
| circularB.def = 0; | ||
| equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object (unambigous test)"); | ||
| }); | ||
| test('array with references to self wont loop', function(){ | ||
| var circularA = [], | ||
| circularB = []; | ||
| circularA.push(circularA); | ||
| circularB.push(circularB); | ||
| equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)"); | ||
| circularA.push( 'abc' ); | ||
| circularB.push( 'abc' ); | ||
| equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on array (ambigous test)"); | ||
| circularA.push( 'hello' ); | ||
| circularB.push( 'goodbye' ); | ||
| equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on array (unambigous test)"); | ||
| }); | ||
| test('mixed object/array with references to self wont loop', function(){ | ||
| var circularA = [{abc:null}], | ||
| circularB = [{abc:null}]; | ||
| circularA[0].abc = circularA; | ||
| circularB[0].abc = circularB; | ||
| circularA.push(circularA); | ||
| circularB.push(circularB); | ||
| equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)"); | ||
| circularA[0].def = 1; | ||
| circularB[0].def = 1; | ||
| equal(QUnit.equiv(circularA, circularB), true, "Should not repeat test on object/array (ambigous test)"); | ||
| circularA[0].def = 1; | ||
| circularB[0].def = 0; | ||
| equal(QUnit.equiv(circularA, circularB), false, "Should not repeat test on object/array (unambigous test)"); | ||
| }); | ||
| test("Test that must be done at the end because they extend some primitive's prototype", function() { | ||
| // Try that a function looks like our regular expression. | ||
| // This tests if we check that a and b are really both instance of RegExp | ||
| Function.prototype.global = true; | ||
| Function.prototype.multiline = true; | ||
| Function.prototype.ignoreCase = false; | ||
| Function.prototype.source = "my regex"; | ||
| var re = /my regex/gm; | ||
| equal(QUnit.equiv(re, function () {}), false, "A function that looks that a regex isn't a regex"); | ||
| // This test will ensures it works in both ways, and ALSO especially that we can make differences | ||
| // between RegExp and Function constructor because typeof on a RegExpt instance is "function" | ||
| equal(QUnit.equiv(function () {}, re), false, "Same conversely, but ensures that function and regexp are distinct because their constructor are different"); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>QUnit Test Suite</title> | ||
| <link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="test.js"></script> | ||
| <script type="text/javascript" src="deepEqual.js"></script> | ||
| <script> | ||
| var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"]; | ||
| for (var i = 0; i < logs.length; i++) { | ||
| (function() { | ||
| var log = logs[i]; | ||
| QUnit[log] = function() { | ||
| console.log(log, arguments); | ||
| }; | ||
| })(); | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>QUnit Test Suite</title> | ||
| <link rel="stylesheet" href="../qunit/qunit.css"> | ||
| <script src="../qunit/qunit.js"></script> | ||
| <script src="test.js"></script> | ||
| <script src="deepEqual.js"></script> | ||
| <script src="swarminject.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>QUnit Test Suite</title> | ||
| <link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="../qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="logs.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id="qunit"></div> | ||
| <div id="qunit-fixture">test markup</div> | ||
| </body> | ||
| </html> |
| // TODO disable reordering for this suite! | ||
| var begin = 0, | ||
| moduleStart = 0, | ||
| moduleDone = 0, | ||
| testStart = 0, | ||
| testDone = 0, | ||
| log = 0, | ||
| moduleContext, | ||
| moduleDoneContext, | ||
| testContext, | ||
| testDoneContext, | ||
| logContext; | ||
| QUnit.begin(function() { | ||
| begin++; | ||
| }); | ||
| QUnit.done(function() { | ||
| }); | ||
| QUnit.moduleStart(function(context) { | ||
| moduleStart++; | ||
| moduleContext = context; | ||
| }); | ||
| QUnit.moduleDone(function(context) { | ||
| moduleDone++; | ||
| moduleDoneContext = context; | ||
| }); | ||
| QUnit.testStart(function(context) { | ||
| testStart++; | ||
| testContext = context; | ||
| }); | ||
| QUnit.testDone(function(context) { | ||
| testDone++; | ||
| testDoneContext = context; | ||
| }); | ||
| QUnit.log(function(context) { | ||
| log++; | ||
| logContext = context; | ||
| }); | ||
| var logs = ["begin", "testStart", "testDone", "log", "moduleStart", "moduleDone", "done"]; | ||
| for (var i = 0; i < logs.length; i++) { | ||
| (function() { | ||
| var log = logs[i]; | ||
| QUnit[log](function() { | ||
| console.log(log, arguments); | ||
| }); | ||
| })(); | ||
| } | ||
| module("logs1"); | ||
| test("test1", 13, function() { | ||
| equal(begin, 1); | ||
| equal(moduleStart, 1); | ||
| equal(testStart, 1); | ||
| equal(testDone, 0); | ||
| equal(moduleDone, 0); | ||
| deepEqual(logContext, { | ||
| result: true, | ||
| message: undefined, | ||
| actual: 0, | ||
| expected: 0 | ||
| }); | ||
| equal("foo", "foo", "msg"); | ||
| deepEqual(logContext, { | ||
| result: true, | ||
| message: "msg", | ||
| actual: "foo", | ||
| expected: "foo" | ||
| }); | ||
| strictEqual(testDoneContext, undefined); | ||
| deepEqual(testContext, { | ||
| module: "logs1", | ||
| name: "test1" | ||
| }); | ||
| strictEqual(moduleDoneContext, undefined); | ||
| deepEqual(moduleContext, { | ||
| name: "logs1" | ||
| }); | ||
| equal(log, 12); | ||
| }); | ||
| test("test2", 10, function() { | ||
| equal(begin, 1); | ||
| equal(moduleStart, 1); | ||
| equal(testStart, 2); | ||
| equal(testDone, 1); | ||
| equal(moduleDone, 0); | ||
| deepEqual(testDoneContext, { | ||
| module: "logs1", | ||
| name: "test1", | ||
| failed: 0, | ||
| passed: 13, | ||
| total: 13 | ||
| }); | ||
| deepEqual(testContext, { | ||
| module: "logs1", | ||
| name: "test2" | ||
| }); | ||
| strictEqual(moduleDoneContext, undefined); | ||
| deepEqual(moduleContext, { | ||
| name: "logs1" | ||
| }); | ||
| equal(log, 22); | ||
| }); | ||
| module("logs2"); | ||
| test("test1", 9, function() { | ||
| equal(begin, 1); | ||
| equal(moduleStart, 2); | ||
| equal(testStart, 3); | ||
| equal(testDone, 2); | ||
| equal(moduleDone, 1); | ||
| deepEqual(testContext, { | ||
| module: "logs2", | ||
| name: "test1" | ||
| }); | ||
| deepEqual(moduleDoneContext, { | ||
| name: "logs1", | ||
| failed: 0, | ||
| passed: 23, | ||
| total: 23 | ||
| }); | ||
| deepEqual(moduleContext, { | ||
| name: "logs2" | ||
| }); | ||
| equal(log, 31); | ||
| }); | ||
| test("test2", 8, function() { | ||
| equal(begin, 1); | ||
| equal(moduleStart, 2); | ||
| equal(testStart, 4); | ||
| equal(testDone, 3); | ||
| equal(moduleDone, 1); | ||
| deepEqual(testContext, { | ||
| module: "logs2", | ||
| name: "test2" | ||
| }); | ||
| deepEqual(moduleContext, { | ||
| name: "logs2" | ||
| }); | ||
| equal(log, 39); | ||
| }); | ||
| var testAutorun = true; | ||
| QUnit.done(function() { | ||
| if (!testAutorun) { | ||
| return; | ||
| } | ||
| testAutorun = false; | ||
| module("autorun"); | ||
| test("reset", 0, function() {}); | ||
| moduleStart = moduleDone = 0; | ||
| test("first", function(){ | ||
| equal(moduleStart, 1, "test started"); | ||
| equal(moduleDone, 0, "test in progress"); | ||
| }); | ||
| test("second", function(){ | ||
| equal(moduleStart, 2, "test started"); | ||
| equal(moduleDone, 1, "test in progress"); | ||
| }); | ||
| }); |
| // run with | ||
| // node test/node-test.js | ||
| var QUnit = require("../qunit/qunit"); | ||
| QUnit.log(function(details) { | ||
| if (!details.result) { | ||
| var output = "FAILED: " + (details.message ? details.message + ", " : ""); | ||
| if (details.actual) { | ||
| output += "expected: " + details.expected + ", actual: " + details.actual; | ||
| } | ||
| if (details.source) { | ||
| output += ", " + details.source; | ||
| } | ||
| print(output); | ||
| } else { | ||
| print("ok!"); | ||
| } | ||
| }); | ||
| QUnit.test("yo", function() { | ||
| QUnit.equal(true, false); | ||
| QUnit.equal(true, false, "gotta fail"); | ||
| x.y.z; | ||
| }); |
| // run with | ||
| // node test/node-test.js | ||
| var QUnit = require("../qunit/qunit"); | ||
| QUnit.log(function(details) { | ||
| if (!details.result) { | ||
| var output = "FAILED: " + (details.message ? details.message + ", " : ""); | ||
| if (details.actual) { | ||
| output += "expected: " + details.expected + ", actual: " + details.actual; | ||
| } | ||
| if (details.source) { | ||
| output += ", " + details.source; | ||
| } | ||
| console.log(output); | ||
| } | ||
| }); | ||
| QUnit.test("yo", function() { | ||
| QUnit.equal(true, false); | ||
| QUnit.equal(true, false, "gotta fail"); | ||
| x.y.z; | ||
| }); |
| // load testswarm agent | ||
| (function() { | ||
| var url = window.location.search; | ||
| url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); | ||
| if ( !url || url.indexOf("http") !== 0 ) { | ||
| return; | ||
| } | ||
| document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>"); | ||
| })(); |
| test("module without setup/teardown (default)", function() { | ||
| expect(1); | ||
| ok(true); | ||
| }); | ||
| test("expect in test", 3, function() { | ||
| ok(true); | ||
| ok(true); | ||
| ok(true); | ||
| }); | ||
| test("expect in test", 1, function() { | ||
| ok(true); | ||
| }); | ||
| module("setup test", { | ||
| setup: function() { | ||
| ok(true); | ||
| } | ||
| }); | ||
| test("module with setup", function() { | ||
| expect(2); | ||
| ok(true); | ||
| }); | ||
| test("module with setup, expect in test call", 2, function() { | ||
| ok(true); | ||
| }); | ||
| var state; | ||
| module("setup/teardown test", { | ||
| setup: function() { | ||
| state = true; | ||
| ok(true); | ||
| x = 1; | ||
| }, | ||
| teardown: function() { | ||
| ok(true); | ||
| // can introduce and delete globals in setup/teardown | ||
| // without noglobals sounding the alarm | ||
| delete x; | ||
| } | ||
| }); | ||
| test("module with setup/teardown", function() { | ||
| expect(3); | ||
| ok(true); | ||
| }); | ||
| module("setup/teardown test 2"); | ||
| test("module without setup/teardown", function() { | ||
| expect(1); | ||
| ok(true); | ||
| }); | ||
| if (typeof setTimeout !== 'undefined') { | ||
| state = 'fail'; | ||
| module("teardown and stop", { | ||
| teardown: function() { | ||
| equal(state, "done", "Test teardown."); | ||
| } | ||
| }); | ||
| test("teardown must be called after test ended", function() { | ||
| expect(1); | ||
| stop(); | ||
| setTimeout(function() { | ||
| state = "done"; | ||
| start(); | ||
| }, 13); | ||
| }); | ||
| test("parameter passed to stop increments semaphore n times", function() { | ||
| expect(1); | ||
| stop(3); | ||
| setTimeout(function() { | ||
| state = "not enough starts"; | ||
| start(), start(); | ||
| }, 13); | ||
| setTimeout(function() { | ||
| state = "done"; | ||
| start(); | ||
| }, 15); | ||
| }); | ||
| test("parameter passed to start decrements semaphore n times", function() { | ||
| expect(1); | ||
| stop(), stop(), stop(); | ||
| setTimeout(function() { | ||
| state = "done"; | ||
| start(3); | ||
| }, 18); | ||
| }); | ||
| module("async setup test", { | ||
| setup: function() { | ||
| stop(); | ||
| setTimeout(function(){ | ||
| ok(true); | ||
| start(); | ||
| }, 500); | ||
| } | ||
| }); | ||
| asyncTest("module with async setup", function() { | ||
| expect(2); | ||
| ok(true); | ||
| start(); | ||
| }); | ||
| module("async teardown test", { | ||
| teardown: function() { | ||
| stop(); | ||
| setTimeout(function(){ | ||
| ok(true); | ||
| start(); | ||
| }, 500); | ||
| } | ||
| }); | ||
| asyncTest("module with async teardown", function() { | ||
| expect(2); | ||
| ok(true); | ||
| start(); | ||
| }); | ||
| module("asyncTest"); | ||
| asyncTest("asyncTest", function() { | ||
| expect(2); | ||
| ok(true); | ||
| setTimeout(function() { | ||
| state = "done"; | ||
| ok(true); | ||
| start(); | ||
| }, 13); | ||
| }); | ||
| asyncTest("asyncTest", 2, function() { | ||
| ok(true); | ||
| setTimeout(function() { | ||
| state = "done"; | ||
| ok(true); | ||
| start(); | ||
| }, 13); | ||
| }); | ||
| test("sync", 2, function() { | ||
| stop(); | ||
| setTimeout(function() { | ||
| ok(true); | ||
| start(); | ||
| }, 13); | ||
| stop(); | ||
| setTimeout(function() { | ||
| ok(true); | ||
| start(); | ||
| }, 125); | ||
| }); | ||
| test("test synchronous calls to stop", 2, function() { | ||
| stop(); | ||
| setTimeout(function(){ | ||
| ok(true, 'first'); | ||
| start(); | ||
| stop(); | ||
| setTimeout(function(){ | ||
| ok(true, 'second'); | ||
| start(); | ||
| }, 150); | ||
| }, 150); | ||
| }); | ||
| } | ||
| module("save scope", { | ||
| setup: function() { | ||
| this.foo = "bar"; | ||
| }, | ||
| teardown: function() { | ||
| deepEqual(this.foo, "bar"); | ||
| } | ||
| }); | ||
| test("scope check", function() { | ||
| expect(2); | ||
| deepEqual(this.foo, "bar"); | ||
| }); | ||
| module("simple testEnvironment setup", { | ||
| foo: "bar", | ||
| bugid: "#5311" // example of meta-data | ||
| }); | ||
| test("scope check", function() { | ||
| deepEqual(this.foo, "bar"); | ||
| }); | ||
| test("modify testEnvironment",function() { | ||
| expect(0); | ||
| this.foo="hamster"; | ||
| }); | ||
| test("testEnvironment reset for next test",function() { | ||
| deepEqual(this.foo, "bar"); | ||
| }); | ||
| module("testEnvironment with object", { | ||
| options:{ | ||
| recipe:"soup", | ||
| ingredients:["hamster","onions"] | ||
| } | ||
| }); | ||
| test("scope check", function() { | ||
| deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ; | ||
| }); | ||
| test("modify testEnvironment",function() { | ||
| expect(0); | ||
| // since we do a shallow copy, the testEnvironment can be modified | ||
| this.options.ingredients.push("carrots"); | ||
| }); | ||
| test("testEnvironment reset for next test",function() { | ||
| deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ; | ||
| }); | ||
| module("testEnvironment tests"); | ||
| function makeurl() { | ||
| var testEnv = QUnit.current_testEnvironment; | ||
| var url = testEnv.url || 'http://example.com/search'; | ||
| var q = testEnv.q || 'a search test'; | ||
| return url + '?q='+encodeURIComponent(q); | ||
| } | ||
| test("makeurl working",function() { | ||
| equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global'); | ||
| equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment'); | ||
| }); | ||
| module("testEnvironment with makeurl settings", { | ||
| url: 'http://google.com/', | ||
| q: 'another_search_test' | ||
| }); | ||
| test("makeurl working with settings from testEnvironment", function() { | ||
| equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to from the url'); | ||
| }); | ||
| module("jsDump"); | ||
| test("jsDump output", function() { | ||
| equal( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" ); | ||
| equal( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"left\": 0,\n \"top\": 5\n}" ); | ||
| if (typeof document !== 'undefined' && document.getElementById("qunit-header")) { | ||
| equal( QUnit.jsDump.parse(document.getElementById("qunit-header")), "<h1 id=\"qunit-header\"></h1>" ); | ||
| equal( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n <h1 id=\"qunit-header\"></h1>\n]" ); | ||
| } | ||
| }); | ||
| module("assertions"); | ||
| test("raises",function() { | ||
| function CustomError( message ) { | ||
| this.message = message; | ||
| } | ||
| CustomError.prototype.toString = function() { | ||
| return this.message; | ||
| }; | ||
| raises( | ||
| function() { | ||
| throw "error" | ||
| } | ||
| ); | ||
| raises( | ||
| function() { | ||
| throw "error" | ||
| }, | ||
| 'raises with just a message, no expected' | ||
| ); | ||
| raises( | ||
| function() { | ||
| throw new CustomError(); | ||
| }, | ||
| CustomError, | ||
| 'raised error is an instance of CustomError' | ||
| ); | ||
| raises( | ||
| function() { | ||
| throw new CustomError("some error description"); | ||
| }, | ||
| /description/, | ||
| "raised error message contains 'description'" | ||
| ); | ||
| raises( | ||
| function() { | ||
| throw new CustomError("some error description"); | ||
| }, | ||
| function( err ) { | ||
| if ( (err instanceof CustomError) && /description/.test(err) ) { | ||
| return true; | ||
| } | ||
| }, | ||
| "custom validation function" | ||
| ); | ||
| this.CustomError = CustomError; | ||
| raises( | ||
| function() { | ||
| throw new this.CustomError("some error description"); | ||
| }, | ||
| /description/, | ||
| "raised error with 'this' context" | ||
| ); | ||
| }); | ||
| if (typeof document !== "undefined") { | ||
| module("fixture"); | ||
| test("setup", function() { | ||
| expect(0); | ||
| document.getElementById("qunit-fixture").innerHTML = "foobar"; | ||
| }); | ||
| test("basics", function() { | ||
| equal( document.getElementById("qunit-fixture").innerHTML, "test markup", "automatically reset" ); | ||
| }); | ||
| test("running test name displayed", function() { | ||
| expect(2); | ||
| var displaying = document.getElementById("qunit-testresult"); | ||
| ok( /running test name displayed/.test(displaying.innerHTML), "Expect test name to be found in displayed text" ); | ||
| ok( /fixture/.test(displaying.innerHTML), "Expect module name to be found in displayed text" ); | ||
| }); | ||
| } | ||
| module("custom assertions"); | ||
| (function() { | ||
| function mod2(value, expected, message) { | ||
| var actual = value % 2; | ||
| QUnit.push(actual == expected, actual, expected, message); | ||
| } | ||
| test("mod2", function() { | ||
| mod2(2, 0, "2 % 2 == 0"); | ||
| mod2(3, 1, "3 % 2 == 1"); | ||
| }); | ||
| })(); | ||
| module("recursions"); | ||
| function Wrap(x) { | ||
| this.wrap = x; | ||
| if (x == undefined) this.first = true; | ||
| } | ||
| function chainwrap(depth, first, prev) { | ||
| depth = depth || 0; | ||
| var last = prev || new Wrap(); | ||
| first = first || last; | ||
| if (depth == 1) { | ||
| first.wrap = last; | ||
| } | ||
| if (depth > 1) { | ||
| last = chainwrap(depth-1, first, new Wrap(last)); | ||
| } | ||
| return last; | ||
| } | ||
| test("check jsDump recursion", function() { | ||
| expect(4); | ||
| var noref = chainwrap(0); | ||
| var nodump = QUnit.jsDump.parse(noref); | ||
| equal(nodump, '{\n "first": true,\n "wrap": undefined\n}'); | ||
| var selfref = chainwrap(1); | ||
| var selfdump = QUnit.jsDump.parse(selfref); | ||
| equal(selfdump, '{\n "first": true,\n "wrap": recursion(-1)\n}'); | ||
| var parentref = chainwrap(2); | ||
| var parentdump = QUnit.jsDump.parse(parentref); | ||
| equal(parentdump, '{\n "wrap": {\n "first": true,\n "wrap": recursion(-2)\n }\n}'); | ||
| var circref = chainwrap(10); | ||
| var circdump = QUnit.jsDump.parse(circref); | ||
| ok(new RegExp("recursion\\(-10\\)").test(circdump), "(" +circdump + ") should show -10 recursion level"); | ||
| }); | ||
| test("check (deep-)equal recursion", function() { | ||
| var noRecursion = chainwrap(0); | ||
| equal(noRecursion, noRecursion, "I should be equal to me."); | ||
| deepEqual(noRecursion, noRecursion, "... and so in depth."); | ||
| var selfref = chainwrap(1); | ||
| equal(selfref, selfref, "Even so if I nest myself."); | ||
| deepEqual(selfref, selfref, "... into the depth."); | ||
| var circref = chainwrap(10); | ||
| equal(circref, circref, "Or hide that through some levels of indirection."); | ||
| deepEqual(circref, circref, "... and checked on all levels!"); | ||
| }); | ||
| test('Circular reference with arrays', function() { | ||
| // pure array self-ref | ||
| var arr = []; | ||
| arr.push(arr); | ||
| var arrdump = QUnit.jsDump.parse(arr); | ||
| equal(arrdump, '[\n recursion(-1)\n]'); | ||
| equal(arr, arr[0], 'no endless stack when trying to dump arrays with circular ref'); | ||
| // mix obj-arr circular ref | ||
| var obj = {}; | ||
| var childarr = [obj]; | ||
| obj.childarr = childarr; | ||
| var objdump = QUnit.jsDump.parse(obj); | ||
| var childarrdump = QUnit.jsDump.parse(childarr); | ||
| equal(objdump, '{\n "childarr": [\n recursion(-2)\n ]\n}'); | ||
| equal(childarrdump, '[\n {\n "childarr": recursion(-2)\n }\n]'); | ||
| equal(obj.childarr, childarr, 'no endless stack when trying to dump array/object mix with circular ref'); | ||
| equal(childarr[0], obj, 'no endless stack when trying to dump array/object mix with circular ref'); | ||
| }); | ||
| test('Circular reference - test reported by soniciq in #105', function() { | ||
| var MyObject = function() {}; | ||
| MyObject.prototype.parent = function(obj) { | ||
| if (obj === undefined) { return this._parent; } | ||
| this._parent = obj; | ||
| }; | ||
| MyObject.prototype.children = function(obj) { | ||
| if (obj === undefined) { return this._children; } | ||
| this._children = obj; | ||
| }; | ||
| var a = new MyObject(), | ||
| b = new MyObject(); | ||
| var barr = [b]; | ||
| a.children(barr); | ||
| b.parent(a); | ||
| equal(a.children(), barr); | ||
| deepEqual(a.children(), [b]); | ||
| }); | ||
| (function() { | ||
| var reset = QUnit.reset; | ||
| function afterTest() { | ||
| ok( false, "reset should not modify test status" ); | ||
| } | ||
| module("reset"); | ||
| test("reset runs assertions", function() { | ||
| expect(0); | ||
| QUnit.reset = function() { | ||
| afterTest(); | ||
| reset.apply( this, arguments ); | ||
| }; | ||
| }); | ||
| test("reset runs assertions2", function() { | ||
| expect(0); | ||
| QUnit.reset = reset; | ||
| }); | ||
| })(); | ||
| if (typeof setTimeout !== 'undefined') { | ||
| function testAfterDone(){ | ||
| var testName = "ensure has correct number of assertions"; | ||
| function secondAfterDoneTest(){ | ||
| QUnit.config.done = []; | ||
| //QUnit.done = function(){}; | ||
| //because when this does happen, the assertion count parameter doesn't actually | ||
| //work we use this test to check the assertion count. | ||
| module("check previous test's assertion counts"); | ||
| test('count previous two test\'s assertions', function(){ | ||
| var spans = document.getElementsByTagName('span'), | ||
| tests = [], | ||
| countNodes; | ||
| //find these two tests | ||
| for (var i = 0; i < spans.length; i++) { | ||
| if (spans[i].innerHTML.indexOf(testName) !== -1) { | ||
| tests.push(spans[i]); | ||
| } | ||
| } | ||
| //walk dom to counts | ||
| countNodes = tests[0].nextSibling.nextSibling.getElementsByTagName('b'); | ||
| equal(countNodes[1].innerHTML, "99"); | ||
| countNodes = tests[1].nextSibling.nextSibling.getElementsByTagName('b'); | ||
| equal(countNodes[1].innerHTML, "99"); | ||
| }); | ||
| } | ||
| QUnit.config.done = []; | ||
| QUnit.done(secondAfterDoneTest); | ||
| module("Synchronous test after load of page"); | ||
| asyncTest('Async test', function(){ | ||
| start(); | ||
| for (var i = 1; i < 100; i++) { | ||
| ok(i); | ||
| } | ||
| }); | ||
| test(testName, 99, function(){ | ||
| for (var i = 1; i < 100; i++) { | ||
| ok(i); | ||
| } | ||
| }); | ||
| //we need two of these types of tests in order to ensure that assertions | ||
| //don't move between tests. | ||
| test(testName + ' 2', 99, function(){ | ||
| for (var i = 1; i < 100; i++) { | ||
| ok(i); | ||
| } | ||
| }); | ||
| } | ||
| QUnit.done(testAfterDone); | ||
| } |
+2
-2
@@ -1,2 +0,2 @@ | ||
| /* genData v1.2.0 / Bemi Faison (c) 2011 / MIT / http://github.com/bemson/genData */ | ||
| (typeof exports!="undefined"?exports:window).genData=function(a){var b=arguments,c=b.callee,d,e,f,g,h=[],i=[],j,k={},l,m,n,o=c,p=typeof o=="function",q;if(this instanceof c){if(a){~{}.toString.call(b[1]).indexOf("y")&&(o=a,b=b[1]),h=h.concat([].slice.call(b));function s(a,b,d){var e=~{}.toString.call(b).indexOf("y");return this instanceof s?a?new c(e?a:s,h.concat(e?b:[].slice.call(arguments))):this:c(a,h.concat(b||[]),d?d:s)}return s.prototype=p?new o:o,s}return this}b[1]&&(h=typeof b[1]=="function"?[b[1]]:b[1]),f=h.length,b[2]&&(o=b[2]);function r(a,b){this.name=a,this.value=b}r.prototype=p?o.prototype:o,l=[["",a]];while(l.length){n=l.shift(),q=new r(n[0],n[1]),e=0,d={parent:0,omit:0,scan:1,exit:0},b=[q.name,q.value,n[2],i,d,k];while(e<f&&!d.exit)h[e++].apply(q,b);d.omit?q._OMIT=!0:i.push(q);if(d.exit)l=[];else{m=[];if(d.scan&&typeof q.value=="object"){j=typeof d.parent=="object"?d.parent:q;for(g in q.value)q.value.hasOwnProperty(g)&&m.push([g,q.value[g],j])}l=m.concat(l)}}return i}; | ||
| /* genData v1.2.1 / Bemi Faison (c) 2012 / MIT / http://github.com/bemson/genData */ | ||
| (typeof exports!="undefined"?exports:window).genData=function(a){var b,c,d,e,f,g,h,i,j,k=arguments,l={},m=[],n=[],o=k.callee,p=o;if(this instanceof o){if(a){~{}.toString.call(k[1]).indexOf("y")&&(p=a,k=k[1]),m=m.concat([].slice.call(k));function r(a,b,c){var d=~{}.toString.call(b).indexOf("y");return this instanceof r?a?new o(d?a:r,m.concat(d?b:[].slice.call(arguments))):this:o(a,m.concat(b||[]),c?c:r)}return r.prototype=typeof p=="function"?new p:p,r}return this}k[1]&&(m=typeof k[1]=="function"?[k[1]]:k[1]),j=m.length,k[2]&&(p=k[2]);function q(a,b){this.name=a,this.value=b}q.prototype=typeof p=="function"?p.prototype:p,g=[["",a]];while(g.length){i=g.shift(),c=new q(i[0],i[1]),b=0,f={omit:0,scan:1,exit:0,parent:0},k=[i[0],i[1],i[2],n,f,l];while(b<j&&!f.exit)m[b++].apply(c,k);f.omit?c._OMIT=!0:n.push(c);if(f.exit)g=[];else{h=[];if(f.scan&&typeof c.value=="object"){e=typeof f.parent=="object"?f.parent:c;for(d in c.value)c.value.hasOwnProperty(d)&&h.push([d,c.value[d],e])}g=h.concat(g)}}return n}; |
+1
-1
| { | ||
| "name": "genData" | ||
| , "version": "1.2.0" | ||
| , "version": "1.2.1" | ||
| , "description": "A normalization pattern to build, query, and manipulate everything." | ||
@@ -5,0 +5,0 @@ , "keywords": [ |
+3
-3
| # genData | ||
| A normalization pattern to build, query, and manipulate everything. | ||
| (11/21/11) | ||
| version 1.2.0 | ||
| (4/20/12) | ||
| version 1.2.1 | ||
| by Bemi Faison | ||
@@ -20,3 +20,3 @@ | ||
| * src/ - Directory containing the source code | ||
| * src-test/ - Directory containing [Qunit](http://docs.jquery.com/Qunit) test files | ||
| * test/ - Directory containing [Qunit](http://docs.jquery.com/Qunit) test files | ||
@@ -23,0 +23,0 @@ |
+184
-97
| /*! | ||
| * genData @ https://github.com/bemson/genData | ||
| * by Bemi Faison | ||
| * MIT license | ||
| * **genData** generates normalized datasets and functions that encapsulate customizations while extending the prototype-chain. | ||
| * | by Bemi Faison | ||
| * | MIT license | ||
| * | ||
| * **genData** generates normalized datasets and funcions that curry customizations and extend the prototype-chain. | ||
| * | ||
| * We start by adding `genData` to the (global) window object, or exporting it for commonjs environments. The genData "library" is just a function, and omits the conventional self-executing closure, in favor of performance and because the behavior is functioinal enough to omit private variables. | ||
| */ | ||
| (typeof exports !== 'undefined' ? exports : window).genData = function (stuff) { | ||
| /** | ||
| * Define genData in the global scope, or export as a module if we're in a commonjs environment. | ||
| * Declare all necessary variables. Most of these are placeholders. | ||
| * | ||
| * This function forks it's behavior when called with the `new` statement. | ||
| * The `arguments` object is aliased for minification purposes (mostly). The dataModel serves as the prototype to extend or use, and is the `genData` function by default - which can be overriden by the incoming arguments. | ||
| */ | ||
| (typeof exports !== 'undefined' ? exports : window).genData = function(stuff) { | ||
| /** | ||
| * Declare all variables, most of which are placeholders. | ||
| */ | ||
| var args = arguments, | ||
| origFnc = args.callee, | ||
| parserFlags, | ||
| currentParserIndex, | ||
| totalParsers, | ||
| memberName, | ||
| parsers = [], | ||
| dataset = [], | ||
| parentRef, | ||
| sharedVars = {}, | ||
| queue, | ||
| queueBuffer, | ||
| queueItem, | ||
| dataModel = origFnc, | ||
| isDataModelConstructor = typeof dataModel === 'function', | ||
| dataInstance; | ||
| /** | ||
| * When invoked without the `new` operator, genData presumes it will normalize `stuff` and return a dataset. | ||
| */ | ||
| var | ||
| currentParserIndex | ||
| , dataInstance | ||
| , memberName | ||
| , parentRef | ||
| , parserFlags | ||
| , queue | ||
| , queueBuffer | ||
| , queueItem | ||
| , totalParsers | ||
| , sharedVars = {} | ||
| , parsers = [] | ||
| , dataset = [] | ||
| , args = arguments | ||
| , origFnc = args.callee | ||
| , dataModel = origFnc | ||
| ; | ||
| /** | ||
| * genData forks it's behavior based on whether or not it was invoked with or without the `new` statement. | ||
| */ | ||
| if (!(this instanceof origFnc)) { | ||
| /** | ||
| * Handles the following argument signatures: | ||
| * When invoked without the `new` statement, genData will assume it's normalization role. | ||
| * | ||
| * 1. `genData([stuff])` | ||
| * 2. `genData(stuff, parser)` | ||
| * 3. `genData(stuff, parser, dataModel)` | ||
| * 4. `genData(stuff, parsersArray)` | ||
| * 5. `genData(stuff, parsersArray, dataModel)` | ||
| * This functional form handles the following argument signatures: | ||
| * | ||
| * 1. `var dataset1 = genData(stuff);` | ||
| * 2. `var dataset2 = genData(stuff, parsers);` | ||
| * 3. `var dataset3 = genData(stuff, parsers, dataModel);` | ||
| * | ||
| * **stuff** is any JavaScript value (including null). genData will recursively iterate and parse the non-inherited members of this argument. | ||
| * | ||
| * **parsers** | ||
| * | ||
| * One or more functions (i.e., an _array_ of functions) that will parse each object member. | ||
| * | ||
| * **dataModel** | ||
| * | ||
| * A function, who's prototype is applied to each resulting object parsed. | ||
| */ | ||
| // if there is a second argument... | ||
| if (args[1]) { | ||
| // capture as a collection of parsers - ensure it's an array of functions, even when given one function | ||
| parsers = typeof args[1] === 'function' ? [args[1]] : args[1]; | ||
| } | ||
| // capture the number of parsers | ||
| totalParsers = parsers.length; | ||
| // if a second argument is present... | ||
| if (args[2]) { | ||
| // capture as the function prototype for the resulting parsed objects | ||
| dataModel = args[2]; | ||
| } | ||
| /** | ||
| * Define an anonymous Data constructor. | ||
| * The default klass for data objects, parsed while iterating and normalizing. | ||
| * | ||
| * Set the prototype to the resolved dataModel (genData by default). | ||
| * The structure of a _genData_ data object is simple: the name and value to be parsed. | ||
| * | ||
| * By default, the prototype to this klass is genData's. When passed a function as a third argument, it's prototype is used instead. | ||
| */ | ||
@@ -61,6 +79,7 @@ function Data(name, value) { | ||
| } | ||
| Data.prototype = isDataModelConstructor ? dataModel.prototype : dataModel; | ||
| // use the given or default prototype | ||
| Data.prototype = typeof dataModel === 'function' ? dataModel.prototype : dataModel; | ||
| /** | ||
| * Queue an array of parameters, needed to instantiate a Data object. | ||
| * The queue is an array of parameter configurations (another array). The parameters are those needed when instantiating a Data instance; _name_ and _value_. The initial parameter-set is an empty name and the original value to be normalized. | ||
| */ | ||
@@ -74,7 +93,9 @@ queue = [ | ||
| /** | ||
| * Begin the main processing/normalization loop, and continue until `queue` is empty. | ||
| * | ||
| * Each loop begins with removing an item from the queue, defining a Data instance from it, and resetting loop variables - used when invoking each parser function. | ||
| * This is the iteration loop that continues until the `queue` array is empty. | ||
| */ | ||
| while (queue.length) { | ||
| /** | ||
| * The loop begins by removing the first parameter-set from the queue, and using that information to initialize a data object. | ||
| * This data object will serve as the scope when invoking the parsers passed in this genData call. We reset a variable that tracks the current parser, for each newly defined data object. | ||
| */ | ||
| queueItem = queue.shift(); | ||
@@ -84,71 +105,100 @@ dataInstance = new Data(queueItem[0], queueItem[1]); | ||
| /** | ||
| * Reset the flags object passed to _parser_ functions. | ||
| * Here we setup the arguments that will be passed to all the parsers. The `parserFlags` object is critical, as it allows parser functions to control how and what is processed _next_ in the queue. The `parserFlags` object is passed to each parser (in a larger collection of arguments. Below are the keys and their impact on the iteration process. | ||
| * | ||
| * - **parent**: When a data object, the instance to parent any scanned and queued properties | ||
| * - **omit**: When truthy, the data object is excluded from the dataset | ||
| * - **scan**: When falsy, members of the data object are not processed | ||
| * - **exit**: When truthy, genData stops processing the queue | ||
| * - **omit**: A booly flag that indicates when the private data object should be excluded from the resulting data set. | ||
| * - **scan**: A booly flag that indicates whether members of the current data object should be added to the queue. | ||
| * - **exit**: A booly flag that indicates when the queue should be abandoned. | ||
| * - **parent**: An object to use as the parent argument, when processing any members of the current data object. | ||
| */ | ||
| parserFlags = { | ||
| parent: 0, // auto, by default | ||
| omit: 0, // false, by default | ||
| scan: 1, // truthy, by default | ||
| exit: 0 // falsy, by default | ||
| // falsy, by default | ||
| omit: 0 | ||
| // truthy, by default | ||
| , scan: 1 | ||
| // falsy, by default | ||
| , exit: 0 | ||
| // instructs genData to use the data object as the parent, by default | ||
| , parent: 0 | ||
| }; | ||
| /** | ||
| * Define the arguments for all _parsers_. | ||
| * Here we define an array of arguments, that are passed to each parser function. Below are the parameters names and argument values passed to parser functions. | ||
| * | ||
| * 1. Original data name | ||
| * 2. Original data value | ||
| * 3. The parent data object (if any) | ||
| * 4. The dataset array | ||
| * 5. The flags object | ||
| * 1. **name** A string representing the original value of the scope/data object's `.name` property. | ||
| * 2. **value** A JavaScript value representing the original value of the scope/data object's `.value` property. | ||
| * 3. **parent** An object representing the container for the name-value pair that defines the scope/data object. | ||
| * 4. **dataset** The final array that will be returned by the orginal genData call. | ||
| * 5. **flags** An object whose key/value pairs control genData's iteration and parisng behavior. | ||
| * 6. **shared** An object whose key/value pairs are preserved between processing each data object. | ||
| */ | ||
| args = [ | ||
| dataInstance.name, // a string | ||
| dataInstance.value, // mixed type | ||
| queueItem[2], // a data object | ||
| dataset, // an array | ||
| parserFlags, // an object | ||
| sharedVars // shared variable container | ||
| // the orginal name | ||
| queueItem[0] | ||
| // the original value | ||
| , queueItem[1] | ||
| // the parent to the scope/data object | ||
| , queueItem[2] | ||
| // the array returned by genData | ||
| , dataset | ||
| // a collection of parser flags | ||
| , parserFlags | ||
| // an object, preserved between iterations | ||
| , sharedVars | ||
| ]; | ||
| /** | ||
| * Now pass arguments to each parser, unless one trips the "exit" flag. | ||
| * Now we begin another loop to invoke each parser function. This loop continues until all parsers are invoked, or the `parserFlags.exit` is true. | ||
| * | ||
| * After parsing the data object, we observe the `parserFlags`. | ||
| */ | ||
| while (currentParserIndex < totalParsers && !parserFlags.exit) { | ||
| // invoke each parser with the data object as it's scope, and the predefined arguments | ||
| parsers[currentParserIndex++].apply(dataInstance, args); | ||
| } | ||
| /** | ||
| * Observe the "omit" flag, to determine whether `data` will be returned with the dataset. | ||
| * The "omit" flag determines whether the original data object will be added to the dataset. | ||
| * | ||
| * (Excluded data objects are tagged, in case they are referenced later.) | ||
| * (Omitted data objects are tagged, in case they are referenced later.) | ||
| */ | ||
| // if omitting this data object... | ||
| if (parserFlags.omit) { | ||
| // tag this instance, in case it is used later | ||
| dataInstance._OMIT = true; | ||
| } else { | ||
| } else { // (otherwise) when including this data object... | ||
| // add this object to the dataset | ||
| dataset.push(dataInstance); | ||
| } | ||
| // if exiting... | ||
| /** | ||
| * Observe the "exit" flag, which - when truthy - aborts processing the queue... | ||
| * The "exit" flag determines when to stop processing the queue. | ||
| * | ||
| * When truthy, the `queue` array is emptied, which will cause the iteration loop to exit. | ||
| */ | ||
| // if exiting... | ||
| if (parserFlags.exit) { | ||
| // clear the queue | ||
| queue = []; | ||
| } | ||
| /** | ||
| * If falsy, we next observe the "scan" flag, queuing parameters of future Data objects, for each non-inherited member from the current data object's value. | ||
| * When the "exit" flag is falsy, continue parsing this data object. | ||
| * | ||
| * A temporary buffer queues these members in first-to-last order. | ||
| * The "scan" flag determines whether the members of the final value should also be scanned. If so, all non-inherited members are add to a temporary `queueBuffer` array, which is ultimately added to the original queue. | ||
| * | ||
| * We also capture the parent in the queue. That is, the object containing the found members - unless an override object is given by `parentFlags.parent`. | ||
| */ | ||
| else { | ||
| } else { // (otherwise) when not exiting the queue-processing loop... | ||
| // reset the queueBuffer | ||
| queueBuffer = []; | ||
| // if allowed to scan this object... | ||
| if (parserFlags.scan && typeof dataInstance.value === 'object') { | ||
| // resolve what object will be given to parser functions, as the parent paraneter | ||
| parentRef = typeof parserFlags.parent === 'object' ? parserFlags.parent : dataInstance; | ||
| // with each member of the object... | ||
| for (memberName in dataInstance.value) { | ||
| // if the member is not-inherited... | ||
| if (dataInstance.value.hasOwnProperty(memberName)) { | ||
| // add to the temporary queue buffer | ||
| queueBuffer.push([ | ||
| memberName, // _name_ passed to "new Data()" | ||
| dataInstance.value[memberName], // _value_ passed to "new Data()" | ||
| parentRef // _parent_ (argument [2]) passed to parsers | ||
| // the _name_ argument for a new Data object | ||
| memberName | ||
| // the _value_ argument for a new Data object | ||
| , dataInstance.value[memberName] | ||
| // the parent argument passed to parsers | ||
| , parentRef | ||
| ]); | ||
@@ -158,60 +208,97 @@ } | ||
| } | ||
| // prepend the existing queue with these "child" members of the current data object | ||
| queue = queueBuffer.concat(queue); | ||
| } | ||
| /** | ||
| * Wrap up the queue-loop, and return the resulting dataset | ||
| * Ultimately, when iterating and parsing an object, genData will return an array, called the dataset. | ||
| */ | ||
| } | ||
| return dataset; | ||
| } | ||
| /** | ||
| * When called with `new` and passed an argument, genData returns a _generator_, or curried function. | ||
| * When genData is called with the `new` operator _and_ given an argument, it returns a curried `genData` function that also extends the prototype chain, called a "generator". Generators behave exactly like the genData function, which means that generators can spawn generators. This lets you compound various parser combinations and branch specific prototype chains. | ||
| * | ||
| * The following signatures spawn a generator (from either genData or an existing generator): | ||
| * | ||
| * 1. `var generator1 = new genData(dataModel, parsers);` | ||
| * 2. `var generator2 = new genData(parser [, parser]);` | ||
| * | ||
| * The first form requires **parsers** to be an array, in order for the first argument to be recognized as **dataModel**. If one or more functions are given, they will all be considered individual parser functions. | ||
| * | ||
| * _Note:_ The signature validation for this use of genData (and generator functions) is weak. | ||
| */ | ||
| else if (stuff) { | ||
| /** | ||
| * Handles the following argument signatures: | ||
| * | ||
| * 1. `new genData(dataModel, parsersArray)` | ||
| * 2. `new genData(parser1 [, parserN])` | ||
| */ | ||
| } else if (stuff) { // or, when called with `new` and given any argument... | ||
| // if the second argument is an array... | ||
| if (~{}.toString.call(args[1]).indexOf('y')) { | ||
| // assume the first argument is a function | ||
| dataModel = stuff; | ||
| // assume the second argument is an array of parser functions | ||
| args = args[1]; | ||
| } | ||
| // capture and ensure that parsers is an array (since args may be the raw arguments object) | ||
| parsers = parsers.concat([].slice.call(args)); | ||
| /** | ||
| * Define a curry-like function that mimics genData's forking logic. | ||
| * Ultimately, this curry-like function calls genData to do the actual normalization. | ||
| * This is the curry function returned when spawning a generator. | ||
| * | ||
| * The function mimics genData's forking logic, based on it's signature, then calls genData with it's curried arguments. Each generator spawned will extend the prototype chain of the previous generator. This allows you to prototype methods to all generators when spawned from genData (i.e., without passing in your own constructor). | ||
| * | ||
| * **Example:** | ||
| * | ||
| * This example demonstrates how dataset objects, from generators, share the **genData** prototype chain. (This example assumes that `myParser` and `anotherParser` are pre-existing functions.) | ||
| * | ||
| * var | ||
| * genFoo = new genData(myParser) | ||
| * , fooSet = genFoo('anything') | ||
| * , genBar = new genData(anotherParser) | ||
| * , barSet = genBar('something else') | ||
| * ; | ||
| * genData.prototype.hello = function () {return 'hello world'}; | ||
| * return typeof barSet[0].hello === 'function' && barSet[0].hello === 'function'; // true | ||
| * | ||
| */ | ||
| function Generator(stuff, moreParsers, newModel) { | ||
| var moreParsersIsArray = ~{}.toString.call(moreParsers).indexOf('y'); | ||
| var | ||
| // flag when the second argument is an array | ||
| moreParsersIsArray = ~{}.toString.call(moreParsers).indexOf('y') | ||
| ; | ||
| // if called without the `new` statement... | ||
| if (!(this instanceof Generator)) { | ||
| // return result of calling genData with the curried arguments | ||
| return origFnc( | ||
| // the data to parse | ||
| stuff, | ||
| // combine the curried parsers with any additional parsers | ||
| parsers.concat(moreParsers || []), | ||
| // use the given function or this function's prototype | ||
| newModel ? newModel : Generator | ||
| ); | ||
| } else if (stuff) { | ||
| } else if (stuff) { // or, when called with the `new` statement and given an argument... | ||
| // return result of spawning a generator with the curried arguments | ||
| return new origFnc( | ||
| // use the given function or this function's prototype | ||
| moreParsersIsArray ? stuff : Generator, | ||
| // combine the curried parsers with any additional parsers | ||
| parsers.concat( | ||
| // when adding an array to the curried parsers... | ||
| moreParsersIsArray ? | ||
| moreParsers : | ||
| [].slice.call(arguments) | ||
| // add it directly | ||
| moreParsers : | ||
| // otherwise, consider all the arguments to be parsers and add them to the curried parsers | ||
| [].slice.call(arguments) | ||
| ) | ||
| ); | ||
| } | ||
| // otherwise, return standard instance from invoking a constructor with the `new` statement | ||
| return this; | ||
| } | ||
| /** | ||
| * Chain this function to a given prototype, and return it as a genData _generator_. | ||
| */ | ||
| Generator.prototype = isDataModelConstructor ? new dataModel() : dataModel; | ||
| // extend the dataModel when it's a function, otherwise just point to it | ||
| Generator.prototype = typeof dataModel === 'function' ? new dataModel() : dataModel; | ||
| // return the curry function | ||
| return Generator; | ||
| } | ||
| /** | ||
| * Finally, if invoked with `new` but given no arguments, we return an instance of genData. | ||
| * This signature would be used for prototyping chaining. | ||
| * This code block is reached when genData is invoked with the `new` statement, but not given any arguments. The returned instance mimics the behavior expected when initializing an object with a regular constructor function. | ||
| * | ||
| * This behavior exists so that we can extend genData's protoype chain - traditional chaining requires instantiating the constructor. | ||
| */ | ||
| return this; | ||
| }; |
| module('Basics'); | ||
| test('Presence', 2, function () { | ||
| equal(typeof genData, 'function', 'genData is a function.'); | ||
| equal(genData.length, 1, 'genData expects one or more parameters.'); | ||
| }); | ||
| test('Dataset', 5, function () { | ||
| var dataset = genData(); | ||
| ok(dataset instanceof Array, "The dataset returned by genData is an array."); | ||
| ok(dataset[0].hasOwnProperty('name'), 'Each data object has a "name" member.'); | ||
| equal(typeof dataset[0].name, 'string', 'The "name" member is a string.'); | ||
| ok(dataset[0].hasOwnProperty('value'), 'Each data object has a "value" member.'); | ||
| strictEqual(dataset[0].name, '', 'By default, the first data object\'s "name" member is an empty string.'); | ||
| }); | ||
| module('Normalize'); | ||
| test("nothing", 2, function () { | ||
| var dataset = genData(), | ||
| undefSet = genData(undefined); | ||
| equal(dataset.length, 1, 'genData returns a dataset with one item, when passed nothing or "undefined".'); | ||
| deepEqual(dataset, undefSet, 'Passing nothing or undefined, results in the same dataset.'); | ||
| }); | ||
| test("objects", 3, function () { | ||
| var bar = {}, | ||
| stuff = { | ||
| foo: bar, | ||
| ping: 'pong' | ||
| }, | ||
| dataset = genData(stuff); | ||
| equal(dataset.length, (function () { | ||
| var cnt = 0, i; | ||
| for (i in stuff) { | ||
| if (stuff.hasOwnProperty(i)) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt; | ||
| })() + 1, 'The normalized object has the expected number of data objects.'); | ||
| strictEqual(dataset[0].value, stuff, 'The value of the first data object references the first argument passed to genData.'); | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name:'',value:stuff}, {name:'foo',value:bar}, {name:'ping',value:'pong'}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the object into the expected dataset format.'); | ||
| }); | ||
| test('arrays', function () { | ||
| var stuff = ['alpha', 'beta', 'disco', 'theta'], | ||
| dataset = genData(stuff), | ||
| nbrNames = 0, | ||
| i = 0, datasetCnt = dataset.length; | ||
| equal(datasetCnt, stuff.length + 1, 'The normalized array has the expected number of data objects.'); | ||
| for (; i < datasetCnt; i++) { | ||
| if (dataset[i].name == i - 1) { | ||
| nbrNames++; | ||
| } | ||
| } | ||
| equal(nbrNames, stuff.length, 'The array element\'s index becomes the "name" member.'); | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name: '', value: stuff}, {name:'0', value:'alpha'}, {name:'1',value:'beta'}, {name:'2',value:'disco'}, {name:'3',value:'theta'}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the array into the expected dataset format.'); | ||
| }); | ||
| test('associative-arrays', 3, function () { | ||
| var stuff = [], | ||
| assocKeyValue = 'pong', | ||
| assocKeyName = 'ping', | ||
| dataset, | ||
| i = 0, datasetCnt; | ||
| stuff[assocKeyName] = assocKeyValue; | ||
| dataset = genData(stuff); | ||
| datasetCnt = dataset.length; | ||
| equal(datasetCnt, stuff.length + 2, 'The normalized associative-array has the expected number of data objects.'); | ||
| for (; i < datasetCnt; i++) { | ||
| if (dataset[i].name === assocKeyName) { | ||
| equal(dataset[i].value, assocKeyValue, 'genData creates data objects for non-indexed members of an associative array.'); | ||
| break; | ||
| } | ||
| } | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name: '', value: stuff}, {name:assocKeyName, value:assocKeyValue}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the associative-array into the expected dataset format.'); | ||
| }); | ||
| test('functions', 2, function () { | ||
| var stuff = function () {}, | ||
| dataset = genData(stuff); | ||
| equal(dataset.length, 1, 'The normalized function has the expected number of data objects.'); | ||
| strictEqual(dataset[0].value, stuff, 'The first data object value is the function.'); | ||
| }); | ||
| test('mixed object', 2, function () { | ||
| var potAryFnc = function () {}, | ||
| potAry = [ | ||
| 'kettle', | ||
| potAryFnc | ||
| ], | ||
| stuff = { | ||
| foo: 'bar', | ||
| pot: potAry | ||
| }, | ||
| dataset = genData(stuff); | ||
| equal(dataset.length, 5, 'The normalized mixed-object has the expected number of data objects.'); | ||
| ok(!!function () { | ||
| var i = 0, cnt = 0, | ||
| ds = [{name: '', value: stuff}, {name:'foo', value:'bar'}, {name:'pot', value:potAry}, {name:'0', value:'kettle'}, {name:'1', value:potAryFnc}]; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === ds[i].name && dataset[i].value === ds[i].value) { | ||
| cnt++; | ||
| } | ||
| } | ||
| return cnt === dataset.length; | ||
| }, 'genData normalized the mixed-object into the expected dataset format.'); | ||
| }); | ||
| test('depth-first ordered tree', 1, function () { | ||
| var stuff = { | ||
| foo: { | ||
| bop: 10, | ||
| echo: { | ||
| lucky: 20, | ||
| happy: 30 | ||
| }, | ||
| code: [ | ||
| 40, | ||
| 50 | ||
| ] | ||
| }, | ||
| loop: 60 | ||
| }, | ||
| dsOrder = [ | ||
| '', | ||
| 'foo', | ||
| 'bop', | ||
| 'echo', | ||
| 'lucky', | ||
| 'happy', | ||
| 'code', | ||
| '0', | ||
| '1', | ||
| 'loop' | ||
| ], | ||
| dsOrderTest = 0, | ||
| dataset = genData(stuff), | ||
| i = 0; | ||
| for (; i < dataset.length; i++) { | ||
| if (dataset[i].name === dsOrder[i]) { | ||
| dsOrderTest++; | ||
| } | ||
| } | ||
| equal(dsOrder.length, dsOrderTest, 'Each data object occurs in the expected order.'); | ||
| }); | ||
| module('Parsers'); | ||
| test('scope and signature', function () { | ||
| genData('anything', function (name, value, parent, dataset, flags) { | ||
| var args = arguments; | ||
| equal(this.constructor, genData, 'scope is a genData instance'); | ||
| equal(args.length, 6, 'has expected number of arguments'); | ||
| equal(typeof name, 'string', 'name is a string'); | ||
| if (dataset.length) { | ||
| equal(typeof parent, 'object', 'parent is an object'); | ||
| equal(parent.constructor, genData, 'parent is a genData instance'); | ||
| } else { | ||
| ok(!parent, 'the first data object has no parent'); | ||
| } | ||
| equal(typeof flags, 'object', 'flags is an object'); | ||
| ok(flags.hasOwnProperty('omit'), 'omit flag is present'); | ||
| ok(!flags.omit, 'omit flag is false by default'); | ||
| ok(flags.hasOwnProperty('scan'), 'scan flag is present'); | ||
| ok(flags.scan, 'scan flag is true by default'); | ||
| ok(flags.hasOwnProperty('exit'), 'exit flag is present'); | ||
| ok(!flags.exit, 'exit flag is false by default'); | ||
| }); | ||
| }); | ||
| test('one function as second argument', function () { | ||
| genData('anything', function () { | ||
| ok(true, 'parser called'); | ||
| }); | ||
| }); | ||
| test('an array of functions as second argument', function () { | ||
| genData( | ||
| 'anything', | ||
| [ | ||
| function () { | ||
| ok(true, 'first parser called'); | ||
| }, | ||
| function () { | ||
| ok(true, 'second parser called'); | ||
| } | ||
| ] | ||
| ); | ||
| }); | ||
| test('add property', function () { | ||
| var propName = 'id', | ||
| dataset = genData('anything', function () { | ||
| this[propName] = Math.random(); | ||
| }), | ||
| data = dataset[0]; | ||
| ok(data.hasOwnProperty(propName), 'added property'); | ||
| equal(typeof data[propName], 'number', 'property is a number'); | ||
| }); | ||
| test('remove properties', function () { | ||
| var dataset = genData([1,2,3], function () { | ||
| delete this.name; | ||
| delete this.value; | ||
| }), | ||
| i = 0, datasetCnt = dataset.length; | ||
| ok(datasetCnt, 'data objects were returned'); | ||
| for (; i < datasetCnt; i++) { | ||
| ok(!dataset[i].hasOwnProperty('name'), 'the name property was removed'); | ||
| ok(!dataset[i].hasOwnProperty('value'), 'the value property was removed'); | ||
| } | ||
| }); | ||
| test('preserving original value between parsers', function () { | ||
| var originalValue = 'foo'; | ||
| genData( | ||
| originalValue, | ||
| [ | ||
| function (name, value) { | ||
| equal(value, this.value, 'data.value matches the value parameter'); | ||
| equal(value, originalValue, 'value matches the original value'); | ||
| this.value = 'somethingelse'; | ||
| notEqual(value, this.value, 'data.value has been changed'); | ||
| }, | ||
| function (name, value) { | ||
| equal(value, originalValue, 'value still matches the original value'); | ||
| notEqual(value, this.value, 'data.value no longer matches the original value'); | ||
| } | ||
| ] | ||
| ); | ||
| }); | ||
| test('preserving shared object between parsers and iterations', 5, function () { | ||
| var sharedSet = 0, | ||
| sharedRef, | ||
| parser = function (name, value, parent, dataset, flags, shared) { | ||
| if (!sharedSet) { | ||
| sharedSet = 1; | ||
| ok(typeof shared === 'object', 'shared argument is an object'); | ||
| shared.idx = 0; | ||
| sharedRef = shared; | ||
| } else { | ||
| shared.idx++; | ||
| ok(shared === sharedRef, 'shared object is the same'); | ||
| } | ||
| }; | ||
| genData( | ||
| [1], | ||
| [ | ||
| parser, | ||
| parser | ||
| ] | ||
| ); | ||
| equal(sharedRef.idx, 3, 'parsers see same shared object between iterations'); | ||
| }); | ||
| test('flags.parent', function () { | ||
| var passParentFnc = function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = parent; | ||
| }, | ||
| sampleData = [[1]], | ||
| simpleSet = genData(sampleData, passParentFnc), | ||
| genChain = new genData(passParentFnc), | ||
| chainSet = genChain(sampleData), | ||
| model = function () {}, | ||
| modelSet = genData(sampleData, passParentFnc, model), | ||
| failSetFalsy = genData(sampleData, function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = 0; | ||
| }), | ||
| failSetTruthy = genData(sampleData, function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = 1; | ||
| }), | ||
| failSetObject = genData(sampleData, function (name, value, parent, dataset, flags) { | ||
| this.parent = parent; | ||
| flags.parent = {}; | ||
| }); | ||
| equal(simpleSet[1].parent, simpleSet.pop().parent, 'parent change works'); | ||
| equal(chainSet[1].parent, chainSet.pop().parent, 'parent may be instanceof genData'); | ||
| equal(modelSet[1].parent, modelSet.pop().parent, 'parent may be the substituted model'); | ||
| notEqual(failSetFalsy[1].parent, failSetFalsy.pop().parent, 'flags.parent can not be falsy'); | ||
| notEqual(failSetTruthy[1].parent, failSetTruthy.pop().parent, 'flags.parent can not be truthy'); | ||
| notEqual(failSetObject[1].parent, failSetObject.pop().parent, 'flags.parent can not be any object'); | ||
| }); | ||
| test('flags.omit', function () { | ||
| var dataset = genData([1,2,3], function (name, value, parent, dataset, flags) { | ||
| flags.omit = 1; | ||
| if (parent) { | ||
| ok(parent.hasOwnProperty('_OMIT'), 'omitted data objects are flagged'); | ||
| strictEqual(parent._OMIT, true, 'the _OMIT flag is true'); | ||
| } | ||
| }); | ||
| equal(dataset.length, 0, 'dataset has no data objects'); | ||
| }); | ||
| test('flags.scan', function () { | ||
| var stuff = [1,2,3], | ||
| dataset = genData(stuff, function (name, value, parent, dataset, flags) { | ||
| flags.scan = 0; | ||
| }); | ||
| equal(dataset[0].value, stuff, 'first data object has an enumerable value') | ||
| equal(dataset.length, 1, 'member properties were not scanned'); | ||
| }); | ||
| test('flags.exit', function () { | ||
| var tic = 0; | ||
| genData(1, | ||
| [ | ||
| function (name, value, parent, dataset, flags) { | ||
| flags.exit = 1; | ||
| }, | ||
| function () { | ||
| tic = 1; | ||
| } | ||
| ] | ||
| ), | ||
| stuff = [1,2,3], | ||
| dataset = genData(stuff), | ||
| exitSet = genData(stuff, function (name, value, parent, dataset, flags) { | ||
| flags.exit = 1; | ||
| }); | ||
| ok(!tic, 'second parser was skipped'); | ||
| equal(1, exitSet.length, 'only one data object was created'); | ||
| notEqual(dataset.length, exitSet, 'exit flag reduced the number of data objects created'); | ||
| }); | ||
| test('alter the dataset', function () { | ||
| var stuff = 1, | ||
| fauxValues = ['hello', 'world'], | ||
| dataset = genData(stuff, | ||
| function (name, value, parent, dataset, flags) { | ||
| flags.omit = 1; | ||
| dataset.splice(0, dataset.length, 'hello', 'world'); | ||
| } | ||
| ); | ||
| notEqual(typeof stuff, 'object', 'the parsed value has no enumerable members'); | ||
| deepEqual(dataset, fauxValues, 'final dataset has been augmented'); | ||
| }); | ||
| module('Generator'); | ||
| test('spawning', 7, function () { | ||
| var tic = 0, | ||
| parser = function () { | ||
| ok(1, 'parser passed from generator to genData'); | ||
| }, | ||
| gen = new genData(parser), | ||
| tmp = genData, | ||
| dataset; | ||
| ok(typeof gen === 'function', 'returns a function'); | ||
| genData = function () { | ||
| tic = 1; | ||
| }; | ||
| dataset = gen(1); // should fire assertion in parser() | ||
| equal(tic, 0 , 'generator is a closured call'); | ||
| genData = tmp; | ||
| gen(1, parser); | ||
| gen(1, [parser]); | ||
| }); | ||
| test('signature', 5, function () { | ||
| var val = 8, | ||
| fnc = function () { | ||
| this.id = val; | ||
| }, | ||
| genX = new genData(fnc), | ||
| model = function () {}, | ||
| genXY = new genX(fnc), | ||
| genXYZ = new genX(fnc, fnc); | ||
| equal('function', typeof genXY, 'can spawn generator passing one parser'); | ||
| equal('function', typeof genXYZ, 'can spawn generator passing more parsers'); | ||
| equal(val, genX(1, fnc)[0].id, 'accepts a single parser'); | ||
| equal(val, genX(1, [fnc, fnc])[0].id, 'accepts an array of parsers'); | ||
| ok(genX(1, [], model)[0] instanceof model, 'accepts a base model'); | ||
| }); | ||
| test('compounding', function () { | ||
| var strStart = 'foo', | ||
| strEnd = strStart.toUpperCase(), | ||
| idF = function () { | ||
| this.id = strStart; | ||
| }, | ||
| upperF = function () { | ||
| this.id = this.id.toUpperCase(); | ||
| }, | ||
| genId = new genData(idF), | ||
| genUpper = new genId(upperF), | ||
| dataCompound = genUpper(1)[0], | ||
| dataManual = genData( | ||
| 1, | ||
| [ | ||
| idF, | ||
| upperF | ||
| ] | ||
| )[0]; | ||
| equal(strEnd, dataCompound.id, 'the second generator added to the the first'); | ||
| equal(strEnd, dataManual.id, 'manual result matches compound generator'); | ||
| }); | ||
| module('Prototype'); | ||
| test('chaining', function () { | ||
| var emptyFnc = function () {}, | ||
| genAnimal = new genData(emptyFnc), | ||
| genDog = new genAnimal(emptyFnc), | ||
| genFruit = new genData(emptyFnc), | ||
| dog = genDog(1)[0], | ||
| fruit = genFruit(1)[0]; | ||
| ok(dog instanceof genAnimal, 'dog comes from animal generator'); | ||
| ok(dog instanceof genDog, 'dog comes from dog generator'); | ||
| ok(dog instanceof genData, 'dog comes from genData'); | ||
| ok(fruit instanceof genFruit, 'fruit comes from fruit generator'); | ||
| ok(fruit instanceof genData, 'fruit comes from genData'); | ||
| }); | ||
| test('methods', function () { | ||
| var stuff = {foo:'bar'}, | ||
| gen = new genData(function () {}), | ||
| dataset = gen(stuff); | ||
| ok(typeof dataset[0].getValue === 'undefined', 'no getValue method present'); | ||
| genData.prototype.getValue = function () { | ||
| ok(this instanceof genData, 'scope is a genData instance'); | ||
| return this.value; | ||
| }; | ||
| ok(typeof dataset[0].getValue === 'function', 'getValue method exists now'); | ||
| ok(typeof dataset[0].toUpperCase === 'undefined', 'no spawned method present'); | ||
| gen.prototype.toUpperCase = function () { | ||
| ok(this instanceof gen, 'scope is a gen instance'); | ||
| return this.getValue().toUpperCase(); | ||
| }; | ||
| ok(typeof dataset[0].toUpperCase === 'function', 'spawned method exists now'); | ||
| strictEqual(stuff, dataset[0].getValue(), 'genData prototyped method works'); | ||
| strictEqual(stuff.foo.toUpperCase(), dataset[1].toUpperCase(), 'generator prototyped method sees chained methods'); | ||
| // clean up! | ||
| delete genData.prototype.getValue; | ||
| ok(typeof dataset[0].getValue === 'undefined', 'removed prototyped method from genData'); | ||
| }); | ||
| test('substitute base models', function () { | ||
| var tic = 0, | ||
| emptyFnc = function () {}, | ||
| parser = function () { | ||
| tic++; | ||
| }, | ||
| myModel = function () {}, | ||
| dataModel = genData(1, [parser], myModel), | ||
| gen = new genData(parser), | ||
| dataGen = gen(1,[parser], myModel), | ||
| finalTic = 3; | ||
| myModel.prototype.getValue = function () { | ||
| ok(this instanceof myModel, 'scope is an instance of the substitute constructor'); | ||
| return this.value; | ||
| }; | ||
| gen.prototype.hidden = emptyFnc; | ||
| ok(dataModel[0] instanceof myModel, 'can use prototype of a given constructor'); | ||
| ok(!(dataModel[0] instanceof genData), 'substitution kills link to genData'); | ||
| ok(dataGen[0] instanceof myModel, 'generators support prototype substitution'); | ||
| ok(!(dataGen[0] instanceof genData), 'generator substitutions also kill link to genData'); | ||
| ok(typeof dataModel[0].getValue === 'function', 'substitute prototype methods are accessible'); | ||
| ok(typeof dataGen[0].hidden === 'undefined', 'generator and genData methods not available with custom prototypes'); | ||
| equal(1, dataModel[0].getValue(), 'substitute prototype methods work'); | ||
| equal(finalTic, tic, 'Parsers fire during prototype substitution'); | ||
| }); |
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>genData Test Suite</title> | ||
| <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen"> | ||
| <script type="text/javascript" src="qunit/qunit.js"></script> | ||
| <script type="text/javascript" src="../gendata-min.js"></script> | ||
| </head> | ||
| <body> | ||
| <h1 id="qunit-header">genData Test Suite</h1> | ||
| <h2 id="qunit-banner"></h2> | ||
| <div id="qunit-testrunner-toolbar"></div> | ||
| <h2 id="qunit-userAgent"></h2> | ||
| <ol id="qunit-tests"></ol> | ||
| <!-- Place below elements required by qunit --> | ||
| <script type="text/javascript" src="gendata_tests.js"></script> | ||
| </body> | ||
| </html> |
| /** | ||
| * QUnit - A JavaScript Unit Testing Framework | ||
| * | ||
| * http://docs.jquery.com/QUnit | ||
| * | ||
| * Copyright (c) 2011 John Resig, Jörn Zaefferer | ||
| * Dual licensed under the MIT (MIT-LICENSE.txt) | ||
| * or GPL (GPL-LICENSE.txt) licenses. | ||
| */ | ||
| /** Font Family and Sizes */ | ||
| #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { | ||
| font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; | ||
| } | ||
| #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } | ||
| #qunit-tests { font-size: smaller; } | ||
| /** Resets */ | ||
| #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| /** Header */ | ||
| #qunit-header { | ||
| padding: 0.5em 0 0.5em 1em; | ||
| color: #8699a4; | ||
| background-color: #0d3349; | ||
| font-size: 1.5em; | ||
| line-height: 1em; | ||
| font-weight: normal; | ||
| border-radius: 15px 15px 0 0; | ||
| -moz-border-radius: 15px 15px 0 0; | ||
| -webkit-border-top-right-radius: 15px; | ||
| -webkit-border-top-left-radius: 15px; | ||
| } | ||
| #qunit-header a { | ||
| text-decoration: none; | ||
| color: #c2ccd1; | ||
| } | ||
| #qunit-header a:hover, | ||
| #qunit-header a:focus { | ||
| color: #fff; | ||
| } | ||
| #qunit-banner { | ||
| height: 5px; | ||
| } | ||
| #qunit-testrunner-toolbar { | ||
| padding: 0.5em 0 0.5em 2em; | ||
| color: #5E740B; | ||
| background-color: #eee; | ||
| } | ||
| #qunit-userAgent { | ||
| padding: 0.5em 0 0.5em 2.5em; | ||
| background-color: #2b81af; | ||
| color: #fff; | ||
| text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; | ||
| } | ||
| /** Tests: Pass/Fail */ | ||
| #qunit-tests { | ||
| list-style-position: inside; | ||
| } | ||
| #qunit-tests li { | ||
| padding: 0.4em 0.5em 0.4em 2.5em; | ||
| border-bottom: 1px solid #fff; | ||
| list-style-position: inside; | ||
| } | ||
| #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { | ||
| display: none; | ||
| } | ||
| #qunit-tests li strong { | ||
| cursor: pointer; | ||
| } | ||
| #qunit-tests li a { | ||
| padding: 0.5em; | ||
| color: #c2ccd1; | ||
| text-decoration: none; | ||
| } | ||
| #qunit-tests li a:hover, | ||
| #qunit-tests li a:focus { | ||
| color: #000; | ||
| } | ||
| #qunit-tests ol { | ||
| margin-top: 0.5em; | ||
| padding: 0.5em; | ||
| background-color: #fff; | ||
| border-radius: 15px; | ||
| -moz-border-radius: 15px; | ||
| -webkit-border-radius: 15px; | ||
| box-shadow: inset 0px 2px 13px #999; | ||
| -moz-box-shadow: inset 0px 2px 13px #999; | ||
| -webkit-box-shadow: inset 0px 2px 13px #999; | ||
| } | ||
| #qunit-tests table { | ||
| border-collapse: collapse; | ||
| margin-top: .2em; | ||
| } | ||
| #qunit-tests th { | ||
| text-align: right; | ||
| vertical-align: top; | ||
| padding: 0 .5em 0 0; | ||
| } | ||
| #qunit-tests td { | ||
| vertical-align: top; | ||
| } | ||
| #qunit-tests pre { | ||
| margin: 0; | ||
| white-space: pre-wrap; | ||
| word-wrap: break-word; | ||
| } | ||
| #qunit-tests del { | ||
| background-color: #e0f2be; | ||
| color: #374e0c; | ||
| text-decoration: none; | ||
| } | ||
| #qunit-tests ins { | ||
| background-color: #ffcaca; | ||
| color: #500; | ||
| text-decoration: none; | ||
| } | ||
| /*** Test Counts */ | ||
| #qunit-tests b.counts { color: black; } | ||
| #qunit-tests b.passed { color: #5E740B; } | ||
| #qunit-tests b.failed { color: #710909; } | ||
| #qunit-tests li li { | ||
| margin: 0.5em; | ||
| padding: 0.4em 0.5em 0.4em 0.5em; | ||
| background-color: #fff; | ||
| border-bottom: none; | ||
| list-style-position: inside; | ||
| } | ||
| /*** Passing Styles */ | ||
| #qunit-tests li li.pass { | ||
| color: #5E740B; | ||
| background-color: #fff; | ||
| border-left: 26px solid #C6E746; | ||
| } | ||
| #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } | ||
| #qunit-tests .pass .test-name { color: #366097; } | ||
| #qunit-tests .pass .test-actual, | ||
| #qunit-tests .pass .test-expected { color: #999999; } | ||
| #qunit-banner.qunit-pass { background-color: #C6E746; } | ||
| /*** Failing Styles */ | ||
| #qunit-tests li li.fail { | ||
| color: #710909; | ||
| background-color: #fff; | ||
| border-left: 26px solid #EE5757; | ||
| } | ||
| #qunit-tests > li:last-child { | ||
| border-radius: 0 0 15px 15px; | ||
| -moz-border-radius: 0 0 15px 15px; | ||
| -webkit-border-bottom-right-radius: 15px; | ||
| -webkit-border-bottom-left-radius: 15px; | ||
| } | ||
| #qunit-tests .fail { color: #000000; background-color: #EE5757; } | ||
| #qunit-tests .fail .test-name, | ||
| #qunit-tests .fail .module-name { color: #000000; } | ||
| #qunit-tests .fail .test-actual { color: #EE5757; } | ||
| #qunit-tests .fail .test-expected { color: green; } | ||
| #qunit-banner.qunit-fail { background-color: #EE5757; } | ||
| /** Result */ | ||
| #qunit-testresult { | ||
| padding: 0.5em 0.5em 0.5em 2.5em; | ||
| color: #2b81af; | ||
| background-color: #D2E0E6; | ||
| border-bottom: 1px solid white; | ||
| } | ||
| /** Fixture */ | ||
| #qunit-fixture { | ||
| position: absolute; | ||
| top: -10000px; | ||
| left: -10000px; | ||
| } |
| /** | ||
| * QUnit - A JavaScript Unit Testing Framework | ||
| * | ||
| * http://docs.jquery.com/QUnit | ||
| * | ||
| * Copyright (c) 2011 John Resig, Jörn Zaefferer | ||
| * Dual licensed under the MIT (MIT-LICENSE.txt) | ||
| * or GPL (GPL-LICENSE.txt) licenses. | ||
| */ | ||
| (function(window) { | ||
| var defined = { | ||
| setTimeout: typeof window.setTimeout !== "undefined", | ||
| sessionStorage: (function() { | ||
| try { | ||
| return !!sessionStorage.getItem; | ||
| } catch(e){ | ||
| return false; | ||
| } | ||
| })() | ||
| }; | ||
| var testId = 0; | ||
| 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.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++; | ||
| tests.appendChild( li ); | ||
| } | ||
| }, | ||
| setup: function() { | ||
| if (this.module != config.previousModule) { | ||
| if ( config.previousModule ) { | ||
| QUnit.moduleDone( { | ||
| name: config.previousModule, | ||
| failed: config.moduleStats.bad, | ||
| passed: config.moduleStats.all - config.moduleStats.bad, | ||
| total: config.moduleStats.all | ||
| } ); | ||
| } | ||
| config.previousModule = this.module; | ||
| config.moduleStats = { all: 0, bad: 0 }; | ||
| QUnit.moduleStart( { | ||
| name: this.module | ||
| } ); | ||
| } | ||
| config.current = this; | ||
| this.testEnvironment = extend({ | ||
| setup: function() {}, | ||
| teardown: function() {} | ||
| }, this.moduleTestEnvironment); | ||
| if (this.testEnvironmentArg) { | ||
| extend(this.testEnvironment, this.testEnvironmentArg); | ||
| } | ||
| QUnit.testStart( { | ||
| name: this.testName | ||
| } ); | ||
| // allow utility functions to access the current test environment | ||
| // TODO why?? | ||
| QUnit.current_testEnvironment = this.testEnvironment; | ||
| try { | ||
| if ( !config.pollution ) { | ||
| saveGlobal(); | ||
| } | ||
| this.testEnvironment.setup.call(this.testEnvironment); | ||
| } catch(e) { | ||
| QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message ); | ||
| } | ||
| }, | ||
| run: function() { | ||
| if ( this.async ) { | ||
| QUnit.stop(); | ||
| } | ||
| if ( config.notrycatch ) { | ||
| this.callback.call(this.testEnvironment); | ||
| 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) ); | ||
| // else next test will carry the responsibility | ||
| saveGlobal(); | ||
| // Restart the tests if they're blocking | ||
| if ( config.blocking ) { | ||
| start(); | ||
| } | ||
| } | ||
| }, | ||
| teardown: function() { | ||
| try { | ||
| this.testEnvironment.teardown.call(this.testEnvironment); | ||
| checkPollution(); | ||
| } catch(e) { | ||
| QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message ); | ||
| } | ||
| }, | ||
| finish: function() { | ||
| if ( this.expected && this.expected != this.assertions.length ) { | ||
| QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" ); | ||
| } | ||
| var good = 0, bad = 0, | ||
| tests = id("qunit-tests"); | ||
| config.stats.all += this.assertions.length; | ||
| config.moduleStats.all += this.assertions.length; | ||
| if ( tests ) { | ||
| var ol = document.createElement("ol"); | ||
| for ( var i = 0; i < this.assertions.length; i++ ) { | ||
| var assertion = this.assertions[i]; | ||
| var li = document.createElement("li"); | ||
| li.className = assertion.result ? "pass" : "fail"; | ||
| li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed"); | ||
| ol.appendChild( li ); | ||
| if ( assertion.result ) { | ||
| good++; | ||
| } else { | ||
| bad++; | ||
| config.stats.bad++; | ||
| config.moduleStats.bad++; | ||
| } | ||
| } | ||
| // store result when possible | ||
| if ( QUnit.config.reorder && defined.sessionStorage ) { | ||
| if (bad) { | ||
| sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad); | ||
| } else { | ||
| sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName); | ||
| } | ||
| } | ||
| if (bad == 0) { | ||
| ol.style.display = "none"; | ||
| } | ||
| 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>"; | ||
| 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"; | ||
| }); | ||
| addEvent(b, "dblclick", function(e) { | ||
| var target = e && e.target ? e.target : window.event.srcElement; | ||
| 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, "") }); | ||
| } | ||
| }); | ||
| var li = id(this.id); | ||
| li.className = bad ? "fail" : "pass"; | ||
| li.removeChild( li.firstChild ); | ||
| li.appendChild( b ); | ||
| li.appendChild( a ); | ||
| li.appendChild( ol ); | ||
| } else { | ||
| for ( var i = 0; i < this.assertions.length; i++ ) { | ||
| if ( !this.assertions[i].result ) { | ||
| bad++; | ||
| config.stats.bad++; | ||
| config.moduleStats.bad++; | ||
| } | ||
| } | ||
| } | ||
| try { | ||
| QUnit.reset(); | ||
| } catch(e) { | ||
| fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset); | ||
| } | ||
| QUnit.testDone( { | ||
| name: this.testName, | ||
| failed: bad, | ||
| passed: this.assertions.length - bad, | ||
| total: this.assertions.length | ||
| } ); | ||
| }, | ||
| queue: function() { | ||
| var test = this; | ||
| synchronize(function() { | ||
| test.init(); | ||
| }); | ||
| function run() { | ||
| // each of these can by async | ||
| synchronize(function() { | ||
| test.setup(); | ||
| }); | ||
| synchronize(function() { | ||
| test.run(); | ||
| }); | ||
| synchronize(function() { | ||
| test.teardown(); | ||
| }); | ||
| synchronize(function() { | ||
| test.finish(); | ||
| }); | ||
| } | ||
| // 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) { | ||
| run(); | ||
| } else { | ||
| synchronize(run); | ||
| }; | ||
| } | ||
| }; | ||
| var QUnit = { | ||
| // call on start of module test to prepend name to all tests | ||
| module: function(name, testEnvironment) { | ||
| config.currentModule = name; | ||
| config.currentModuleTestEnviroment = testEnvironment; | ||
| }, | ||
| asyncTest: function(testName, expected, callback) { | ||
| if ( arguments.length === 2 ) { | ||
| callback = expected; | ||
| expected = 0; | ||
| } | ||
| QUnit.test(testName, expected, callback, true); | ||
| }, | ||
| test: function(testName, expected, callback, async) { | ||
| var name = '<span class="test-name">' + testName + '</span>', testEnvironmentArg; | ||
| if ( arguments.length === 2 ) { | ||
| callback = expected; | ||
| expected = null; | ||
| } | ||
| // 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; | ||
| } | ||
| if ( !validTest(config.currentModule + ": " + testName) ) { | ||
| 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; | ||
| }, | ||
| /** | ||
| * Asserts true. | ||
| * @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 = escapeHtml(msg); | ||
| QUnit.log(details); | ||
| config.current.assertions.push({ | ||
| result: a, | ||
| message: msg | ||
| }); | ||
| }, | ||
| /** | ||
| * Checks 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) | ||
| */ | ||
| equal: function(actual, expected, message) { | ||
| QUnit.push(expected == actual, actual, expected, message); | ||
| }, | ||
| notEqual: function(actual, expected, message) { | ||
| QUnit.push(expected != actual, actual, expected, message); | ||
| }, | ||
| deepEqual: function(actual, expected, message) { | ||
| QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); | ||
| }, | ||
| notDeepEqual: function(actual, expected, message) { | ||
| QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message); | ||
| }, | ||
| strictEqual: function(actual, expected, message) { | ||
| QUnit.push(expected === actual, actual, expected, message); | ||
| }, | ||
| notStrictEqual: function(actual, expected, message) { | ||
| QUnit.push(expected !== actual, actual, expected, message); | ||
| }, | ||
| raises: function(block, expected, message) { | ||
| var actual, ok = false; | ||
| if (typeof expected === 'string') { | ||
| message = expected; | ||
| expected = null; | ||
| } | ||
| try { | ||
| block(); | ||
| } catch (e) { | ||
| actual = e; | ||
| } | ||
| if (actual) { | ||
| // we don't want to validate thrown error | ||
| if (!expected) { | ||
| ok = true; | ||
| // expected is a regexp | ||
| } else if (QUnit.objectType(expected) === "regexp") { | ||
| ok = expected.test(actual); | ||
| // expected is a constructor | ||
| } else if (actual instanceof expected) { | ||
| ok = true; | ||
| // expected is a validation function which returns true is validation passed | ||
| } else if (expected.call({}, actual) === true) { | ||
| ok = true; | ||
| } | ||
| } | ||
| QUnit.ok(ok, message); | ||
| }, | ||
| start: function() { | ||
| config.semaphore--; | ||
| 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.timeout ) { | ||
| clearTimeout(config.timeout); | ||
| } | ||
| config.blocking = false; | ||
| process(); | ||
| }, 13); | ||
| } else { | ||
| config.blocking = false; | ||
| process(); | ||
| } | ||
| }, | ||
| stop: function(timeout) { | ||
| config.semaphore++; | ||
| config.blocking = true; | ||
| if ( timeout && defined.setTimeout ) { | ||
| clearTimeout(config.timeout); | ||
| config.timeout = window.setTimeout(function() { | ||
| QUnit.ok( false, "Test timed out" ); | ||
| QUnit.start(); | ||
| }, timeout); | ||
| } | ||
| } | ||
| }; | ||
| // Backwards compatibility, deprecated | ||
| QUnit.equals = QUnit.equal; | ||
| QUnit.same = QUnit.deepEqual; | ||
| // Maintain internal state | ||
| var config = { | ||
| // The queue of tests to run | ||
| queue: [], | ||
| // block until document ready | ||
| blocking: true, | ||
| // by default, run previously failed tests first | ||
| // very useful in combination with "Hide passed tests" checked | ||
| reorder: true, | ||
| noglobals: false, | ||
| notrycatch: false | ||
| }; | ||
| // Load paramaters | ||
| (function() { | ||
| var location = window.location || { search: "", protocol: "file:" }, | ||
| params = location.search.slice( 1 ).split( "&" ), | ||
| length = params.length, | ||
| urlParams = {}, | ||
| current; | ||
| if ( params[ 0 ] ) { | ||
| for ( var i = 0; i < length; i++ ) { | ||
| current = params[ i ].split( "=" ); | ||
| current[ 0 ] = decodeURIComponent( current[ 0 ] ); | ||
| // allow just a key to turn on a flag, e.g., test.html?noglobals | ||
| current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; | ||
| urlParams[ current[ 0 ] ] = current[ 1 ]; | ||
| if ( current[ 0 ] in config ) { | ||
| config[ current[ 0 ] ] = current[ 1 ]; | ||
| } | ||
| } | ||
| } | ||
| QUnit.urlParams = urlParams; | ||
| config.filter = urlParams.filter; | ||
| // Figure out if we're running the tests from a server or not | ||
| 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; | ||
| } | ||
| // define these after exposing globals to keep them in these QUnit namespace only | ||
| extend(QUnit, { | ||
| config: config, | ||
| // Initialize the configuration options | ||
| init: function() { | ||
| extend(config, { | ||
| stats: { all: 0, bad: 0 }, | ||
| moduleStats: { all: 0, bad: 0 }, | ||
| started: +new Date, | ||
| updateRate: 1000, | ||
| blocking: false, | ||
| autostart: true, | ||
| autorun: false, | ||
| filter: "", | ||
| queue: [], | ||
| semaphore: 0 | ||
| }); | ||
| var tests = id( "qunit-tests" ), | ||
| banner = id( "qunit-banner" ), | ||
| result = id( "qunit-testresult" ); | ||
| if ( tests ) { | ||
| tests.innerHTML = ""; | ||
| } | ||
| if ( banner ) { | ||
| banner.className = ""; | ||
| } | ||
| if ( result ) { | ||
| result.parentNode.removeChild( result ); | ||
| } | ||
| if ( tests ) { | ||
| result = document.createElement( "p" ); | ||
| result.id = "qunit-testresult"; | ||
| result.className = "result"; | ||
| tests.parentNode.insertBefore( result, tests ); | ||
| 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. | ||
| */ | ||
| reset: function() { | ||
| if ( window.jQuery ) { | ||
| jQuery( "#qunit-fixture" ).html( config.fixture ); | ||
| } else { | ||
| var main = id( 'qunit-fixture' ); | ||
| if ( main ) { | ||
| main.innerHTML = config.fixture; | ||
| } | ||
| } | ||
| }, | ||
| /** | ||
| * Trigger an event on an element. | ||
| * | ||
| * @example triggerEvent( document.body, "click" ); | ||
| * | ||
| * @param DOMElement elem | ||
| * @param String type | ||
| */ | ||
| triggerEvent: function( elem, type, event ) { | ||
| if ( document.createEvent ) { | ||
| 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); | ||
| } | ||
| }, | ||
| // Safe object type checking | ||
| is: function( type, obj ) { | ||
| return QUnit.objectType( obj ) == type; | ||
| }, | ||
| objectType: function( obj ) { | ||
| if (typeof obj === "undefined") { | ||
| return "undefined"; | ||
| // consider: typeof null === object | ||
| } | ||
| if (obj === null) { | ||
| return "null"; | ||
| } | ||
| var type = Object.prototype.toString.call( obj ) | ||
| .match(/^\[object\s(.*)\]$/)[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(); | ||
| } | ||
| if (typeof obj === "object") { | ||
| return "object"; | ||
| } | ||
| return undefined; | ||
| }, | ||
| push: function(result, actual, expected, message) { | ||
| var details = { | ||
| result: result, | ||
| message: message, | ||
| actual: actual, | ||
| expected: expected | ||
| }; | ||
| message = escapeHtml(message) || (result ? "okay" : "failed"); | ||
| message = '<span class="test-message">' + message + "</span>"; | ||
| expected = escapeHtml(QUnit.jsDump.parse(expected)); | ||
| actual = escapeHtml(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) { | ||
| details.source = source; | ||
| output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeHtml(source) + '</pre></td></tr>'; | ||
| } | ||
| } | ||
| output += "</table>"; | ||
| QUnit.log(details); | ||
| config.current.assertions.push({ | ||
| result: !!result, | ||
| message: output | ||
| }); | ||
| }, | ||
| url: function( params ) { | ||
| params = extend( extend( {}, QUnit.urlParams ), params ); | ||
| var querystring = "?", | ||
| key; | ||
| for ( key in params ) { | ||
| querystring += encodeURIComponent( key ) + "=" + | ||
| encodeURIComponent( params[ key ] ) + "&"; | ||
| } | ||
| return window.location.pathname + querystring.slice( 0, -1 ); | ||
| }, | ||
| extend: extend, | ||
| id: id, | ||
| addEvent: addEvent, | ||
| // Logging callbacks; all receive a single argument with the listed properties | ||
| // run test/logs.html for any related changes | ||
| begin: function() {}, | ||
| // done: { failed, passed, total, runtime } | ||
| done: function() {}, | ||
| // log: { result, actual, expected, message } | ||
| log: function() {}, | ||
| // testStart: { name } | ||
| testStart: function() {}, | ||
| // testDone: { name, failed, passed, total } | ||
| testDone: function() {}, | ||
| // moduleStart: { name } | ||
| moduleStart: function() {}, | ||
| // moduleDone: { name, failed, passed, total } | ||
| moduleDone: function() {} | ||
| }); | ||
| if ( typeof document === "undefined" || document.readyState === "complete" ) { | ||
| config.autorun = true; | ||
| } | ||
| addEvent(window, "load", function() { | ||
| QUnit.begin({}); | ||
| // Initialize the config, saving the execution queue | ||
| var oldconfig = extend({}, config); | ||
| QUnit.init(); | ||
| extend(config, oldconfig); | ||
| config.blocking = false; | ||
| var userAgent = id("qunit-userAgent"); | ||
| if ( userAgent ) { | ||
| userAgent.innerHTML = navigator.userAgent; | ||
| } | ||
| var banner = id("qunit-header"); | ||
| if ( banner ) { | ||
| banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' + | ||
| '<label><input name="noglobals" type="checkbox"' + ( config.noglobals ? ' checked="checked"' : '' ) + '>noglobals</label>' + | ||
| '<label><input name="notrycatch" type="checkbox"' + ( config.notrycatch ? ' checked="checked"' : '' ) + '>notrycatch</label>'; | ||
| addEvent( banner, "change", function( event ) { | ||
| var params = {}; | ||
| params[ event.target.name ] = event.target.checked ? true : undefined; | ||
| window.location = QUnit.url( params ); | ||
| }); | ||
| } | ||
| var toolbar = id("qunit-testrunner-toolbar"); | ||
| if ( toolbar ) { | ||
| var filter = document.createElement("input"); | ||
| filter.type = "checkbox"; | ||
| filter.id = "qunit-filter-pass"; | ||
| addEvent( filter, "click", function() { | ||
| var 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 /, " "); | ||
| } | ||
| if ( defined.sessionStorage ) { | ||
| if (filter.checked) { | ||
| sessionStorage.setItem("qunit-filter-passed-tests", "true"); | ||
| } else { | ||
| sessionStorage.removeItem("qunit-filter-passed-tests"); | ||
| } | ||
| } | ||
| }); | ||
| if ( defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) { | ||
| filter.checked = true; | ||
| var ol = document.getElementById("qunit-tests"); | ||
| ol.className = ol.className + " hidepass"; | ||
| } | ||
| toolbar.appendChild( filter ); | ||
| var label = document.createElement("label"); | ||
| label.setAttribute("for", "qunit-filter-pass"); | ||
| label.innerHTML = "Hide passed tests"; | ||
| toolbar.appendChild( label ); | ||
| } | ||
| var main = id('qunit-fixture'); | ||
| if ( main ) { | ||
| config.fixture = main.innerHTML; | ||
| } | ||
| if (config.autostart) { | ||
| QUnit.start(); | ||
| } | ||
| }); | ||
| function done() { | ||
| config.autorun = true; | ||
| // Log the last module results | ||
| if ( config.currentModule ) { | ||
| QUnit.moduleDone( { | ||
| name: config.currentModule, | ||
| failed: config.moduleStats.bad, | ||
| passed: config.moduleStats.all - config.moduleStats.bad, | ||
| total: config.moduleStats.all | ||
| } ); | ||
| } | ||
| var banner = id("qunit-banner"), | ||
| tests = id("qunit-tests"), | ||
| runtime = +new Date - config.started, | ||
| passed = config.stats.all - config.stats.bad, | ||
| html = [ | ||
| 'Tests completed in ', | ||
| runtime, | ||
| ' milliseconds.<br/>', | ||
| '<span class="passed">', | ||
| passed, | ||
| '</span> tests of <span class="total">', | ||
| config.stats.all, | ||
| '</span> passed, <span class="failed">', | ||
| config.stats.bad, | ||
| '</span> failed.' | ||
| ].join(''); | ||
| if ( banner ) { | ||
| banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass"); | ||
| } | ||
| if ( tests ) { | ||
| id( "qunit-testresult" ).innerHTML = html; | ||
| } | ||
| if ( typeof document !== "undefined" && document.title ) { | ||
| // show ✖ for bad, ✔ for good suite result in title | ||
| // use escape sequences in case file gets loaded with non-utf-8-charset | ||
| document.title = (config.stats.bad ? "\u2716" : "\u2714") + " " + document.title; | ||
| } | ||
| QUnit.done( { | ||
| failed: config.stats.bad, | ||
| passed: passed, | ||
| total: config.stats.all, | ||
| runtime: runtime | ||
| } ); | ||
| } | ||
| function validTest( name ) { | ||
| var filter = config.filter, | ||
| run = false; | ||
| if ( !filter ) { | ||
| return true; | ||
| } | ||
| var not = filter.charAt( 0 ) === "!"; | ||
| if ( not ) { | ||
| filter = filter.slice( 1 ); | ||
| } | ||
| if ( name.indexOf( filter ) !== -1 ) { | ||
| return !not; | ||
| } | ||
| if ( not ) { | ||
| run = true; | ||
| } | ||
| 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() { | ||
| 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]; | ||
| } | ||
| } | ||
| } | ||
| function escapeHtml(s) { | ||
| if (!s) { | ||
| return ""; | ||
| } | ||
| s = s + ""; | ||
| return s.replace(/[\&"<>\\]/g, function(s) { | ||
| switch(s) { | ||
| case "&": return "&"; | ||
| case "\\": return "\\\\"; | ||
| case '"': return '\"'; | ||
| case "<": return "<"; | ||
| case ">": return ">"; | ||
| default: return s; | ||
| } | ||
| }); | ||
| } | ||
| function synchronize( callback ) { | ||
| config.queue.push( callback ); | ||
| if ( config.autorun && !config.blocking ) { | ||
| process(); | ||
| } | ||
| } | ||
| function process() { | ||
| var start = (new Date()).getTime(); | ||
| while ( config.queue.length && !config.blocking ) { | ||
| if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) { | ||
| config.queue.shift()(); | ||
| } else { | ||
| window.setTimeout( process, 13 ); | ||
| break; | ||
| } | ||
| } | ||
| if (!config.blocking && !config.queue.length) { | ||
| done(); | ||
| } | ||
| } | ||
| function saveGlobal() { | ||
| config.pollution = []; | ||
| if ( config.noglobals ) { | ||
| for ( var key in window ) { | ||
| config.pollution.push( key ); | ||
| } | ||
| } | ||
| } | ||
| function checkPollution( name ) { | ||
| var old = config.pollution; | ||
| saveGlobal(); | ||
| var newGlobals = diff( config.pollution, old ); | ||
| if ( newGlobals.length > 0 ) { | ||
| ok( false, "Introduced global variable(s): " + newGlobals.join(", ") ); | ||
| } | ||
| var deletedGlobals = diff( old, config.pollution ); | ||
| if ( deletedGlobals.length > 0 ) { | ||
| ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") ); | ||
| } | ||
| } | ||
| // returns a new Array with the elements that are in a but not in b | ||
| function diff( a, b ) { | ||
| var result = a.slice(); | ||
| for ( var i = 0; i < result.length; i++ ) { | ||
| for ( var j = 0; j < b.length; j++ ) { | ||
| if ( result[i] === b[j] ) { | ||
| result.splice(i, 1); | ||
| i--; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function fail(message, exception, callback) { | ||
| if ( typeof console !== "undefined" && console.error && console.warn ) { | ||
| console.error(message); | ||
| console.error(exception); | ||
| console.warn(callback.toString()); | ||
| } 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]; | ||
| } | ||
| } | ||
| return a; | ||
| } | ||
| function addEvent(elem, type, fn) { | ||
| if ( elem.addEventListener ) { | ||
| elem.addEventListener( type, fn, false ); | ||
| } else if ( elem.attachEvent ) { | ||
| elem.attachEvent( "on" + type, fn ); | ||
| } else { | ||
| fn(); | ||
| } | ||
| } | ||
| function id(name) { | ||
| return !!(typeof document !== "undefined" && document && document.getElementById) && | ||
| document.getElementById( name ); | ||
| } | ||
| // Test for equality any JavaScript type. | ||
| // Discussions and reference: http://philrathe.com/articles/equiv | ||
| // Test suites: http://philrathe.com/tests/equiv | ||
| // Author: Philippe Rathé <prathe@gmail.com> | ||
| 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); | ||
| } else { | ||
| return callbacks[prop]; // or undefined | ||
| } | ||
| } | ||
| } | ||
| var callbacks = function () { | ||
| // 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; | ||
| } | ||
| } | ||
| return { | ||
| "string": useStrictEquality, | ||
| "boolean": useStrictEquality, | ||
| "number": useStrictEquality, | ||
| "null": useStrictEquality, | ||
| "undefined": useStrictEquality, | ||
| "nan": function (b) { | ||
| return isNaN(b); | ||
| }, | ||
| "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; | ||
| }, | ||
| // - 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; | ||
| // 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; | ||
| } | ||
| //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; | ||
| } | ||
| } | ||
| 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 | ||
| // comparing constructors is more strict than using instanceof | ||
| if ( a.constructor !== b.constructor) { | ||
| return false; | ||
| } | ||
| // 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 | ||
| } | ||
| 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 | ||
| } | ||
| // 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) { | ||
| return true; // end transition | ||
| } | ||
| 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)) { | ||
| return false; // don't lose time with error prone cases | ||
| } else { | ||
| return bindCallbacks(a, callbacks, [b, a]); | ||
| } | ||
| // apply transition with (1..n) arguments | ||
| })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1)); | ||
| }; | ||
| return innerEquiv; | ||
| }(); | ||
| /** | ||
| * jsDump | ||
| * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com | ||
| * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php) | ||
| * Date: 5/15/2008 | ||
| * @projectDescription Advanced and extensible data dumping for Javascript. | ||
| * @version 1.0.0 | ||
| * @author Ariel Flesler | ||
| * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} | ||
| */ | ||
| QUnit.jsDump = (function() { | ||
| function quote( str ) { | ||
| return '"' + str.toString().replace(/"/g, '\\"') + '"'; | ||
| }; | ||
| function literal( o ) { | ||
| return o + ''; | ||
| }; | ||
| function join( pre, arr, post ) { | ||
| var s = jsDump.separator(), | ||
| base = jsDump.indent(), | ||
| inner = jsDump.indent(1); | ||
| if ( arr.join ) | ||
| arr = arr.join( ',' + s + inner ); | ||
| if ( !arr ) | ||
| return pre + post; | ||
| return [ pre, inner + arr, base + post ].join(s); | ||
| }; | ||
| function array( arr ) { | ||
| var i = arr.length, ret = Array(i); | ||
| this.up(); | ||
| while ( i-- ) | ||
| ret[i] = this.parse( arr[i] ); | ||
| this.down(); | ||
| return join( '[', ret, ']' ); | ||
| }; | ||
| var reName = /^function (\w+)/; | ||
| var jsDump = { | ||
| parse:function( obj, type ) { //type is used mostly internally, you can fix a (custom)type in advance | ||
| var parser = this.parsers[ type || this.typeOf(obj) ]; | ||
| type = typeof parser; | ||
| return type == 'function' ? parser.call( this, obj ) : | ||
| 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'), '}' ); | ||
| }, | ||
| array: array, | ||
| nodelist: array, | ||
| arguments: array, | ||
| object:function( map ) { | ||
| var ret = [ ]; | ||
| QUnit.jsDump.up(); | ||
| for ( var key in map ) | ||
| ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(map[key]) ); | ||
| QUnit.jsDump.down(); | ||
| return join( '{', ret, '}' ); | ||
| }, | ||
| 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' ); | ||
| } | ||
| return ret + close + open + '/' + tag + close; | ||
| }, | ||
| 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(', ') + ' '; | ||
| }, | ||
| key:quote, //object calls it internally, the key part of an item in a map | ||
| functionCode:'[code]', //function calls it internally, it's the content of the function | ||
| attribute:quote, //node calls it internally, it's an html attribute value | ||
| string:quote, | ||
| date:quote, | ||
| regexp:literal, //regex | ||
| number:literal, | ||
| 'boolean':literal | ||
| }, | ||
| DOMAttrs:{//attributes to dump from nodes, name=>realName | ||
| id:'id', | ||
| name:'name', | ||
| 'class':'className' | ||
| }, | ||
| HTML:false,//if true, entities are escaped ( <, >, \t, space and \n ) | ||
| indentChar:' ',//indentation unit | ||
| multiline:true //if true, items in a collection, are separated by a \n, else just a space. | ||
| }; | ||
| return jsDump; | ||
| })(); | ||
| // from Sizzle.js | ||
| function getText( elems ) { | ||
| var ret = "", elem; | ||
| for ( var i = 0; elems[i]; i++ ) { | ||
| elem = elems[i]; | ||
| // Get the text from text nodes and CDATA nodes | ||
| if ( elem.nodeType === 3 || elem.nodeType === 4 ) { | ||
| ret += elem.nodeValue; | ||
| // Traverse everything else, except comment nodes | ||
| } else if ( elem.nodeType !== 8 ) { | ||
| ret += getText( elem.childNodes ); | ||
| } | ||
| } | ||
| return ret; | ||
| }; | ||
| /* | ||
| * Javascript Diff Algorithm | ||
| * By John Resig (http://ejohn.org/) | ||
| * Modified by Chu Alan "sprite" | ||
| * | ||
| * Released under the MIT license. | ||
| * | ||
| * More Info: | ||
| * http://ejohn.org/projects/javascript-diff-algorithm/ | ||
| * | ||
| * Usage: QUnit.diff(expected, actual) | ||
| * | ||
| * 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 = new Object(); | ||
| var os = new Object(); | ||
| for (var i = 0; i < n.length; i++) { | ||
| if (ns[n[i]] == null) | ||
| ns[n[i]] = { | ||
| rows: new Array(), | ||
| o: null | ||
| }; | ||
| ns[n[i]].rows.push(i); | ||
| } | ||
| for (var i = 0; i < o.length; i++) { | ||
| if (os[o[i]] == null) | ||
| os[o[i]] = { | ||
| rows: new Array(), | ||
| n: null | ||
| }; | ||
| 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]], | ||
| row: os[i].rows[0] | ||
| }; | ||
| o[os[i].rows[0]] = { | ||
| text: o[os[i].rows[0]], | ||
| row: ns[i].rows[0] | ||
| }; | ||
| } | ||
| } | ||
| 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], | ||
| row: n[i].row + 1 | ||
| }; | ||
| o[n[i].row + 1] = { | ||
| text: o[n[i].row + 1], | ||
| row: i + 1 | ||
| }; | ||
| } | ||
| } | ||
| 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], | ||
| row: n[i].row - 1 | ||
| }; | ||
| o[n[i].row - 1] = { | ||
| text: o[n[i].row - 1], | ||
| row: i - 1 | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| o: o, | ||
| n: n | ||
| }; | ||
| } | ||
| return function(o, n){ | ||
| o = o.replace(/\s+$/, ''); | ||
| n = n.replace(/\s+$/, ''); | ||
| var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/)); | ||
| var str = ""; | ||
| var oSpace = o.match(/\s+/g); | ||
| if (oSpace == null) { | ||
| oSpace = [" "]; | ||
| } | ||
| else { | ||
| oSpace.push(" "); | ||
| } | ||
| var nSpace = n.match(/\s+/g); | ||
| if (nSpace == null) { | ||
| nSpace = [" "]; | ||
| } | ||
| else { | ||
| nSpace.push(" "); | ||
| } | ||
| if (out.n.length == 0) { | ||
| for (var 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>"; | ||
| } | ||
| } | ||
| for (var i = 0; i < out.n.length; i++) { | ||
| if (out.n[i].text == null) { | ||
| str += '<ins>' + out.n[i] + nSpace[i] + "</ins>"; | ||
| } | ||
| else { | ||
| var 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>"; | ||
| } | ||
| str += " " + out.n[i].text + nSpace[i] + pre; | ||
| } | ||
| } | ||
| } | ||
| return str; | ||
| }; | ||
| })(); | ||
| })(this); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
234463
204.08%52
477.78%5586
164.24%1
Infinity%1
Infinity%