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