unittests/qunit.js
author hamidouk
Mon, 19 Dec 2011 15:25:22 +0100
branchpopcorn-port
changeset 481 a46cfeee6d77
parent 57 eabfc9a2eb35
permissions -rw-r--r--
using jquery ui draggable changes the state of an element from absolute to relative positioning, which breaks the way our seek button expands itself, so we need to force absolute positioning, quite uglily, using jquery.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     1
/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     2
 * QUnit - A JavaScript Unit Testing Framework
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     3
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     4
 * http://docs.jquery.com/QUnit
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     5
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     6
 * Copyright (c) 2011 John Resig, Jörn Zaefferer
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     7
 * Dual licensed under the MIT (MIT-LICENSE.txt)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     8
 * or GPL (GPL-LICENSE.txt) licenses.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
     9
 * Pulled Live from Git Thu Oct  6 09:15:01 UTC 2011
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    10
 * Last Commit: 3006fa77db4625c4293c368a8999ddb1abba7f48
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    11
 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    12
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    13
(function(window) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    14
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    15
var defined = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    16
	setTimeout: typeof window.setTimeout !== "undefined",
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    17
	sessionStorage: (function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    18
		try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    19
			return !!sessionStorage.getItem;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    20
		} catch(e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    21
			return false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    22
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    23
	})()
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    24
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    25
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    26
var testId = 0;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    27
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    28
var Test = function(name, testName, expected, testEnvironmentArg, async, callback) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    29
	this.name = name;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    30
	this.testName = testName;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    31
	this.expected = expected;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    32
	this.testEnvironmentArg = testEnvironmentArg;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    33
	this.async = async;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    34
	this.callback = callback;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    35
	this.assertions = [];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    36
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    37
Test.prototype = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    38
	init: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    39
		var tests = id("qunit-tests");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    40
		if (tests) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    41
			var b = document.createElement("strong");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    42
				b.innerHTML = "Running " + this.name;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    43
			var li = document.createElement("li");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    44
				li.appendChild( b );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    45
				li.className = "running";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    46
				li.id = this.id = "test-output" + testId++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    47
			tests.appendChild( li );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    48
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    49
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    50
	setup: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    51
		if (this.module != config.previousModule) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    52
			if ( config.previousModule ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    53
				runLoggingCallbacks('moduleDone', QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    54
					name: config.previousModule,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    55
					failed: config.moduleStats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    56
					passed: config.moduleStats.all - config.moduleStats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    57
					total: config.moduleStats.all
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    58
				} );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    59
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    60
			config.previousModule = this.module;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    61
			config.moduleStats = { all: 0, bad: 0 };
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    62
			runLoggingCallbacks( 'moduleStart', QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    63
				name: this.module
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    64
			} );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    65
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    66
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    67
		config.current = this;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    68
		this.testEnvironment = extend({
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    69
			setup: function() {},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    70
			teardown: function() {}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    71
		}, this.moduleTestEnvironment);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    72
		if (this.testEnvironmentArg) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    73
			extend(this.testEnvironment, this.testEnvironmentArg);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    74
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    75
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    76
		runLoggingCallbacks( 'testStart', QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    77
			name: this.testName,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    78
			module: this.module
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    79
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    80
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    81
		// allow utility functions to access the current test environment
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    82
		// TODO why??
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    83
		QUnit.current_testEnvironment = this.testEnvironment;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    84
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    85
		try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    86
			if ( !config.pollution ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    87
				saveGlobal();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    88
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    89
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    90
			this.testEnvironment.setup.call(this.testEnvironment);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    91
		} catch(e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    92
			QUnit.ok( false, "Setup failed on " + this.testName + ": " + e.message );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    93
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    94
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    95
	run: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    96
		if ( this.async ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    97
			QUnit.stop();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    98
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
    99
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   100
		if ( config.notrycatch ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   101
			this.callback.call(this.testEnvironment);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   102
			return;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   103
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   104
		try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   105
			this.callback.call(this.testEnvironment);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   106
		} catch(e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   107
			fail("Test " + this.testName + " died, exception and test follows", e, this.callback);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   108
			QUnit.ok( false, "Died on test #" + (this.assertions.length + 1) + ": " + e.message + " - " + QUnit.jsDump.parse(e) );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   109
			// else next test will carry the responsibility
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   110
			saveGlobal();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   111
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   112
			// Restart the tests if they're blocking
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   113
			if ( config.blocking ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   114
				start();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   115
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   116
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   117
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   118
	teardown: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   119
		try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   120
			this.testEnvironment.teardown.call(this.testEnvironment);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   121
			checkPollution();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   122
		} catch(e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   123
			QUnit.ok( false, "Teardown failed on " + this.testName + ": " + e.message );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   124
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   125
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   126
	finish: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   127
		if ( this.expected && this.expected != this.assertions.length ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   128
			QUnit.ok( false, "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   129
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   130
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   131
		var good = 0, bad = 0,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   132
			tests = id("qunit-tests");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   133
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   134
		config.stats.all += this.assertions.length;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   135
		config.moduleStats.all += this.assertions.length;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   136
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   137
		if ( tests ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   138
			var ol = document.createElement("ol");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   139
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   140
			for ( var i = 0; i < this.assertions.length; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   141
				var assertion = this.assertions[i];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   142
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   143
				var li = document.createElement("li");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   144
				li.className = assertion.result ? "pass" : "fail";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   145
				li.innerHTML = assertion.message || (assertion.result ? "okay" : "failed");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   146
				ol.appendChild( li );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   147
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   148
				if ( assertion.result ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   149
					good++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   150
				} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   151
					bad++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   152
					config.stats.bad++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   153
					config.moduleStats.bad++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   154
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   155
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   156
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   157
			// store result when possible
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   158
			if ( QUnit.config.reorder && defined.sessionStorage ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   159
				if (bad) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   160
					sessionStorage.setItem("qunit-" + this.module + "-" + this.testName, bad);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   161
				} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   162
					sessionStorage.removeItem("qunit-" + this.module + "-" + this.testName);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   163
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   164
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   165
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   166
			if (bad == 0) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   167
				ol.style.display = "none";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   168
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   169
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   170
			var b = document.createElement("strong");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   171
			b.innerHTML = this.name + " <b class='counts'>(<b class='failed'>" + bad + "</b>, <b class='passed'>" + good + "</b>, " + this.assertions.length + ")</b>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   172
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   173
			var a = document.createElement("a");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   174
			a.innerHTML = "Rerun";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   175
			a.href = QUnit.url({ filter: getText([b]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   176
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   177
			addEvent(b, "click", function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   178
				var next = b.nextSibling.nextSibling,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   179
					display = next.style.display;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   180
				next.style.display = display === "none" ? "block" : "none";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   181
			});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   182
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   183
			addEvent(b, "dblclick", function(e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   184
				var target = e && e.target ? e.target : window.event.srcElement;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   185
				if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   186
					target = target.parentNode;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   187
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   188
				if ( window.location && target.nodeName.toLowerCase() === "strong" ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   189
					window.location = QUnit.url({ filter: getText([target]).replace(/\([^)]+\)$/, "").replace(/(^\s*|\s*$)/g, "") });
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   190
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   191
			});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   192
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   193
			var li = id(this.id);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   194
			li.className = bad ? "fail" : "pass";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   195
			li.removeChild( li.firstChild );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   196
			li.appendChild( b );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   197
			li.appendChild( a );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   198
			li.appendChild( ol );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   199
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   200
		} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   201
			for ( var i = 0; i < this.assertions.length; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   202
				if ( !this.assertions[i].result ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   203
					bad++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   204
					config.stats.bad++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   205
					config.moduleStats.bad++;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   206
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   207
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   208
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   209
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   210
		try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   211
			QUnit.reset();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   212
		} catch(e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   213
			fail("reset() failed, following Test " + this.testName + ", exception and reset fn follows", e, QUnit.reset);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   214
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   215
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   216
		runLoggingCallbacks( 'testDone', QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   217
			name: this.testName,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   218
			module: this.module,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   219
			failed: bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   220
			passed: this.assertions.length - bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   221
			total: this.assertions.length
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   222
		} );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   223
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   224
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   225
	queue: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   226
		var test = this;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   227
		synchronize(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   228
			test.init();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   229
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   230
		function run() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   231
			// each of these can by async
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   232
			synchronize(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   233
				test.setup();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   234
			});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   235
			synchronize(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   236
				test.run();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   237
			});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   238
			synchronize(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   239
				test.teardown();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   240
			});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   241
			synchronize(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   242
				test.finish();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   243
			});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   244
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   245
		// defer when previous test run passed, if storage is available
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   246
		var bad = QUnit.config.reorder && defined.sessionStorage && +sessionStorage.getItem("qunit-" + this.module + "-" + this.testName);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   247
		if (bad) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   248
			run();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   249
		} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   250
			synchronize(run);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   251
		};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   252
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   253
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   254
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   255
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   256
var QUnit = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   257
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   258
	// call on start of module test to prepend name to all tests
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   259
	module: function(name, testEnvironment) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   260
		config.currentModule = name;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   261
		config.currentModuleTestEnviroment = testEnvironment;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   262
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   263
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   264
	asyncTest: function(testName, expected, callback) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   265
		if ( arguments.length === 2 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   266
			callback = expected;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   267
			expected = 0;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   268
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   269
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   270
		QUnit.test(testName, expected, callback, true);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   271
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   272
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   273
	test: function(testName, expected, callback, async) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   274
		var name = '<span class="test-name">' + testName + '</span>', testEnvironmentArg;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   275
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   276
		if ( arguments.length === 2 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   277
			callback = expected;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   278
			expected = null;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   279
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   280
		// is 2nd argument a testEnvironment?
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   281
		if ( expected && typeof expected === 'object') {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   282
			testEnvironmentArg = expected;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   283
			expected = null;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   284
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   285
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   286
		if ( config.currentModule ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   287
			name = '<span class="module-name">' + config.currentModule + "</span>: " + name;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   288
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   289
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   290
		if ( !validTest(config.currentModule + ": " + testName) ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   291
			return;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   292
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   293
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   294
		var test = new Test(name, testName, expected, testEnvironmentArg, async, callback);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   295
		test.module = config.currentModule;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   296
		test.moduleTestEnvironment = config.currentModuleTestEnviroment;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   297
		test.queue();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   298
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   299
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   300
	/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   301
	 * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   302
	 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   303
	expect: function(asserts) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   304
		config.current.expected = asserts;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   305
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   306
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   307
	/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   308
	 * Asserts true.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   309
	 * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   310
	 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   311
	ok: function(a, msg) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   312
		a = !!a;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   313
		var details = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   314
			result: a,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   315
			message: msg
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   316
		};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   317
		msg = escapeInnerText(msg);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   318
		runLoggingCallbacks( 'log', QUnit, details );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   319
		config.current.assertions.push({
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   320
			result: a,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   321
			message: msg
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   322
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   323
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   324
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   325
	/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   326
	 * Checks that the first two arguments are equal, with an optional message.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   327
	 * Prints out both actual and expected values.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   328
	 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   329
	 * Prefered to ok( actual == expected, message )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   330
	 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   331
	 * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   332
	 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   333
	 * @param Object actual
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   334
	 * @param Object expected
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   335
	 * @param String message (optional)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   336
	 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   337
	equal: function(actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   338
		QUnit.push(expected == actual, actual, expected, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   339
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   340
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   341
	notEqual: function(actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   342
		QUnit.push(expected != actual, actual, expected, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   343
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   344
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   345
	deepEqual: function(actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   346
		QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   347
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   348
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   349
	notDeepEqual: function(actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   350
		QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   351
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   352
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   353
	strictEqual: function(actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   354
		QUnit.push(expected === actual, actual, expected, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   355
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   356
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   357
	notStrictEqual: function(actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   358
		QUnit.push(expected !== actual, actual, expected, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   359
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   360
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   361
	raises: function(block, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   362
		var actual, ok = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   363
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   364
		if (typeof expected === 'string') {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   365
			message = expected;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   366
			expected = null;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   367
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   368
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   369
		try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   370
			block();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   371
		} catch (e) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   372
			actual = e;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   373
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   374
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   375
		if (actual) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   376
			// we don't want to validate thrown error
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   377
			if (!expected) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   378
				ok = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   379
			// expected is a regexp
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   380
			} else if (QUnit.objectType(expected) === "regexp") {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   381
				ok = expected.test(actual);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   382
			// expected is a constructor
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   383
			} else if (actual instanceof expected) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   384
				ok = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   385
			// expected is a validation function which returns true is validation passed
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   386
			} else if (expected.call({}, actual) === true) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   387
				ok = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   388
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   389
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   390
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   391
		QUnit.ok(ok, message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   392
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   393
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   394
	start: function(count) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   395
		config.semaphore -= count || 1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   396
		if (config.semaphore > 0) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   397
			// don't start until equal number of stop-calls
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   398
			return;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   399
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   400
		if (config.semaphore < 0) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   401
			// ignore if start is called more often then stop
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   402
			config.semaphore = 0;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   403
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   404
		// A slight delay, to avoid any current callbacks
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   405
		if ( defined.setTimeout ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   406
			window.setTimeout(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   407
				if (config.semaphore > 0) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   408
					return;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   409
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   410
				if ( config.timeout ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   411
					clearTimeout(config.timeout);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   412
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   413
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   414
				config.blocking = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   415
				process();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   416
			}, 13);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   417
		} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   418
			config.blocking = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   419
			process();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   420
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   421
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   422
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   423
	stop: function(count) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   424
		config.semaphore += count || 1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   425
		config.blocking = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   426
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   427
		if ( config.testTimeout && defined.setTimeout ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   428
			clearTimeout(config.timeout);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   429
			config.timeout = window.setTimeout(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   430
				QUnit.ok( false, "Test timed out" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   431
				config.semaphore = 1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   432
				QUnit.start();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   433
			}, config.testTimeout);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   434
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   435
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   436
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   437
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   438
//We want access to the constructor's prototype
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   439
(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   440
	function F(){};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   441
	F.prototype = QUnit;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   442
	QUnit = new F();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   443
	//Make F QUnit's constructor so that we can add to the prototype later
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   444
	QUnit.constructor = F;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   445
})();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   446
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   447
// Backwards compatibility, deprecated
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   448
QUnit.equals = QUnit.equal;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   449
QUnit.same = QUnit.deepEqual;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   450
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   451
// Maintain internal state
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   452
var config = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   453
	// The queue of tests to run
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   454
	queue: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   455
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   456
	// block until document ready
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   457
	blocking: true,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   458
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   459
	// when enabled, show only failing tests
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   460
	// gets persisted through sessionStorage and can be changed in UI via checkbox
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   461
	hidepassed: false,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   462
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   463
	// by default, run previously failed tests first
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   464
	// very useful in combination with "Hide passed tests" checked
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   465
	reorder: true,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   466
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   467
	// by default, modify document.title when suite is done
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   468
	altertitle: true,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   469
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   470
	urlConfig: ['noglobals', 'notrycatch'],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   471
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   472
	//logging callback queues
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   473
	begin: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   474
	done: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   475
	log: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   476
	testStart: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   477
	testDone: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   478
	moduleStart: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   479
	moduleDone: []
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   480
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   481
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   482
// Load paramaters
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   483
(function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   484
	var location = window.location || { search: "", protocol: "file:" },
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   485
		params = location.search.slice( 1 ).split( "&" ),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   486
		length = params.length,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   487
		urlParams = {},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   488
		current;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   489
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   490
	if ( params[ 0 ] ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   491
		for ( var i = 0; i < length; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   492
			current = params[ i ].split( "=" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   493
			current[ 0 ] = decodeURIComponent( current[ 0 ] );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   494
			// allow just a key to turn on a flag, e.g., test.html?noglobals
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   495
			current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   496
			urlParams[ current[ 0 ] ] = current[ 1 ];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   497
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   498
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   499
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   500
	QUnit.urlParams = urlParams;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   501
	config.filter = urlParams.filter;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   502
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   503
	// Figure out if we're running the tests from a server or not
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   504
	QUnit.isLocal = !!(location.protocol === 'file:');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   505
})();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   506
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   507
// Expose the API as global variables, unless an 'exports'
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   508
// object exists, in that case we assume we're in CommonJS
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   509
if ( typeof exports === "undefined" || typeof require === "undefined" ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   510
	extend(window, QUnit);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   511
	window.QUnit = QUnit;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   512
} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   513
	extend(exports, QUnit);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   514
	exports.QUnit = QUnit;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   515
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   516
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   517
// define these after exposing globals to keep them in these QUnit namespace only
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   518
extend(QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   519
	config: config,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   520
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   521
	// Initialize the configuration options
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   522
	init: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   523
		extend(config, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   524
			stats: { all: 0, bad: 0 },
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   525
			moduleStats: { all: 0, bad: 0 },
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   526
			started: +new Date,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   527
			updateRate: 1000,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   528
			blocking: false,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   529
			autostart: true,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   530
			autorun: false,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   531
			filter: "",
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   532
			queue: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   533
			semaphore: 0
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   534
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   535
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   536
		var tests = id( "qunit-tests" ),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   537
			banner = id( "qunit-banner" ),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   538
			result = id( "qunit-testresult" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   539
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   540
		if ( tests ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   541
			tests.innerHTML = "";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   542
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   543
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   544
		if ( banner ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   545
			banner.className = "";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   546
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   547
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   548
		if ( result ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   549
			result.parentNode.removeChild( result );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   550
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   551
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   552
		if ( tests ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   553
			result = document.createElement( "p" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   554
			result.id = "qunit-testresult";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   555
			result.className = "result";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   556
			tests.parentNode.insertBefore( result, tests );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   557
			result.innerHTML = 'Running...<br/>&nbsp;';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   558
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   559
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   560
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   561
	/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   562
	 * Resets the test setup. Useful for tests that modify the DOM.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   563
	 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   564
	 * If jQuery is available, uses jQuery's html(), otherwise just innerHTML.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   565
	 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   566
	reset: function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   567
		if ( window.jQuery ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   568
			jQuery( "#qunit-fixture" ).html( config.fixture );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   569
		} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   570
			var main = id( 'qunit-fixture' );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   571
			if ( main ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   572
				main.innerHTML = config.fixture;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   573
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   574
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   575
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   576
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   577
	/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   578
	 * Trigger an event on an element.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   579
	 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   580
	 * @example triggerEvent( document.body, "click" );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   581
	 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   582
	 * @param DOMElement elem
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   583
	 * @param String type
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   584
	 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   585
	triggerEvent: function( elem, type, event ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   586
		if ( document.createEvent ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   587
			event = document.createEvent("MouseEvents");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   588
			event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   589
				0, 0, 0, 0, 0, false, false, false, false, 0, null);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   590
			elem.dispatchEvent( event );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   591
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   592
		} else if ( elem.fireEvent ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   593
			elem.fireEvent("on"+type);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   594
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   595
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   596
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   597
	// Safe object type checking
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   598
	is: function( type, obj ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   599
		return QUnit.objectType( obj ) == type;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   600
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   601
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   602
	objectType: function( obj ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   603
		if (typeof obj === "undefined") {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   604
				return "undefined";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   605
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   606
		// consider: typeof null === object
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   607
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   608
		if (obj === null) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   609
				return "null";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   610
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   611
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   612
		var type = Object.prototype.toString.call( obj )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   613
			.match(/^\[object\s(.*)\]$/)[1] || '';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   614
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   615
		switch (type) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   616
				case 'Number':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   617
						if (isNaN(obj)) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   618
								return "nan";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   619
						} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   620
								return "number";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   621
						}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   622
				case 'String':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   623
				case 'Boolean':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   624
				case 'Array':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   625
				case 'Date':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   626
				case 'RegExp':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   627
				case 'Function':
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   628
						return type.toLowerCase();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   629
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   630
		if (typeof obj === "object") {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   631
				return "object";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   632
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   633
		return undefined;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   634
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   635
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   636
	push: function(result, actual, expected, message) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   637
		var details = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   638
			result: result,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   639
			message: message,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   640
			actual: actual,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   641
			expected: expected
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   642
		};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   643
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   644
		message = escapeInnerText(message) || (result ? "okay" : "failed");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   645
		message = '<span class="test-message">' + message + "</span>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   646
		expected = escapeInnerText(QUnit.jsDump.parse(expected));
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   647
		actual = escapeInnerText(QUnit.jsDump.parse(actual));
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   648
		var output = message + '<table><tr class="test-expected"><th>Expected: </th><td><pre>' + expected + '</pre></td></tr>';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   649
		if (actual != expected) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   650
			output += '<tr class="test-actual"><th>Result: </th><td><pre>' + actual + '</pre></td></tr>';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   651
			output += '<tr class="test-diff"><th>Diff: </th><td><pre>' + QUnit.diff(expected, actual) +'</pre></td></tr>';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   652
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   653
		if (!result) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   654
			var source = sourceFromStacktrace();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   655
			if (source) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   656
				details.source = source;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   657
				output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeInnerText(source) + '</pre></td></tr>';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   658
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   659
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   660
		output += "</table>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   661
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   662
		runLoggingCallbacks( 'log', QUnit, details );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   663
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   664
		config.current.assertions.push({
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   665
			result: !!result,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   666
			message: output
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   667
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   668
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   669
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   670
	url: function( params ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   671
		params = extend( extend( {}, QUnit.urlParams ), params );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   672
		var querystring = "?",
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   673
			key;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   674
		for ( key in params ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   675
			querystring += encodeURIComponent( key ) + "=" +
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   676
				encodeURIComponent( params[ key ] ) + "&";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   677
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   678
		return window.location.pathname + querystring.slice( 0, -1 );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   679
	},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   680
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   681
	extend: extend,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   682
	id: id,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   683
	addEvent: addEvent
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   684
});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   685
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   686
//QUnit.constructor is set to the empty F() above so that we can add to it's prototype later
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   687
//Doing this allows us to tell if the following methods have been overwritten on the actual
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   688
//QUnit object, which is a deprecated way of using the callbacks.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   689
extend(QUnit.constructor.prototype, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   690
	// Logging callbacks; all receive a single argument with the listed properties
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   691
	// run test/logs.html for any related changes
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   692
	begin: registerLoggingCallback('begin'),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   693
	// done: { failed, passed, total, runtime }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   694
	done: registerLoggingCallback('done'),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   695
	// log: { result, actual, expected, message }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   696
	log: registerLoggingCallback('log'),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   697
	// testStart: { name }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   698
	testStart: registerLoggingCallback('testStart'),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   699
	// testDone: { name, failed, passed, total }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   700
	testDone: registerLoggingCallback('testDone'),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   701
	// moduleStart: { name }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   702
	moduleStart: registerLoggingCallback('moduleStart'),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   703
	// moduleDone: { name, failed, passed, total }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   704
	moduleDone: registerLoggingCallback('moduleDone')
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   705
});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   706
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   707
if ( typeof document === "undefined" || document.readyState === "complete" ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   708
	config.autorun = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   709
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   710
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   711
QUnit.load = function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   712
	runLoggingCallbacks( 'begin', QUnit, {} );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   713
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   714
	// Initialize the config, saving the execution queue
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   715
	var oldconfig = extend({}, config);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   716
	QUnit.init();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   717
	extend(config, oldconfig);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   718
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   719
	config.blocking = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   720
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   721
	var urlConfigHtml = '', len = config.urlConfig.length;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   722
	for ( var i = 0, val; i < len, val = config.urlConfig[i]; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   723
		config[val] = QUnit.urlParams[val];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   724
		urlConfigHtml += '<label><input name="' + val + '" type="checkbox"' + ( config[val] ? ' checked="checked"' : '' ) + '>' + val + '</label>';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   725
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   726
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   727
	var userAgent = id("qunit-userAgent");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   728
	if ( userAgent ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   729
		userAgent.innerHTML = navigator.userAgent;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   730
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   731
	var banner = id("qunit-header");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   732
	if ( banner ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   733
		banner.innerHTML = '<a href="' + QUnit.url({ filter: undefined }) + '"> ' + banner.innerHTML + '</a> ' + urlConfigHtml;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   734
		addEvent( banner, "change", function( event ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   735
			var params = {};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   736
			params[ event.target.name ] = event.target.checked ? true : undefined;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   737
			window.location = QUnit.url( params );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   738
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   739
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   740
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   741
	var toolbar = id("qunit-testrunner-toolbar");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   742
	if ( toolbar ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   743
		var filter = document.createElement("input");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   744
		filter.type = "checkbox";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   745
		filter.id = "qunit-filter-pass";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   746
		addEvent( filter, "click", function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   747
			var ol = document.getElementById("qunit-tests");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   748
			if ( filter.checked ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   749
				ol.className = ol.className + " hidepass";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   750
			} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   751
				var tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " ";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   752
				ol.className = tmp.replace(/ hidepass /, " ");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   753
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   754
			if ( defined.sessionStorage ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   755
				if (filter.checked) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   756
					sessionStorage.setItem("qunit-filter-passed-tests", "true");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   757
				} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   758
					sessionStorage.removeItem("qunit-filter-passed-tests");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   759
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   760
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   761
		});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   762
		if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem("qunit-filter-passed-tests") ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   763
			filter.checked = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   764
			var ol = document.getElementById("qunit-tests");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   765
			ol.className = ol.className + " hidepass";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   766
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   767
		toolbar.appendChild( filter );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   768
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   769
		var label = document.createElement("label");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   770
		label.setAttribute("for", "qunit-filter-pass");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   771
		label.innerHTML = "Hide passed tests";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   772
		toolbar.appendChild( label );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   773
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   774
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   775
	var main = id('qunit-fixture');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   776
	if ( main ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   777
		config.fixture = main.innerHTML;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   778
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   779
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   780
	if (config.autostart) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   781
		QUnit.start();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   782
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   783
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   784
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   785
addEvent(window, "load", QUnit.load);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   786
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   787
function done() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   788
	config.autorun = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   789
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   790
	// Log the last module results
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   791
	if ( config.currentModule ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   792
		runLoggingCallbacks( 'moduleDone', QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   793
			name: config.currentModule,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   794
			failed: config.moduleStats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   795
			passed: config.moduleStats.all - config.moduleStats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   796
			total: config.moduleStats.all
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   797
		} );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   798
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   799
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   800
	var banner = id("qunit-banner"),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   801
		tests = id("qunit-tests"),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   802
		runtime = +new Date - config.started,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   803
		passed = config.stats.all - config.stats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   804
		html = [
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   805
			'Tests completed in ',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   806
			runtime,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   807
			' milliseconds.<br/>',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   808
			'<span class="passed">',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   809
			passed,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   810
			'</span> tests of <span class="total">',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   811
			config.stats.all,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   812
			'</span> passed, <span class="failed">',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   813
			config.stats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   814
			'</span> failed.'
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   815
		].join('');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   816
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   817
	if ( banner ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   818
		banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   819
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   820
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   821
	if ( tests ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   822
		id( "qunit-testresult" ).innerHTML = html;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   823
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   824
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   825
	if ( config.altertitle && typeof document !== "undefined" && document.title ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   826
		// show ✖ for good, ✔ for bad suite result in title
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   827
		// use escape sequences in case file gets loaded with non-utf-8-charset
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   828
		document.title = [
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   829
			(config.stats.bad ? "\u2716" : "\u2714"),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   830
			document.title.replace(/^[\u2714\u2716] /i, "")
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   831
		].join(" ");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   832
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   833
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   834
	runLoggingCallbacks( 'done', QUnit, {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   835
		failed: config.stats.bad,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   836
		passed: passed,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   837
		total: config.stats.all,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   838
		runtime: runtime
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   839
	} );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   840
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   841
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   842
function validTest( name ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   843
	var filter = config.filter,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   844
		run = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   845
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   846
	if ( !filter ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   847
		return true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   848
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   849
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   850
	var not = filter.charAt( 0 ) === "!";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   851
	if ( not ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   852
		filter = filter.slice( 1 );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   853
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   854
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   855
	if ( name.indexOf( filter ) !== -1 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   856
		return !not;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   857
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   858
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   859
	if ( not ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   860
		run = true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   861
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   862
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   863
	return run;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   864
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   865
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   866
// so far supports only Firefox, Chrome and Opera (buggy)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   867
// could be extended in the future to use something like https://github.com/csnover/TraceKit
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   868
function sourceFromStacktrace() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   869
	try {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   870
		throw new Error();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   871
	} catch ( e ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   872
		if (e.stacktrace) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   873
			// Opera
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   874
			return e.stacktrace.split("\n")[6];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   875
		} else if (e.stack) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   876
			// Firefox, Chrome
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   877
			return e.stack.split("\n")[4];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   878
		} else if (e.sourceURL) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   879
			// Safari, PhantomJS
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   880
			// TODO sourceURL points at the 'throw new Error' line above, useless
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   881
			//return e.sourceURL + ":" + e.line;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   882
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   883
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   884
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   885
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   886
function escapeInnerText(s) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   887
	if (!s) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   888
		return "";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   889
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   890
	s = s + "";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   891
	return s.replace(/[\&<>]/g, function(s) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   892
		switch(s) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   893
			case "&": return "&amp;";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   894
			case "<": return "&lt;";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   895
			case ">": return "&gt;";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   896
			default: return s;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   897
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   898
	});
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   899
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   900
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   901
function synchronize( callback ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   902
	config.queue.push( callback );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   903
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   904
	if ( config.autorun && !config.blocking ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   905
		process();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   906
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   907
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   908
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   909
function process() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   910
	var start = (new Date()).getTime();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   911
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   912
	while ( config.queue.length && !config.blocking ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   913
		if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   914
			config.queue.shift()();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   915
		} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   916
			window.setTimeout( process, 13 );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   917
			break;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   918
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   919
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   920
	if (!config.blocking && !config.queue.length) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   921
		done();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   922
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   923
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   924
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   925
function saveGlobal() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   926
	config.pollution = [];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   927
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   928
	if ( config.noglobals ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   929
		for ( var key in window ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   930
			config.pollution.push( key );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   931
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   932
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   933
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   934
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   935
function checkPollution( name ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   936
	var old = config.pollution;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   937
	saveGlobal();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   938
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   939
	var newGlobals = diff( config.pollution, old );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   940
	if ( newGlobals.length > 0 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   941
		ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   942
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   943
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   944
	var deletedGlobals = diff( old, config.pollution );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   945
	if ( deletedGlobals.length > 0 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   946
		ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   947
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   948
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   949
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   950
// returns a new Array with the elements that are in a but not in b
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   951
function diff( a, b ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   952
	var result = a.slice();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   953
	for ( var i = 0; i < result.length; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   954
		for ( var j = 0; j < b.length; j++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   955
			if ( result[i] === b[j] ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   956
				result.splice(i, 1);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   957
				i--;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   958
				break;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   959
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   960
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   961
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   962
	return result;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   963
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   964
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   965
function fail(message, exception, callback) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   966
	if ( typeof console !== "undefined" && console.error && console.warn ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   967
		console.error(message);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   968
		console.error(exception);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   969
		console.warn(callback.toString());
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   970
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   971
	} else if ( window.opera && opera.postError ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   972
		opera.postError(message, exception, callback.toString);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   973
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   974
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   975
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   976
function extend(a, b) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   977
	for ( var prop in b ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   978
		if ( b[prop] === undefined ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   979
			delete a[prop];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   980
		} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   981
			a[prop] = b[prop];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   982
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   983
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   984
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   985
	return a;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   986
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   987
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   988
function addEvent(elem, type, fn) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   989
	if ( elem.addEventListener ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   990
		elem.addEventListener( type, fn, false );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   991
	} else if ( elem.attachEvent ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   992
		elem.attachEvent( "on" + type, fn );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   993
	} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   994
		fn();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   995
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   996
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   997
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   998
function id(name) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
   999
	return !!(typeof document !== "undefined" && document && document.getElementById) &&
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1000
		document.getElementById( name );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1001
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1002
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1003
function registerLoggingCallback(key){
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1004
	return function(callback){
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1005
		config[key].push( callback );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1006
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1007
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1008
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1009
// Supports deprecated method of completely overwriting logging callbacks
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1010
function runLoggingCallbacks(key, scope, args) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1011
	//debugger;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1012
	var callbacks;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1013
	if ( QUnit.hasOwnProperty(key) ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1014
		QUnit[key].call(scope, args);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1015
	} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1016
		callbacks = config[key];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1017
		for( var i = 0; i < callbacks.length; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1018
			callbacks[i].call( scope, args );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1019
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1020
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1021
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1022
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1023
// Test for equality any JavaScript type.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1024
// Author: Philippe Rathé <prathe@gmail.com>
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1025
QUnit.equiv = function () {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1026
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1027
	var innerEquiv; // the real equiv function
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1028
	var callers = []; // stack to decide between skip/abort functions
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1029
	var parents = []; // stack to avoiding loops from circular referencing
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1030
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1031
	// Call the o related callback with the given arguments.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1032
	function bindCallbacks(o, callbacks, args) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1033
		var prop = QUnit.objectType(o);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1034
		if (prop) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1035
			if (QUnit.objectType(callbacks[prop]) === "function") {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1036
				return callbacks[prop].apply(callbacks, args);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1037
			} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1038
				return callbacks[prop]; // or undefined
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1039
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1040
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1041
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1042
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1043
	var callbacks = function () {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1044
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1045
		// for string, boolean, number and null
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1046
		function useStrictEquality(b, a) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1047
			if (b instanceof a.constructor || a instanceof b.constructor) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1048
				// to catch short annotaion VS 'new' annotation of a
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1049
				// declaration
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1050
				// e.g. var i = 1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1051
				// var j = new Number(1);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1052
				return a == b;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1053
			} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1054
				return a === b;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1055
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1056
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1057
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1058
		return {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1059
			"string" : useStrictEquality,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1060
			"boolean" : useStrictEquality,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1061
			"number" : useStrictEquality,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1062
			"null" : useStrictEquality,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1063
			"undefined" : useStrictEquality,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1064
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1065
			"nan" : function(b) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1066
				return isNaN(b);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1067
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1068
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1069
			"date" : function(b, a) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1070
				return QUnit.objectType(b) === "date"
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1071
						&& a.valueOf() === b.valueOf();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1072
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1073
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1074
			"regexp" : function(b, a) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1075
				return QUnit.objectType(b) === "regexp"
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1076
						&& a.source === b.source && // the regex itself
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1077
						a.global === b.global && // and its modifers
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1078
													// (gmi) ...
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1079
						a.ignoreCase === b.ignoreCase
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1080
						&& a.multiline === b.multiline;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1081
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1082
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1083
			// - skip when the property is a method of an instance (OOP)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1084
			// - abort otherwise,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1085
			// initial === would have catch identical references anyway
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1086
			"function" : function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1087
				var caller = callers[callers.length - 1];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1088
				return caller !== Object && typeof caller !== "undefined";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1089
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1090
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1091
			"array" : function(b, a) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1092
				var i, j, loop;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1093
				var len;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1094
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1095
				// b could be an object literal here
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1096
				if (!(QUnit.objectType(b) === "array")) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1097
					return false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1098
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1099
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1100
				len = a.length;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1101
				if (len !== b.length) { // safe and faster
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1102
					return false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1103
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1104
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1105
				// track reference to avoid circular references
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1106
				parents.push(a);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1107
				for (i = 0; i < len; i++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1108
					loop = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1109
					for (j = 0; j < parents.length; j++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1110
						if (parents[j] === a[i]) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1111
							loop = true;// dont rewalk array
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1112
						}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1113
					}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1114
					if (!loop && !innerEquiv(a[i], b[i])) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1115
						parents.pop();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1116
						return false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1117
					}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1118
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1119
				parents.pop();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1120
				return true;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1121
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1122
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1123
			"object" : function(b, a) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1124
				var i, j, loop;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1125
				var eq = true; // unless we can proove it
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1126
				var aProperties = [], bProperties = []; // collection of
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1127
														// strings
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1128
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1129
				// comparing constructors is more strict than using
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1130
				// instanceof
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1131
				if (a.constructor !== b.constructor) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1132
					return false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1133
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1134
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1135
				// stack constructor before traversing properties
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1136
				callers.push(a.constructor);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1137
				// track reference to avoid circular references
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1138
				parents.push(a);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1139
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1140
				for (i in a) { // be strict: don't ensures hasOwnProperty
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1141
								// and go deep
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1142
					loop = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1143
					for (j = 0; j < parents.length; j++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1144
						if (parents[j] === a[i])
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1145
							loop = true; // don't go down the same path
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1146
											// twice
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1147
					}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1148
					aProperties.push(i); // collect a's properties
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1149
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1150
					if (!loop && !innerEquiv(a[i], b[i])) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1151
						eq = false;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1152
						break;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1153
					}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1154
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1155
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1156
				callers.pop(); // unstack, we are done
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1157
				parents.pop();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1158
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1159
				for (i in b) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1160
					bProperties.push(i); // collect b's properties
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1161
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1162
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1163
				// Ensures identical properties name
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1164
				return eq
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1165
						&& innerEquiv(aProperties.sort(), bProperties
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1166
								.sort());
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1167
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1168
		};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1169
	}();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1170
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1171
	innerEquiv = function() { // can take multiple arguments
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1172
		var args = Array.prototype.slice.apply(arguments);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1173
		if (args.length < 2) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1174
			return true; // end transition
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1175
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1176
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1177
		return (function(a, b) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1178
			if (a === b) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1179
				return true; // catch the most you can
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1180
			} else if (a === null || b === null || typeof a === "undefined"
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1181
					|| typeof b === "undefined"
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1182
					|| QUnit.objectType(a) !== QUnit.objectType(b)) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1183
				return false; // don't lose time with error prone cases
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1184
			} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1185
				return bindCallbacks(a, callbacks, [ b, a ]);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1186
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1187
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1188
			// apply transition with (1..n) arguments
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1189
		})(args[0], args[1])
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1190
				&& arguments.callee.apply(this, args.splice(1,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1191
						args.length - 1));
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1192
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1193
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1194
	return innerEquiv;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1195
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1196
}();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1197
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1198
/**
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1199
 * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com |
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1200
 * http://flesler.blogspot.com Licensed under BSD
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1201
 * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1202
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1203
 * @projectDescription Advanced and extensible data dumping for Javascript.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1204
 * @version 1.0.0
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1205
 * @author Ariel Flesler
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1206
 * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1207
 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1208
QUnit.jsDump = (function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1209
	function quote( str ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1210
		return '"' + str.toString().replace(/"/g, '\\"') + '"';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1211
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1212
	function literal( o ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1213
		return o + '';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1214
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1215
	function join( pre, arr, post ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1216
		var s = jsDump.separator(),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1217
			base = jsDump.indent(),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1218
			inner = jsDump.indent(1);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1219
		if ( arr.join )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1220
			arr = arr.join( ',' + s + inner );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1221
		if ( !arr )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1222
			return pre + post;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1223
		return [ pre, inner + arr, base + post ].join(s);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1224
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1225
	function array( arr, stack ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1226
		var i = arr.length, ret = Array(i);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1227
		this.up();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1228
		while ( i-- )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1229
			ret[i] = this.parse( arr[i] , undefined , stack);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1230
		this.down();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1231
		return join( '[', ret, ']' );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1232
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1233
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1234
	var reName = /^function (\w+)/;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1235
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1236
	var jsDump = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1237
		parse:function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1238
			stack = stack || [ ];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1239
			var parser = this.parsers[ type || this.typeOf(obj) ];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1240
			type = typeof parser;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1241
			var inStack = inArray(obj, stack);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1242
			if (inStack != -1) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1243
				return 'recursion('+(inStack - stack.length)+')';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1244
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1245
			//else
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1246
			if (type == 'function')  {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1247
					stack.push(obj);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1248
					var res = parser.call( this, obj, stack );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1249
					stack.pop();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1250
					return res;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1251
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1252
			// else
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1253
			return (type == 'string') ? parser : this.parsers.error;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1254
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1255
		typeOf:function( obj ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1256
			var type;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1257
			if ( obj === null ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1258
				type = "null";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1259
			} else if (typeof obj === "undefined") {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1260
				type = "undefined";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1261
			} else if (QUnit.is("RegExp", obj)) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1262
				type = "regexp";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1263
			} else if (QUnit.is("Date", obj)) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1264
				type = "date";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1265
			} else if (QUnit.is("Function", obj)) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1266
				type = "function";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1267
			} else if (typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined") {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1268
				type = "window";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1269
			} else if (obj.nodeType === 9) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1270
				type = "document";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1271
			} else if (obj.nodeType) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1272
				type = "node";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1273
			} else if (typeof obj === "object" && typeof obj.length === "number" && obj.length >= 0) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1274
				type = "array";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1275
			} else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1276
				type = typeof obj;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1277
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1278
			return type;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1279
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1280
		separator:function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1281
			return this.multiline ?	this.HTML ? '<br />' : '\n' : this.HTML ? '&nbsp;' : ' ';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1282
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1283
		indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1284
			if ( !this.multiline )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1285
				return '';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1286
			var chr = this.indentChar;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1287
			if ( this.HTML )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1288
				chr = chr.replace(/\t/g,'   ').replace(/ /g,'&nbsp;');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1289
			return Array( this._depth_ + (extra||0) ).join(chr);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1290
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1291
		up:function( a ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1292
			this._depth_ += a || 1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1293
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1294
		down:function( a ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1295
			this._depth_ -= a || 1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1296
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1297
		setParser:function( name, parser ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1298
			this.parsers[name] = parser;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1299
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1300
		// The next 3 are exposed so you can use them
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1301
		quote:quote,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1302
		literal:literal,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1303
		join:join,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1304
		//
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1305
		_depth_: 1,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1306
		// This is the list of parsers, to modify them, use jsDump.setParser
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1307
		parsers:{
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1308
			window: '[Window]',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1309
			document: '[Document]',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1310
			error:'[ERROR]', //when no parser is found, shouldn't happen
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1311
			unknown: '[Unknown]',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1312
			'null':'null',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1313
			'undefined':'undefined',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1314
			'function':function( fn ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1315
				var ret = 'function',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1316
					name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1317
				if ( name )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1318
					ret += ' ' + name;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1319
				ret += '(';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1320
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1321
				ret = [ ret, QUnit.jsDump.parse( fn, 'functionArgs' ), '){'].join('');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1322
				return join( ret, QUnit.jsDump.parse(fn,'functionCode'), '}' );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1323
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1324
			array: array,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1325
			nodelist: array,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1326
			arguments: array,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1327
			object:function( map, stack ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1328
				var ret = [ ];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1329
				QUnit.jsDump.up();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1330
				for ( var key in map ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1331
				    var val = map[key];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1332
					ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(val, undefined, stack));
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1333
                }
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1334
				QUnit.jsDump.down();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1335
				return join( '{', ret, '}' );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1336
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1337
			node:function( node ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1338
				var open = QUnit.jsDump.HTML ? '&lt;' : '<',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1339
					close = QUnit.jsDump.HTML ? '&gt;' : '>';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1340
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1341
				var tag = node.nodeName.toLowerCase(),
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1342
					ret = open + tag;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1343
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1344
				for ( var a in QUnit.jsDump.DOMAttrs ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1345
					var val = node[QUnit.jsDump.DOMAttrs[a]];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1346
					if ( val )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1347
						ret += ' ' + a + '=' + QUnit.jsDump.parse( val, 'attribute' );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1348
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1349
				return ret + close + open + '/' + tag + close;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1350
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1351
			functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1352
				var l = fn.length;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1353
				if ( !l ) return '';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1354
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1355
				var args = Array(l);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1356
				while ( l-- )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1357
					args[l] = String.fromCharCode(97+l);//97 is 'a'
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1358
				return ' ' + args.join(', ') + ' ';
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1359
			},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1360
			key:quote, //object calls it internally, the key part of an item in a map
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1361
			functionCode:'[code]', //function calls it internally, it's the content of the function
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1362
			attribute:quote, //node calls it internally, it's an html attribute value
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1363
			string:quote,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1364
			date:quote,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1365
			regexp:literal, //regex
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1366
			number:literal,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1367
			'boolean':literal
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1368
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1369
		DOMAttrs:{//attributes to dump from nodes, name=>realName
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1370
			id:'id',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1371
			name:'name',
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1372
			'class':'className'
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1373
		},
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1374
		HTML:false,//if true, entities are escaped ( <, >, \t, space and \n )
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1375
		indentChar:'  ',//indentation unit
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1376
		multiline:true //if true, items in a collection, are separated by a \n, else just a space.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1377
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1378
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1379
	return jsDump;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1380
})();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1381
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1382
// from Sizzle.js
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1383
function getText( elems ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1384
	var ret = "", elem;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1385
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1386
	for ( var i = 0; elems[i]; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1387
		elem = elems[i];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1388
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1389
		// Get the text from text nodes and CDATA nodes
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1390
		if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1391
			ret += elem.nodeValue;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1392
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1393
		// Traverse everything else, except comment nodes
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1394
		} else if ( elem.nodeType !== 8 ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1395
			ret += getText( elem.childNodes );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1396
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1397
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1398
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1399
	return ret;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1400
};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1401
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1402
//from jquery.js
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1403
function inArray( elem, array ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1404
	if ( array.indexOf ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1405
		return array.indexOf( elem );
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1406
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1407
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1408
	for ( var i = 0, length = array.length; i < length; i++ ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1409
		if ( array[ i ] === elem ) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1410
			return i;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1411
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1412
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1413
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1414
	return -1;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1415
}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1416
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1417
/*
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1418
 * Javascript Diff Algorithm
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1419
 *  By John Resig (http://ejohn.org/)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1420
 *  Modified by Chu Alan "sprite"
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1421
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1422
 * Released under the MIT license.
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1423
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1424
 * More Info:
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1425
 *  http://ejohn.org/projects/javascript-diff-algorithm/
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1426
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1427
 * Usage: QUnit.diff(expected, actual)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1428
 *
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1429
 * 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"
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1430
 */
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1431
QUnit.diff = (function() {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1432
	function diff(o, n) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1433
		var ns = {};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1434
		var os = {};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1435
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1436
		for (var i = 0; i < n.length; i++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1437
			if (ns[n[i]] == null)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1438
				ns[n[i]] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1439
					rows: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1440
					o: null
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1441
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1442
			ns[n[i]].rows.push(i);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1443
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1444
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1445
		for (var i = 0; i < o.length; i++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1446
			if (os[o[i]] == null)
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1447
				os[o[i]] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1448
					rows: [],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1449
					n: null
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1450
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1451
			os[o[i]].rows.push(i);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1452
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1453
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1454
		for (var i in ns) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1455
			if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1456
				n[ns[i].rows[0]] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1457
					text: n[ns[i].rows[0]],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1458
					row: os[i].rows[0]
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1459
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1460
				o[os[i].rows[0]] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1461
					text: o[os[i].rows[0]],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1462
					row: ns[i].rows[0]
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1463
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1464
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1465
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1466
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1467
		for (var i = 0; i < n.length - 1; i++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1468
			if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null &&
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1469
			n[i + 1] == o[n[i].row + 1]) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1470
				n[i + 1] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1471
					text: n[i + 1],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1472
					row: n[i].row + 1
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1473
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1474
				o[n[i].row + 1] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1475
					text: o[n[i].row + 1],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1476
					row: i + 1
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1477
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1478
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1479
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1480
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1481
		for (var i = n.length - 1; i > 0; i--) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1482
			if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null &&
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1483
			n[i - 1] == o[n[i].row - 1]) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1484
				n[i - 1] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1485
					text: n[i - 1],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1486
					row: n[i].row - 1
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1487
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1488
				o[n[i].row - 1] = {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1489
					text: o[n[i].row - 1],
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1490
					row: i - 1
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1491
				};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1492
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1493
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1494
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1495
		return {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1496
			o: o,
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1497
			n: n
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1498
		};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1499
	}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1500
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1501
	return function(o, n) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1502
		o = o.replace(/\s+$/, '');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1503
		n = n.replace(/\s+$/, '');
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1504
		var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/));
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1505
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1506
		var str = "";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1507
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1508
		var oSpace = o.match(/\s+/g);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1509
		if (oSpace == null) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1510
			oSpace = [" "];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1511
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1512
		else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1513
			oSpace.push(" ");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1514
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1515
		var nSpace = n.match(/\s+/g);
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1516
		if (nSpace == null) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1517
			nSpace = [" "];
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1518
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1519
		else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1520
			nSpace.push(" ");
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1521
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1522
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1523
		if (out.n.length == 0) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1524
			for (var i = 0; i < out.o.length; i++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1525
				str += '<del>' + out.o[i] + oSpace[i] + "</del>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1526
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1527
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1528
		else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1529
			if (out.n[0].text == null) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1530
				for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1531
					str += '<del>' + out.o[n] + oSpace[n] + "</del>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1532
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1533
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1534
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1535
			for (var i = 0; i < out.n.length; i++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1536
				if (out.n[i].text == null) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1537
					str += '<ins>' + out.n[i] + nSpace[i] + "</ins>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1538
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1539
				else {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1540
					var pre = "";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1541
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1542
					for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) {
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1543
						pre += '<del>' + out.o[n] + oSpace[n] + "</del>";
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1544
					}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1545
					str += " " + out.n[i].text + nSpace[i] + pre;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1546
				}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1547
			}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1548
		}
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1549
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1550
		return str;
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1551
	};
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1552
})();
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1553
eabfc9a2eb35 Added unit testing with QUnit.
hamidouk
parents:
diff changeset
  1554
})(this);