envjs19 0.3.8.20101029121421
Sign up to get free protection for your applications and to get access to all the features.
- data/.jslintrbrc +30 -0
- data/.project +17 -0
- data/CHANGELOG.rdoc +57 -0
- data/DTD/xhtml-lat1.ent +196 -0
- data/DTD/xhtml-special.ent +80 -0
- data/DTD/xhtml-symbol.ent +237 -0
- data/DTD/xhtml.soc +14 -0
- data/DTD/xhtml1-frameset.dtd +1235 -0
- data/DTD/xhtml1-strict.dtd +978 -0
- data/DTD/xhtml1-transitional.dtd +1201 -0
- data/DTD/xhtml1.dcl +192 -0
- data/Makefile +7 -0
- data/Manifest.txt +280 -0
- data/README.rdoc +65 -0
- data/Rakefile +196 -0
- data/Wakefile +11 -0
- data/bin/envjsrb +257 -0
- data/build.properties +9 -0
- data/build.xml +247 -0
- data/gm/jquery.js +6002 -0
- data/gm/mainx.js +2648 -0
- data/gm/sensx.js +135 -0
- data/gm/t.js +6 -0
- data/gm/x.html +76 -0
- data/htmlparser/BrowserTreeBuilder.java +456 -0
- data/htmlparser/README +34 -0
- data/htmlparser/build.sh +38 -0
- data/jsl/jsl +0 -0
- data/jsl/jsl.default.conf +129 -0
- data/jsl/jsl.exe +0 -0
- data/lib/envjs.rb +35 -0
- data/lib/envjs/event_loop.js +206 -0
- data/lib/envjs/net.rb +3 -0
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +69 -0
- data/lib/envjs/options.rb +11 -0
- data/lib/envjs/runtime.rb +346 -0
- data/lib/envjs/tempfile.rb +24 -0
- data/licenses/GPL-LICENSE.txt +278 -0
- data/licenses/MIT-LICENSE.txt +20 -0
- data/src/base64.js +80 -0
- data/src/build.js +6 -0
- data/src/cruft/bad.html +24 -0
- data/src/cruft/dom.js +606 -0
- data/src/cruft/element.js +297 -0
- data/src/cruft/good.html +30 -0
- data/src/cruft/good.js +32 -0
- data/src/cruft/internal.js +81 -0
- data/src/cruft/parser.js +458 -0
- data/src/css/properties.js +293 -0
- data/src/css/rule.js +22 -0
- data/src/css/sizzle.js +717 -0
- data/src/css/stylesheet.js +52 -0
- data/src/dom/attr.js +55 -0
- data/src/dom/cdatasection.js +31 -0
- data/src/dom/characterdata.js +119 -0
- data/src/dom/comment.js +30 -0
- data/src/dom/doctype.js +9 -0
- data/src/dom/document.js +1023 -0
- data/src/dom/dom.js +134 -0
- data/src/dom/element.js +217 -0
- data/src/dom/entities.js +273 -0
- data/src/dom/exception.js +28 -0
- data/src/dom/fragment.js +37 -0
- data/src/dom/implementation.js +140 -0
- data/src/dom/instruction.js +51 -0
- data/src/dom/namednodemap.js +374 -0
- data/src/dom/namespace.js +50 -0
- data/src/dom/node.js +618 -0
- data/src/dom/nodelist.js +195 -0
- data/src/dom/parser.js +1207 -0
- data/src/dom/text.js +73 -0
- data/src/event/event.js +47 -0
- data/src/event/mouseevent.js +4 -0
- data/src/event/uievent.js +8 -0
- data/src/html/a.js +110 -0
- data/src/html/anchor.js +80 -0
- data/src/html/area.js +57 -0
- data/src/html/base.js +26 -0
- data/src/html/blockquote-q.js +19 -0
- data/src/html/body.js +19 -0
- data/src/html/button.js +21 -0
- data/src/html/canvas.js +14 -0
- data/src/html/col-colgroup.js +49 -0
- data/src/html/collection.js +72 -0
- data/src/html/cookie.js +153 -0
- data/src/html/del-ins.js +25 -0
- data/src/html/div.js +28 -0
- data/src/html/document.js +364 -0
- data/src/html/element.js +382 -0
- data/src/html/fieldset.js +19 -0
- data/src/html/form.js +484 -0
- data/src/html/frame.js +89 -0
- data/src/html/frameset.js +25 -0
- data/src/html/head.js +44 -0
- data/src/html/html.js +0 -0
- data/src/html/htmlparser.js +340 -0
- data/src/html/iframe.js +26 -0
- data/src/html/image.js +0 -0
- data/src/html/img.js +62 -0
- data/src/html/input-elements.js +307 -0
- data/src/html/input.js +65 -0
- data/src/html/label.js +26 -0
- data/src/html/legend.js +19 -0
- data/src/html/link.js +82 -0
- data/src/html/map.js +22 -0
- data/src/html/meta.js +37 -0
- data/src/html/object.js +89 -0
- data/src/html/optgroup.js +25 -0
- data/src/html/option.js +103 -0
- data/src/html/param.js +38 -0
- data/src/html/script.js +122 -0
- data/src/html/select.js +132 -0
- data/src/html/style.js +31 -0
- data/src/html/table.js +199 -0
- data/src/html/tbody-thead-tfoot.js +92 -0
- data/src/html/td-th.js +18 -0
- data/src/html/textarea.js +31 -0
- data/src/html/title.js +20 -0
- data/src/html/tr.js +114 -0
- data/src/intro.js +141 -0
- data/src/outro.js +70 -0
- data/src/parser/html5.detailed.js +10762 -0
- data/src/parser/html5.min.js +503 -0
- data/src/parser/html5.pretty.js +10815 -0
- data/src/parser/intro.js +42 -0
- data/src/parser/outro.js +9 -0
- data/src/platform/core.js +323 -0
- data/src/platform/johnson.js +484 -0
- data/src/platform/rhino.js +327 -0
- data/src/platform/static/intro.js +41 -0
- data/src/platform/static/outro.js +30 -0
- data/src/profile/aop.js +238 -0
- data/src/profile/profile.js +402 -0
- data/src/serializer/xml.js +21 -0
- data/src/svg/animatedstring.js +25 -0
- data/src/svg/document.js +25 -0
- data/src/svg/element.js +22 -0
- data/src/svg/locatable.js +17 -0
- data/src/svg/rect.js +18 -0
- data/src/svg/rectelement.js +24 -0
- data/src/svg/stylable.js +49 -0
- data/src/svg/svgelement.js +22 -0
- data/src/svg/transformable.js +15 -0
- data/src/window/css.js +15 -0
- data/src/window/dialog.js +16 -0
- data/src/window/document.js +28 -0
- data/src/window/event.js +265 -0
- data/src/window/history.js +62 -0
- data/src/window/location.js +156 -0
- data/src/window/navigator.js +48 -0
- data/src/window/screen.js +53 -0
- data/src/window/timer.js +21 -0
- data/src/window/window.js +284 -0
- data/src/window/xhr.js +135 -0
- data/src/xpath/expression.js +49 -0
- data/src/xpath/implementation.js +2505 -0
- data/src/xpath/result.js +67 -0
- data/src/xpath/util.js +551 -0
- data/src/xpath/xmltoken.js +149 -0
- data/src/xslt/COPYING +34 -0
- data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
- data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
- data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
- data/src/xslt/ajaxslt-0.8.1/README +102 -0
- data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
- data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
- data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
- data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
- data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
- data/src/xslt/implementation.js +625 -0
- data/src/xslt/processor.js +37 -0
- data/src/xslt/util.js +449 -0
- data/test/base64.js +80 -0
- data/test/call-load-test.js +15 -0
- data/test/data.js +45 -0
- data/test/debug.js +53 -0
- data/test/firebug/errorIcon.png +0 -0
- data/test/firebug/firebug.css +209 -0
- data/test/firebug/firebug.html +23 -0
- data/test/firebug/firebug.js +672 -0
- data/test/firebug/firebugx.js +10 -0
- data/test/firebug/infoIcon.png +0 -0
- data/test/firebug/warningIcon.png +0 -0
- data/test/fixtures/html/events.html +171 -0
- data/test/fixtures/html/iframe1.html +46 -0
- data/test/fixtures/html/iframe1a.html +46 -0
- data/test/fixtures/html/iframe2.html +45 -0
- data/test/fixtures/html/iframe3.html +28 -0
- data/test/fixtures/html/iframeN.html +57 -0
- data/test/fixtures/html/malformed.html +181 -0
- data/test/fixtures/html/scope.html +81 -0
- data/test/fixtures/html/trivial.html +19 -0
- data/test/fixtures/html/with_js.html +26 -0
- data/test/fixtures/images/icon-blue.png +0 -0
- data/test/fixtures/js/external_script.js +1 -0
- data/test/fixtures/js/script.js +1 -0
- data/test/fixtures/js/script_error.js +2 -0
- data/test/foo.html +8 -0
- data/test/foo.js +40 -0
- data/test/html/events.html +171 -0
- data/test/html/iframe1.html +46 -0
- data/test/html/iframe1a.html +46 -0
- data/test/html/iframe2.html +45 -0
- data/test/html/iframe3.html +30 -0
- data/test/html/iframeN.html +57 -0
- data/test/html/malformed.html +181 -0
- data/test/html/scope.html +87 -0
- data/test/html/script.js +1 -0
- data/test/html/trivial.html +19 -0
- data/test/html/with_js.html +26 -0
- data/test/index.html +328 -0
- data/test/java-prototype.js +9 -0
- data/test/jquery.js +6002 -0
- data/test/primary-tests.js +26 -0
- data/test/prototype-test.js +13 -0
- data/test/qunit.js +61 -0
- data/test/qunit/qunit/qunit.css +17 -0
- data/test/qunit/qunit/qunit.js +997 -0
- data/test/scope.html +19 -0
- data/test/scope.rb +24 -0
- data/test/smp/dmathieu/index.html +8 -0
- data/test/specs/dist/env.spec.js +1534 -0
- data/test/specs/envjs.spec.css +46 -0
- data/test/specs/parser/html.js +31 -0
- data/test/specs/parser/spec.html +40 -0
- data/test/specs/parser/xml.js +31 -0
- data/test/specs/qunit.bdd.js +210 -0
- data/test/specs/qunit.css +17 -0
- data/test/specs/qunit.js +997 -0
- data/test/specs/template/spec-0.js +31 -0
- data/test/specs/template/spec-1.js +31 -0
- data/test/specs/template/spec.html +40 -0
- data/test/specs/window/css.js +23 -0
- data/test/specs/window/dialog.js +25 -0
- data/test/specs/window/document.js +23 -0
- data/test/specs/window/event.js +25 -0
- data/test/specs/window/history.js +34 -0
- data/test/specs/window/location.js +34 -0
- data/test/specs/window/navigator.js +71 -0
- data/test/specs/window/screen.js +42 -0
- data/test/specs/window/spec.html +48 -0
- data/test/specs/window/timer.js +26 -0
- data/test/specs/window/window.js +53 -0
- data/test/specs/xhr/spec.html +47 -0
- data/test/specs/xhr/xhr.js +31 -0
- data/test/test.js +10 -0
- data/test/unit/dom.js +44 -0
- data/test/unit/elementmembers.js +92 -0
- data/test/unit/events.js +195 -0
- data/test/unit/fixtures/external_script.js +1 -0
- data/test/unit/form.js +40 -0
- data/test/unit/iframe.js +234 -0
- data/test/unit/insertion.js +23 -0
- data/test/unit/multi-window.js +212 -0
- data/test/unit/nu.validator.js +34 -0
- data/test/unit/onload.js +90 -0
- data/test/unit/parser.js +122 -0
- data/test/unit/prototypecompat.js +22 -0
- data/test/unit/proxy.js +6 -0
- data/test/unit/scope.js +209 -0
- data/test/unit/timer.js +115 -0
- data/test/unit/window.js +57 -0
- data/test/x.js +1 -0
- data/test/y.js +1 -0
- metadata +367 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
load("test/qunit.js");
|
2
|
+
|
3
|
+
window.addEventListener("load",function(){
|
4
|
+
print("\n\nTesting with " + whichInterpreter);
|
5
|
+
print("Handling onload for test.js");
|
6
|
+
print("Loading tests.");
|
7
|
+
|
8
|
+
load("test/unit/dom.js");
|
9
|
+
load("test/unit/window.js");
|
10
|
+
load("test/unit/elementmembers.js");
|
11
|
+
load("test/unit/insertion.js");
|
12
|
+
if (multiwindow) {
|
13
|
+
load("test/unit/onload.js");
|
14
|
+
load("test/unit/scope.js"); // must come before frame.js changes page content
|
15
|
+
load("test/unit/iframe.js");
|
16
|
+
load("test/unit/events.js");
|
17
|
+
load("test/unit/multi-window.js");
|
18
|
+
}
|
19
|
+
load("test/unit/parser.js");
|
20
|
+
load("test/unit/timer.js");
|
21
|
+
load("test/unit/form.js");
|
22
|
+
|
23
|
+
print("Load complete. Running tests.");
|
24
|
+
});
|
25
|
+
|
26
|
+
window.location = "test/index.html";
|
@@ -0,0 +1,13 @@
|
|
1
|
+
load("test/qunit.js");
|
2
|
+
|
3
|
+
window.addEventListener("load",function(){
|
4
|
+
print("\n\nTesting with " + whichInterpreter);
|
5
|
+
print("Handling onload for test.js");
|
6
|
+
print("Loading tests.");
|
7
|
+
|
8
|
+
load("test/unit/prototypecompat.js");
|
9
|
+
|
10
|
+
print("Load complete. Running tests.");
|
11
|
+
});
|
12
|
+
|
13
|
+
window.location = "test/index.html";
|
data/test/qunit.js
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
load("test/qunit/qunit/qunit.js");
|
2
|
+
|
3
|
+
(function(){
|
4
|
+
var assertion_index = 0;
|
5
|
+
|
6
|
+
var module_index = 0;
|
7
|
+
var module;
|
8
|
+
|
9
|
+
var test_index = 0;
|
10
|
+
var test;
|
11
|
+
|
12
|
+
QUnit.moduleStart = function(m,te) {
|
13
|
+
module = m;
|
14
|
+
module_index++;
|
15
|
+
};
|
16
|
+
|
17
|
+
QUnit.moduleDone = function(t,f,tx) {
|
18
|
+
var s = module_index + ". module "+t+": ";
|
19
|
+
if ( f ) {
|
20
|
+
s += f + " failure(s) in " + tx + " tests";
|
21
|
+
} else {
|
22
|
+
s += "all " + tx + " tests successful";
|
23
|
+
}
|
24
|
+
// print(s);
|
25
|
+
module = undefined;
|
26
|
+
};
|
27
|
+
|
28
|
+
QUnit.testStart = function(t) {
|
29
|
+
test = t;
|
30
|
+
test_index++;
|
31
|
+
};
|
32
|
+
|
33
|
+
QUnit.testDone = function(t) {
|
34
|
+
test = undefined;
|
35
|
+
}
|
36
|
+
|
37
|
+
QUnit.log = function(r,m) {
|
38
|
+
assertion_index++;
|
39
|
+
var test_string = "";
|
40
|
+
if ( module || test ) {
|
41
|
+
var test_string = "[";
|
42
|
+
if ( module ) {
|
43
|
+
test_string += module;
|
44
|
+
if ( test ) {
|
45
|
+
test_string += ": ";
|
46
|
+
}
|
47
|
+
}
|
48
|
+
if ( test ) {
|
49
|
+
test_string += test;
|
50
|
+
}
|
51
|
+
test_string += "] ";
|
52
|
+
}
|
53
|
+
var s = ( r ? "PASS (" : "FAIL (" ) + assertion_index + ") " + test_string + m;
|
54
|
+
print(s);
|
55
|
+
};
|
56
|
+
|
57
|
+
QUnit.done = function(f,t) {
|
58
|
+
print((t-f) + " Passed, " + f + " Failed, " + t + " Total Tests" );
|
59
|
+
};
|
60
|
+
|
61
|
+
})(QUnit);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
h1#qunit-header { padding: 15px; font-size: large; background-color: #06b; color: white; font-family: 'trebuchet ms', verdana, arial; margin: 0; }
|
2
|
+
h1#qunit-header a { color: white; }
|
3
|
+
|
4
|
+
h2#qunit-banner { height: 2em; border-bottom: 1px solid white; background-color: #eee; margin: 0; font-family: 'trebuchet ms', verdana, arial; }
|
5
|
+
h2#qunit-banner.pass { background-color: green; }
|
6
|
+
h2#qunit-banner.fail { background-color: red; }
|
7
|
+
|
8
|
+
h2#qunit-userAgent { padding: 10px; background-color: #eee; color: black; margin: 0; font-size: small; font-weight: normal; font-family: 'trebuchet ms', verdana, arial; font-size: 10pt; }
|
9
|
+
|
10
|
+
div#qunit-testrunner-toolbar { background: #eee; border-top: 1px solid black; padding: 10px; font-family: 'trebuchet ms', verdana, arial; margin: 0; font-size: 10pt; }
|
11
|
+
|
12
|
+
ol#qunit-tests { font-family: 'trebuchet ms', verdana, arial; font-size: 10pt; }
|
13
|
+
ol#qunit-tests li strong { cursor:pointer; }
|
14
|
+
ol#qunit-tests .pass { color: green; }
|
15
|
+
ol#qunit-tests .fail { color: red; }
|
16
|
+
|
17
|
+
p#qunit-testresult { margin-left: 1em; font-size: 10pt; font-family: 'trebuchet ms', verdana, arial; }
|
@@ -0,0 +1,997 @@
|
|
1
|
+
/*
|
2
|
+
* QUnit - A JavaScript Unit Testing Framework
|
3
|
+
*
|
4
|
+
* http://docs.jquery.com/QUnit
|
5
|
+
*
|
6
|
+
* Copyright (c) 2009 John Resig, Jörn Zaefferer
|
7
|
+
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
8
|
+
* and GPL (GPL-LICENSE.txt) licenses.
|
9
|
+
*/
|
10
|
+
|
11
|
+
(function(window) {
|
12
|
+
|
13
|
+
var QUnit = {
|
14
|
+
|
15
|
+
// Initialize the configuration options
|
16
|
+
init: function init() {
|
17
|
+
config = {
|
18
|
+
stats: { all: 0, bad: 0 },
|
19
|
+
moduleStats: { all: 0, bad: 0 },
|
20
|
+
started: +new Date,
|
21
|
+
blocking: false,
|
22
|
+
autorun: false,
|
23
|
+
assertions: [],
|
24
|
+
filters: [],
|
25
|
+
queue: []
|
26
|
+
};
|
27
|
+
|
28
|
+
var tests = id("qunit-tests"),
|
29
|
+
banner = id("qunit-banner"),
|
30
|
+
result = id("qunit-testresult");
|
31
|
+
|
32
|
+
if ( tests ) {
|
33
|
+
tests.innerHTML = "";
|
34
|
+
}
|
35
|
+
|
36
|
+
if ( banner ) {
|
37
|
+
banner.className = "";
|
38
|
+
}
|
39
|
+
|
40
|
+
if ( result ) {
|
41
|
+
result.parentNode.removeChild( result );
|
42
|
+
}
|
43
|
+
},
|
44
|
+
|
45
|
+
// call on start of module test to prepend name to all tests
|
46
|
+
module: function module(name, testEnvironment) {
|
47
|
+
|
48
|
+
synchronize(function() {
|
49
|
+
if ( config.currentModule ) {
|
50
|
+
QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all );
|
51
|
+
}
|
52
|
+
|
53
|
+
config.currentModule = name;
|
54
|
+
config.moduleTestEnvironment = testEnvironment;
|
55
|
+
config.moduleStats = { all: 0, bad: 0 };
|
56
|
+
|
57
|
+
QUnit.moduleStart( name, testEnvironment );
|
58
|
+
});
|
59
|
+
},
|
60
|
+
|
61
|
+
asyncTest: function asyncTest(testName, expected, callback) {
|
62
|
+
if ( arguments.length === 2 ) {
|
63
|
+
callback = expected;
|
64
|
+
expected = 0;
|
65
|
+
}
|
66
|
+
|
67
|
+
QUnit.test(testName, expected, callback, true);
|
68
|
+
},
|
69
|
+
|
70
|
+
test: function test(testName, expected, callback, async) {
|
71
|
+
var name = testName, testEnvironment = {};
|
72
|
+
|
73
|
+
if ( arguments.length === 2 ) {
|
74
|
+
callback = expected;
|
75
|
+
expected = null;
|
76
|
+
}
|
77
|
+
|
78
|
+
if ( config.currentModule ) {
|
79
|
+
name = config.currentModule + " module: " + name;
|
80
|
+
}
|
81
|
+
|
82
|
+
if ( !validTest(name) ) {
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
synchronize(function() {
|
87
|
+
QUnit.testStart( testName );
|
88
|
+
|
89
|
+
testEnvironment = extend({
|
90
|
+
setup: function() {},
|
91
|
+
teardown: function() {}
|
92
|
+
}, config.moduleTestEnvironment);
|
93
|
+
|
94
|
+
config.assertions = [];
|
95
|
+
config.expected = null;
|
96
|
+
|
97
|
+
if ( arguments.length >= 3 ) {
|
98
|
+
config.expected = callback;
|
99
|
+
callback = arguments[2];
|
100
|
+
}
|
101
|
+
|
102
|
+
try {
|
103
|
+
if ( !config.pollution ) {
|
104
|
+
saveGlobal();
|
105
|
+
}
|
106
|
+
|
107
|
+
testEnvironment.setup.call(testEnvironment);
|
108
|
+
} catch(e) {
|
109
|
+
QUnit.ok( false, "Setup failed on " + name + ": " + e.message );
|
110
|
+
}
|
111
|
+
|
112
|
+
if ( async ) {
|
113
|
+
QUnit.stop();
|
114
|
+
}
|
115
|
+
|
116
|
+
try {
|
117
|
+
callback.call(testEnvironment);
|
118
|
+
} catch(e) {
|
119
|
+
fail("Test " + name + " died, exception and test follows", e, callback);
|
120
|
+
QUnit.ok( false, "Died on test #" + (config.assertions.length + 1) + ": " + e.message );
|
121
|
+
// else next test will carry the responsibility
|
122
|
+
saveGlobal();
|
123
|
+
|
124
|
+
// Restart the tests if they're blocking
|
125
|
+
if ( config.blocking ) {
|
126
|
+
start();
|
127
|
+
}
|
128
|
+
}
|
129
|
+
});
|
130
|
+
|
131
|
+
synchronize(function() {
|
132
|
+
try {
|
133
|
+
checkPollution();
|
134
|
+
testEnvironment.teardown.call(testEnvironment);
|
135
|
+
} catch(e) {
|
136
|
+
QUnit.ok( false, "Teardown failed on " + name + ": " + e.message );
|
137
|
+
}
|
138
|
+
|
139
|
+
try {
|
140
|
+
QUnit.reset();
|
141
|
+
} catch(e) {
|
142
|
+
fail("reset() failed, following Test " + name + ", exception and reset fn follows", e, reset);
|
143
|
+
}
|
144
|
+
|
145
|
+
if ( config.expected && config.expected != config.assertions.length ) {
|
146
|
+
QUnit.ok( false, "Expected " + config.expected + " assertions, but " + config.assertions.length + " were run" );
|
147
|
+
}
|
148
|
+
|
149
|
+
var good = 0, bad = 0,
|
150
|
+
tests = id("qunit-tests");
|
151
|
+
|
152
|
+
config.stats.all += config.assertions.length;
|
153
|
+
config.moduleStats.all += config.assertions.length;
|
154
|
+
|
155
|
+
if ( tests ) {
|
156
|
+
var ol = document.createElement("ol");
|
157
|
+
ol.style.display = "none";
|
158
|
+
|
159
|
+
for ( var i = 0; i < config.assertions.length; i++ ) {
|
160
|
+
var assertion = config.assertions[i];
|
161
|
+
|
162
|
+
var li = document.createElement("li");
|
163
|
+
li.className = assertion.result ? "pass" : "fail";
|
164
|
+
li.innerHTML = config.currentModule+' : '+assertion.message || "(no message)";
|
165
|
+
ol.appendChild( li );
|
166
|
+
|
167
|
+
if ( assertion.result ) {
|
168
|
+
good++;
|
169
|
+
} else {
|
170
|
+
bad++;
|
171
|
+
config.stats.bad++;
|
172
|
+
config.moduleStats.bad++;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
var b = document.createElement("strong");
|
177
|
+
b.innerHTML = name + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + config.assertions.length + ")</b>";
|
178
|
+
|
179
|
+
addEvent(b, "click", function() {
|
180
|
+
var next = b.nextSibling, display = next.style.display;
|
181
|
+
next.style.display = display === "none" ? "block" : "none";
|
182
|
+
});
|
183
|
+
|
184
|
+
addEvent(b, "dblclick", function(e) {
|
185
|
+
var target = (e || window.event).target;
|
186
|
+
if ( target.nodeName.toLowerCase() === "strong" ) {
|
187
|
+
var text = "", node = target.firstChild;
|
188
|
+
|
189
|
+
while ( node.nodeType === 3 ) {
|
190
|
+
text += node.nodeValue;
|
191
|
+
node = node.nextSibling;
|
192
|
+
}
|
193
|
+
|
194
|
+
text = text.replace(/(^\s*|\s*$)/g, "");
|
195
|
+
|
196
|
+
if ( window.location ) {
|
197
|
+
window.location.href = window.location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent(text);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
});
|
201
|
+
|
202
|
+
var li = document.createElement("li");
|
203
|
+
li.className = bad ? "fail" : "pass";
|
204
|
+
li.appendChild( b );
|
205
|
+
li.appendChild( ol );
|
206
|
+
tests.appendChild( li );
|
207
|
+
|
208
|
+
if ( bad ) {
|
209
|
+
var toolbar = id("qunit-testrunner-toolbar");
|
210
|
+
if ( toolbar ) {
|
211
|
+
toolbar.style.display = "block";
|
212
|
+
id("qunit-filter-pass").disabled = null;
|
213
|
+
id("qunit-filter-missing").disabled = null;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
} else {
|
218
|
+
for ( var i = 0; i < config.assertions.length; i++ ) {
|
219
|
+
if ( !config.assertions[i].result ) {
|
220
|
+
bad++;
|
221
|
+
config.stats.bad++;
|
222
|
+
config.moduleStats.bad++;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
QUnit.testDone( testName, bad, config.assertions.length );
|
228
|
+
|
229
|
+
if ( !window.setTimeout && !config.queue.length ) {
|
230
|
+
done();
|
231
|
+
}
|
232
|
+
});
|
233
|
+
|
234
|
+
if ( window.setTimeout && !config.doneTimer ) {
|
235
|
+
config.doneTimer = window.setTimeout(function(){
|
236
|
+
if ( !config.queue.length ) {
|
237
|
+
done();
|
238
|
+
} else {
|
239
|
+
synchronize( done );
|
240
|
+
}
|
241
|
+
}, 13);
|
242
|
+
}
|
243
|
+
},
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
|
247
|
+
*/
|
248
|
+
expect: function expect(asserts) {
|
249
|
+
config.expected = asserts;
|
250
|
+
},
|
251
|
+
|
252
|
+
/**
|
253
|
+
* Asserts true.
|
254
|
+
* @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" );
|
255
|
+
*/
|
256
|
+
ok: function ok(a, msg) {
|
257
|
+
QUnit.log(a, msg);
|
258
|
+
|
259
|
+
config.assertions.push({
|
260
|
+
result: !!a,
|
261
|
+
message: msg
|
262
|
+
});
|
263
|
+
},
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Checks that the first two arguments are equal, with an optional message.
|
267
|
+
* Prints out both actual and expected values.
|
268
|
+
*
|
269
|
+
* Prefered to ok( actual == expected, message )
|
270
|
+
*
|
271
|
+
* @example equals( format("Received {0} bytes.", 2), "Received 2 bytes." );
|
272
|
+
*
|
273
|
+
* @param Object actual
|
274
|
+
* @param Object expected
|
275
|
+
* @param String message (optional)
|
276
|
+
*/
|
277
|
+
equals: function equals(actual, expected, message) {
|
278
|
+
push(expected == actual, actual, expected, message);
|
279
|
+
},
|
280
|
+
|
281
|
+
same: function(a, b, message) {
|
282
|
+
push(QUnit.equiv(a, b), a, b, message);
|
283
|
+
},
|
284
|
+
|
285
|
+
start: function start() {
|
286
|
+
// A slight delay, to avoid any current callbacks
|
287
|
+
if ( window.setTimeout ) {
|
288
|
+
window.setTimeout(function() {
|
289
|
+
if ( config.timeout ) {
|
290
|
+
clearTimeout(config.timeout);
|
291
|
+
}
|
292
|
+
|
293
|
+
config.blocking = false;
|
294
|
+
process();
|
295
|
+
}, 13);
|
296
|
+
} else {
|
297
|
+
config.blocking = false;
|
298
|
+
process();
|
299
|
+
}
|
300
|
+
},
|
301
|
+
|
302
|
+
stop: function stop(timeout) {
|
303
|
+
config.blocking = true;
|
304
|
+
|
305
|
+
if ( timeout && window.setTimeout ) {
|
306
|
+
config.timeout = window.setTimeout(function() {
|
307
|
+
QUnit.ok( false, "Test timed out" );
|
308
|
+
QUnit.start();
|
309
|
+
}, timeout);
|
310
|
+
}
|
311
|
+
},
|
312
|
+
|
313
|
+
/**
|
314
|
+
* Resets the test setup. Useful for tests that modify the DOM.
|
315
|
+
*/
|
316
|
+
reset: function reset() {
|
317
|
+
if ( window.jQuery ) {
|
318
|
+
jQuery("#main").html( config.fixture );
|
319
|
+
jQuery.event.global = {};
|
320
|
+
jQuery.ajaxSettings = extend({}, config.ajaxSettings);
|
321
|
+
}
|
322
|
+
},
|
323
|
+
|
324
|
+
/**
|
325
|
+
* Trigger an event on an element.
|
326
|
+
*
|
327
|
+
* @example triggerEvent( document.body, "click" );
|
328
|
+
*
|
329
|
+
* @param DOMElement elem
|
330
|
+
* @param String type
|
331
|
+
*/
|
332
|
+
triggerEvent: function triggerEvent( elem, type, event ) {
|
333
|
+
if ( document.createEvent ) {
|
334
|
+
event = document.createEvent("MouseEvents");
|
335
|
+
event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView,
|
336
|
+
0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
337
|
+
elem.dispatchEvent( event );
|
338
|
+
|
339
|
+
} else if ( elem.fireEvent ) {
|
340
|
+
elem.fireEvent("on"+type);
|
341
|
+
}
|
342
|
+
},
|
343
|
+
|
344
|
+
// Logging callbacks
|
345
|
+
done: function done(failures, total) {},
|
346
|
+
log: function log(result, message) {},
|
347
|
+
testStart: function testStart(name) {},
|
348
|
+
testDone: function testDone(name, failures, total) {},
|
349
|
+
moduleStart: function moduleStart(name, testEnvironment) {},
|
350
|
+
moduleDone: function moduleDone(name, failures, total) {}
|
351
|
+
};
|
352
|
+
|
353
|
+
// Maintain internal state
|
354
|
+
var config = {
|
355
|
+
// The queue of tests to run
|
356
|
+
queue: [],
|
357
|
+
|
358
|
+
// block until document ready
|
359
|
+
blocking: true
|
360
|
+
};
|
361
|
+
|
362
|
+
// Load paramaters
|
363
|
+
(function() {
|
364
|
+
var location = window.location || { search: "", protocol: "file:" },
|
365
|
+
GETParams = location.search.slice(1).split('&');
|
366
|
+
|
367
|
+
for ( var i = 0; i < GETParams.length; i++ ) {
|
368
|
+
GETParams[i] = decodeURIComponent( GETParams[i] );
|
369
|
+
if ( GETParams[i] === "noglobals" ) {
|
370
|
+
GETParams.splice( i, 1 );
|
371
|
+
i--;
|
372
|
+
config.noglobals = true;
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
376
|
+
// restrict modules/tests by get parameters
|
377
|
+
config.filters = GETParams;
|
378
|
+
|
379
|
+
// Figure out if we're running the tests from a server or not
|
380
|
+
QUnit.isLocal = !!(location.protocol === 'file:');
|
381
|
+
})();
|
382
|
+
|
383
|
+
// Expose the API as global variables, unless an 'exports'
|
384
|
+
// object exists, in that case we assume we're in CommonJS
|
385
|
+
if ( typeof exports === "undefined" || typeof require === "undefined" ) {
|
386
|
+
extend(window, QUnit);
|
387
|
+
window.QUnit = QUnit;
|
388
|
+
} else {
|
389
|
+
extend(exports, QUnit);
|
390
|
+
exports.QUnit = QUnit;
|
391
|
+
}
|
392
|
+
|
393
|
+
if ( typeof document === "undefined" || document.readyState === "complete" ) {
|
394
|
+
config.autorun = true;
|
395
|
+
}
|
396
|
+
|
397
|
+
addEvent(window, "load", function() {
|
398
|
+
// Initialize the config, saving the execution queue
|
399
|
+
var oldconfig = extend({}, config);
|
400
|
+
QUnit.init();
|
401
|
+
extend(config, oldconfig);
|
402
|
+
|
403
|
+
config.blocking = false;
|
404
|
+
|
405
|
+
var userAgent = id("qunit-userAgent");
|
406
|
+
if ( userAgent ) {
|
407
|
+
userAgent.innerHTML = navigator.userAgent;
|
408
|
+
}
|
409
|
+
|
410
|
+
var toolbar = id("qunit-testrunner-toolbar");
|
411
|
+
if ( toolbar ) {
|
412
|
+
toolbar.style.display = "none";
|
413
|
+
|
414
|
+
var filter = document.createElement("input");
|
415
|
+
filter.type = "checkbox";
|
416
|
+
filter.id = "qunit-filter-pass";
|
417
|
+
filter.disabled = true;
|
418
|
+
addEvent( filter, "click", function() {
|
419
|
+
var li = document.getElementsByTagName("li");
|
420
|
+
for ( var i = 0; i < li.length; i++ ) {
|
421
|
+
if ( li[i].className.indexOf("pass") > -1 ) {
|
422
|
+
li[i].style.display = filter.checked ? "none" : "block";
|
423
|
+
}
|
424
|
+
}
|
425
|
+
});
|
426
|
+
toolbar.appendChild( filter );
|
427
|
+
|
428
|
+
var label = document.createElement("label");
|
429
|
+
label.setAttribute("for", "filter-pass");
|
430
|
+
label.innerHTML = "Hide passed tests";
|
431
|
+
toolbar.appendChild( label );
|
432
|
+
|
433
|
+
var missing = document.createElement("input");
|
434
|
+
missing.type = "checkbox";
|
435
|
+
missing.id = "qunit-filter-missing";
|
436
|
+
missing.disabled = true;
|
437
|
+
addEvent( missing, "click", function() {
|
438
|
+
var li = document.getElementsByTagName("li");
|
439
|
+
for ( var i = 0; i < li.length; i++ ) {
|
440
|
+
if ( li[i].className.indexOf("fail") > -1 && li[i].innerHTML.indexOf('missing test - untested code is broken code') > - 1 ) {
|
441
|
+
li[i].parentNode.parentNode.style.display = missing.checked ? "none" : "block";
|
442
|
+
}
|
443
|
+
}
|
444
|
+
});
|
445
|
+
toolbar.appendChild( missing );
|
446
|
+
|
447
|
+
label = document.createElement("label");
|
448
|
+
label.setAttribute("for", "filter-missing");
|
449
|
+
label.innerHTML = "Hide missing tests (untested code is broken code)";
|
450
|
+
toolbar.appendChild( label );
|
451
|
+
}
|
452
|
+
|
453
|
+
var main = id('main');
|
454
|
+
if ( main ) {
|
455
|
+
config.fixture = main.innerHTML;
|
456
|
+
}
|
457
|
+
|
458
|
+
if ( window.jQuery ) {
|
459
|
+
config.ajaxSettings = window.jQuery.ajaxSettings;
|
460
|
+
}
|
461
|
+
|
462
|
+
QUnit.start();
|
463
|
+
});
|
464
|
+
|
465
|
+
function done() {
|
466
|
+
if ( config.doneTimer && window.clearTimeout ) {
|
467
|
+
window.clearTimeout( config.doneTimer );
|
468
|
+
config.doneTimer = null;
|
469
|
+
}
|
470
|
+
|
471
|
+
if ( config.queue.length ) {
|
472
|
+
config.doneTimer = window.setTimeout(function(){
|
473
|
+
if ( !config.queue.length ) {
|
474
|
+
done();
|
475
|
+
} else {
|
476
|
+
synchronize( done );
|
477
|
+
}
|
478
|
+
}, 13);
|
479
|
+
|
480
|
+
return;
|
481
|
+
}
|
482
|
+
|
483
|
+
config.autorun = true;
|
484
|
+
|
485
|
+
// Log the last module results
|
486
|
+
if ( config.currentModule ) {
|
487
|
+
QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all );
|
488
|
+
}
|
489
|
+
|
490
|
+
var banner = id("qunit-banner"),
|
491
|
+
tests = id("qunit-tests"),
|
492
|
+
html = ['Tests completed in ',
|
493
|
+
+new Date - config.started, ' milliseconds.<br/>',
|
494
|
+
'<span class="bad">', config.stats.all - config.stats.bad, '</span> tests of <span class="all">', config.stats.all, '</span> passed, ', config.stats.bad,' failed.'].join('');
|
495
|
+
|
496
|
+
if ( banner ) {
|
497
|
+
banner.className += " " + (config.stats.bad ? "fail" : "pass");
|
498
|
+
}
|
499
|
+
|
500
|
+
if ( tests ) {
|
501
|
+
var result = id("qunit-testresult");
|
502
|
+
|
503
|
+
if ( !result ) {
|
504
|
+
result = document.createElement("p");
|
505
|
+
result.id = "qunit-testresult";
|
506
|
+
result.className = "result";
|
507
|
+
tests.parentNode.insertBefore( result, tests.nextSibling );
|
508
|
+
}
|
509
|
+
|
510
|
+
result.innerHTML = html;
|
511
|
+
}
|
512
|
+
|
513
|
+
QUnit.done( config.stats.bad, config.stats.all );
|
514
|
+
}
|
515
|
+
|
516
|
+
function validTest( name ) {
|
517
|
+
var i = config.filters.length,
|
518
|
+
run = false;
|
519
|
+
|
520
|
+
if ( !i ) {
|
521
|
+
return true;
|
522
|
+
}
|
523
|
+
|
524
|
+
while ( i-- ) {
|
525
|
+
var filter = config.filters[i],
|
526
|
+
not = filter.charAt(0) == '!';
|
527
|
+
|
528
|
+
if ( not ) {
|
529
|
+
filter = filter.slice(1);
|
530
|
+
}
|
531
|
+
|
532
|
+
if ( name.indexOf(filter) !== -1 ) {
|
533
|
+
return !not;
|
534
|
+
}
|
535
|
+
|
536
|
+
if ( not ) {
|
537
|
+
run = true;
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
541
|
+
return run;
|
542
|
+
}
|
543
|
+
|
544
|
+
function push(result, actual, expected, message) {
|
545
|
+
message = message || (result ? "okay" : "failed");
|
546
|
+
QUnit.ok( result, result ? message + ": " + expected : message + ", expected: " + QUnit.jsDump.parse(expected) + " result: " + QUnit.jsDump.parse(actual) );
|
547
|
+
}
|
548
|
+
|
549
|
+
function synchronize( callback ) {
|
550
|
+
config.queue.push( callback );
|
551
|
+
|
552
|
+
if ( config.autorun && !config.blocking ) {
|
553
|
+
process();
|
554
|
+
}
|
555
|
+
}
|
556
|
+
|
557
|
+
function process() {
|
558
|
+
while ( config.queue.length && !config.blocking ) {
|
559
|
+
config.queue.shift()();
|
560
|
+
}
|
561
|
+
}
|
562
|
+
|
563
|
+
function saveGlobal() {
|
564
|
+
config.pollution = [];
|
565
|
+
|
566
|
+
if ( config.noglobals ) {
|
567
|
+
for ( var key in window ) {
|
568
|
+
config.pollution.push( key );
|
569
|
+
}
|
570
|
+
}
|
571
|
+
}
|
572
|
+
|
573
|
+
function checkPollution( name ) {
|
574
|
+
var old = config.pollution;
|
575
|
+
saveGlobal();
|
576
|
+
|
577
|
+
var newGlobals = diff( old, config.pollution );
|
578
|
+
if ( newGlobals.length > 0 ) {
|
579
|
+
ok( false, "Introduced global variable(s): " + newGlobals.join(", ") );
|
580
|
+
config.expected++;
|
581
|
+
}
|
582
|
+
|
583
|
+
var deletedGlobals = diff( config.pollution, old );
|
584
|
+
if ( deletedGlobals.length > 0 ) {
|
585
|
+
ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") );
|
586
|
+
config.expected++;
|
587
|
+
}
|
588
|
+
}
|
589
|
+
|
590
|
+
// returns a new Array with the elements that are in a but not in b
|
591
|
+
function diff( a, b ) {
|
592
|
+
var result = a.slice();
|
593
|
+
for ( var i = 0; i < result.length; i++ ) {
|
594
|
+
for ( var j = 0; j < b.length; j++ ) {
|
595
|
+
if ( result[i] === b[j] ) {
|
596
|
+
result.splice(i, 1);
|
597
|
+
i--;
|
598
|
+
break;
|
599
|
+
}
|
600
|
+
}
|
601
|
+
}
|
602
|
+
return result;
|
603
|
+
}
|
604
|
+
|
605
|
+
function fail(message, exception, callback) {
|
606
|
+
if ( typeof console !== "undefined" && console.error && console.warn ) {
|
607
|
+
console.error(message);
|
608
|
+
console.error(exception);
|
609
|
+
console.warn(callback.toString());
|
610
|
+
|
611
|
+
} else if ( window.opera && opera.postError ) {
|
612
|
+
opera.postError(message, exception, callback.toString);
|
613
|
+
}
|
614
|
+
}
|
615
|
+
|
616
|
+
function extend(a, b) {
|
617
|
+
for ( var prop in b ) {
|
618
|
+
a[prop] = b[prop];
|
619
|
+
}
|
620
|
+
|
621
|
+
return a;
|
622
|
+
}
|
623
|
+
|
624
|
+
function addEvent(elem, type, fn) {
|
625
|
+
if ( elem.addEventListener ) {
|
626
|
+
elem.addEventListener( type, fn, false );
|
627
|
+
} else if ( elem.attachEvent ) {
|
628
|
+
elem.attachEvent( "on" + type, fn );
|
629
|
+
} else {
|
630
|
+
fn();
|
631
|
+
}
|
632
|
+
}
|
633
|
+
|
634
|
+
function id(name) {
|
635
|
+
return !!(typeof document !== "undefined" && document && document.getElementById) &&
|
636
|
+
document.getElementById( name );
|
637
|
+
}
|
638
|
+
|
639
|
+
// Test for equality any JavaScript type.
|
640
|
+
// Discussions and reference: http://philrathe.com/articles/equiv
|
641
|
+
// Test suites: http://philrathe.com/tests/equiv
|
642
|
+
// Author: Philippe Rathé <prathe@gmail.com>
|
643
|
+
QUnit.equiv = function () {
|
644
|
+
|
645
|
+
var innerEquiv; // the real equiv function
|
646
|
+
var callers = []; // stack to decide between skip/abort functions
|
647
|
+
|
648
|
+
|
649
|
+
// Determine what is o.
|
650
|
+
function hoozit(o) {
|
651
|
+
if (o.constructor === String) {
|
652
|
+
return "string";
|
653
|
+
|
654
|
+
} else if (o.constructor === Boolean) {
|
655
|
+
return "boolean";
|
656
|
+
|
657
|
+
} else if (o.constructor === Number) {
|
658
|
+
|
659
|
+
if (isNaN(o)) {
|
660
|
+
return "nan";
|
661
|
+
} else {
|
662
|
+
return "number";
|
663
|
+
}
|
664
|
+
|
665
|
+
} else if (typeof o === "undefined") {
|
666
|
+
return "undefined";
|
667
|
+
|
668
|
+
// consider: typeof null === object
|
669
|
+
} else if (o === null) {
|
670
|
+
return "null";
|
671
|
+
|
672
|
+
// consider: typeof [] === object
|
673
|
+
} else if (o instanceof Array) {
|
674
|
+
return "array";
|
675
|
+
|
676
|
+
// consider: typeof new Date() === object
|
677
|
+
} else if (o instanceof Date) {
|
678
|
+
return "date";
|
679
|
+
|
680
|
+
// consider: /./ instanceof Object;
|
681
|
+
// /./ instanceof RegExp;
|
682
|
+
// typeof /./ === "function"; // => false in IE and Opera,
|
683
|
+
// true in FF and Safari
|
684
|
+
} else if (o instanceof RegExp) {
|
685
|
+
return "regexp";
|
686
|
+
|
687
|
+
} else if (typeof o === "object") {
|
688
|
+
return "object";
|
689
|
+
|
690
|
+
} else if (o instanceof Function) {
|
691
|
+
return "function";
|
692
|
+
} else {
|
693
|
+
return undefined;
|
694
|
+
}
|
695
|
+
}
|
696
|
+
|
697
|
+
// Call the o related callback with the given arguments.
|
698
|
+
function bindCallbacks(o, callbacks, args) {
|
699
|
+
var prop = hoozit(o);
|
700
|
+
if (prop) {
|
701
|
+
if (hoozit(callbacks[prop]) === "function") {
|
702
|
+
return callbacks[prop].apply(callbacks, args);
|
703
|
+
} else {
|
704
|
+
return callbacks[prop]; // or undefined
|
705
|
+
}
|
706
|
+
}
|
707
|
+
}
|
708
|
+
|
709
|
+
var callbacks = function () {
|
710
|
+
|
711
|
+
// for string, boolean, number and null
|
712
|
+
function useStrictEquality(b, a) {
|
713
|
+
if (b instanceof a.constructor || a instanceof b.constructor) {
|
714
|
+
// to catch short annotaion VS 'new' annotation of a declaration
|
715
|
+
// e.g. var i = 1;
|
716
|
+
// var j = new Number(1);
|
717
|
+
return a == b;
|
718
|
+
} else {
|
719
|
+
return a === b;
|
720
|
+
}
|
721
|
+
}
|
722
|
+
|
723
|
+
return {
|
724
|
+
"string": useStrictEquality,
|
725
|
+
"boolean": useStrictEquality,
|
726
|
+
"number": useStrictEquality,
|
727
|
+
"null": useStrictEquality,
|
728
|
+
"undefined": useStrictEquality,
|
729
|
+
|
730
|
+
"nan": function (b) {
|
731
|
+
return isNaN(b);
|
732
|
+
},
|
733
|
+
|
734
|
+
"date": function (b, a) {
|
735
|
+
return hoozit(b) === "date" && a.valueOf() === b.valueOf();
|
736
|
+
},
|
737
|
+
|
738
|
+
"regexp": function (b, a) {
|
739
|
+
return hoozit(b) === "regexp" &&
|
740
|
+
a.source === b.source && // the regex itself
|
741
|
+
a.global === b.global && // and its modifers (gmi) ...
|
742
|
+
a.ignoreCase === b.ignoreCase &&
|
743
|
+
a.multiline === b.multiline;
|
744
|
+
},
|
745
|
+
|
746
|
+
// - skip when the property is a method of an instance (OOP)
|
747
|
+
// - abort otherwise,
|
748
|
+
// initial === would have catch identical references anyway
|
749
|
+
"function": function () {
|
750
|
+
var caller = callers[callers.length - 1];
|
751
|
+
return caller !== Object &&
|
752
|
+
typeof caller !== "undefined";
|
753
|
+
},
|
754
|
+
|
755
|
+
"array": function (b, a) {
|
756
|
+
var i;
|
757
|
+
var len;
|
758
|
+
|
759
|
+
// b could be an object literal here
|
760
|
+
if ( ! (hoozit(b) === "array")) {
|
761
|
+
return false;
|
762
|
+
}
|
763
|
+
|
764
|
+
len = a.length;
|
765
|
+
if (len !== b.length) { // safe and faster
|
766
|
+
return false;
|
767
|
+
}
|
768
|
+
for (i = 0; i < len; i++) {
|
769
|
+
if ( ! innerEquiv(a[i], b[i])) {
|
770
|
+
return false;
|
771
|
+
}
|
772
|
+
}
|
773
|
+
return true;
|
774
|
+
},
|
775
|
+
|
776
|
+
"object": function (b, a) {
|
777
|
+
var i;
|
778
|
+
var eq = true; // unless we can proove it
|
779
|
+
var aProperties = [], bProperties = []; // collection of strings
|
780
|
+
|
781
|
+
// comparing constructors is more strict than using instanceof
|
782
|
+
if ( a.constructor !== b.constructor) {
|
783
|
+
return false;
|
784
|
+
}
|
785
|
+
|
786
|
+
// stack constructor before traversing properties
|
787
|
+
callers.push(a.constructor);
|
788
|
+
|
789
|
+
for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
|
790
|
+
|
791
|
+
aProperties.push(i); // collect a's properties
|
792
|
+
|
793
|
+
if ( ! innerEquiv(a[i], b[i])) {
|
794
|
+
eq = false;
|
795
|
+
}
|
796
|
+
}
|
797
|
+
|
798
|
+
callers.pop(); // unstack, we are done
|
799
|
+
|
800
|
+
for (i in b) {
|
801
|
+
bProperties.push(i); // collect b's properties
|
802
|
+
}
|
803
|
+
|
804
|
+
// Ensures identical properties name
|
805
|
+
return eq && innerEquiv(aProperties.sort(), bProperties.sort());
|
806
|
+
}
|
807
|
+
};
|
808
|
+
}();
|
809
|
+
|
810
|
+
innerEquiv = function () { // can take multiple arguments
|
811
|
+
var args = Array.prototype.slice.apply(arguments);
|
812
|
+
if (args.length < 2) {
|
813
|
+
return true; // end transition
|
814
|
+
}
|
815
|
+
|
816
|
+
return (function (a, b) {
|
817
|
+
if (a === b) {
|
818
|
+
return true; // catch the most you can
|
819
|
+
} else if (a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || hoozit(a) !== hoozit(b)) {
|
820
|
+
return false; // don't lose time with error prone cases
|
821
|
+
} else {
|
822
|
+
return bindCallbacks(a, callbacks, [b, a]);
|
823
|
+
}
|
824
|
+
|
825
|
+
// apply transition with (1..n) arguments
|
826
|
+
})(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1));
|
827
|
+
};
|
828
|
+
|
829
|
+
return innerEquiv;
|
830
|
+
|
831
|
+
}();
|
832
|
+
|
833
|
+
/**
|
834
|
+
* jsDump
|
835
|
+
* Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
|
836
|
+
* Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php)
|
837
|
+
* Date: 5/15/2008
|
838
|
+
* @projectDescription Advanced and extensible data dumping for Javascript.
|
839
|
+
* @version 1.0.0
|
840
|
+
* @author Ariel Flesler
|
841
|
+
* @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html}
|
842
|
+
*/
|
843
|
+
QUnit.jsDump = (function() {
|
844
|
+
function quote( str ) {
|
845
|
+
return '"' + str.toString().replace(/"/g, '\\"') + '"';
|
846
|
+
};
|
847
|
+
function literal( o ) {
|
848
|
+
return o + '';
|
849
|
+
};
|
850
|
+
function join( pre, arr, post ) {
|
851
|
+
var s = jsDump.separator(),
|
852
|
+
base = jsDump.indent(),
|
853
|
+
inner = jsDump.indent(1);
|
854
|
+
if ( arr.join )
|
855
|
+
arr = arr.join( ',' + s + inner );
|
856
|
+
if ( !arr )
|
857
|
+
return pre + post;
|
858
|
+
return [ pre, inner + arr, base + post ].join(s);
|
859
|
+
};
|
860
|
+
function array( arr ) {
|
861
|
+
var i = arr.length, ret = Array(i);
|
862
|
+
this.up();
|
863
|
+
while ( i-- )
|
864
|
+
ret[i] = this.parse( arr[i] );
|
865
|
+
this.down();
|
866
|
+
return join( '[', ret, ']' );
|
867
|
+
};
|
868
|
+
|
869
|
+
var reName = /^function (\w+)/;
|
870
|
+
|
871
|
+
var jsDump = {
|
872
|
+
parse:function( obj, type ) { //type is used mostly internally, you can fix a (custom)type in advance
|
873
|
+
var parser = this.parsers[ type || this.typeOf(obj) ];
|
874
|
+
type = typeof parser;
|
875
|
+
|
876
|
+
return type == 'function' ? parser.call( this, obj ) :
|
877
|
+
type == 'string' ? parser :
|
878
|
+
this.parsers.error;
|
879
|
+
},
|
880
|
+
typeOf:function( obj ) {
|
881
|
+
var type = typeof obj,
|
882
|
+
f = 'function';//we'll use it 3 times, save it
|
883
|
+
return type != 'object' && type != f ? type :
|
884
|
+
!obj ? 'null' :
|
885
|
+
obj.exec ? 'regexp' :// some browsers (FF) consider regexps functions
|
886
|
+
obj.getHours ? 'date' :
|
887
|
+
obj.scrollBy ? 'window' :
|
888
|
+
obj.nodeName == '#document' ? 'document' :
|
889
|
+
obj.nodeName ? 'node' :
|
890
|
+
obj.item ? 'nodelist' : // Safari reports nodelists as functions
|
891
|
+
obj.callee ? 'arguments' :
|
892
|
+
obj.call || obj.constructor != Array && //an array would also fall on this hack
|
893
|
+
(obj+'').indexOf(f) != -1 ? f : //IE reports functions like alert, as objects
|
894
|
+
'length' in obj ? 'array' :
|
895
|
+
type;
|
896
|
+
},
|
897
|
+
separator:function() {
|
898
|
+
return this.multiline ? this.HTML ? '<br />' : '\n' : this.HTML ? ' ' : ' ';
|
899
|
+
},
|
900
|
+
indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing
|
901
|
+
if ( !this.multiline )
|
902
|
+
return '';
|
903
|
+
var chr = this.indentChar;
|
904
|
+
if ( this.HTML )
|
905
|
+
chr = chr.replace(/\t/g,' ').replace(/ /g,' ');
|
906
|
+
return Array( this._depth_ + (extra||0) ).join(chr);
|
907
|
+
},
|
908
|
+
up:function( a ) {
|
909
|
+
this._depth_ += a || 1;
|
910
|
+
},
|
911
|
+
down:function( a ) {
|
912
|
+
this._depth_ -= a || 1;
|
913
|
+
},
|
914
|
+
setParser:function( name, parser ) {
|
915
|
+
this.parsers[name] = parser;
|
916
|
+
},
|
917
|
+
// The next 3 are exposed so you can use them
|
918
|
+
quote:quote,
|
919
|
+
literal:literal,
|
920
|
+
join:join,
|
921
|
+
//
|
922
|
+
_depth_: 1,
|
923
|
+
// This is the list of parsers, to modify them, use jsDump.setParser
|
924
|
+
parsers:{
|
925
|
+
window: '[Window]',
|
926
|
+
document: '[Document]',
|
927
|
+
error:'[ERROR]', //when no parser is found, shouldn't happen
|
928
|
+
unknown: '[Unknown]',
|
929
|
+
'null':'null',
|
930
|
+
undefined:'undefined',
|
931
|
+
'function':function( fn ) {
|
932
|
+
var ret = 'function',
|
933
|
+
name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE
|
934
|
+
if ( name )
|
935
|
+
ret += ' ' + name;
|
936
|
+
ret += '(';
|
937
|
+
|
938
|
+
ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join('');
|
939
|
+
return join( ret, this.parse(fn,'functionCode'), '}' );
|
940
|
+
},
|
941
|
+
array: array,
|
942
|
+
nodelist: array,
|
943
|
+
arguments: array,
|
944
|
+
object:function( map ) {
|
945
|
+
var ret = [ ];
|
946
|
+
this.up();
|
947
|
+
for ( var key in map )
|
948
|
+
ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) );
|
949
|
+
this.down();
|
950
|
+
return join( '{', ret, '}' );
|
951
|
+
},
|
952
|
+
node:function( node ) {
|
953
|
+
var open = this.HTML ? '<' : '<',
|
954
|
+
close = this.HTML ? '>' : '>';
|
955
|
+
|
956
|
+
var tag = node.nodeName.toLowerCase(),
|
957
|
+
ret = open + tag;
|
958
|
+
|
959
|
+
for ( var a in this.DOMAttrs ) {
|
960
|
+
var val = node[this.DOMAttrs[a]];
|
961
|
+
if ( val )
|
962
|
+
ret += ' ' + a + '=' + this.parse( val, 'attribute' );
|
963
|
+
}
|
964
|
+
return ret + close + open + '/' + tag + close;
|
965
|
+
},
|
966
|
+
functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function
|
967
|
+
var l = fn.length;
|
968
|
+
if ( !l ) return '';
|
969
|
+
|
970
|
+
var args = Array(l);
|
971
|
+
while ( l-- )
|
972
|
+
args[l] = String.fromCharCode(97+l);//97 is 'a'
|
973
|
+
return ' ' + args.join(', ') + ' ';
|
974
|
+
},
|
975
|
+
key:quote, //object calls it internally, the key part of an item in a map
|
976
|
+
functionCode:'[code]', //function calls it internally, it's the content of the function
|
977
|
+
attribute:quote, //node calls it internally, it's an html attribute value
|
978
|
+
string:quote,
|
979
|
+
date:quote,
|
980
|
+
regexp:literal, //regex
|
981
|
+
number:literal,
|
982
|
+
'boolean':literal
|
983
|
+
},
|
984
|
+
DOMAttrs:{//attributes to dump from nodes, name=>realName
|
985
|
+
id:'id',
|
986
|
+
name:'name',
|
987
|
+
'class':'className'
|
988
|
+
},
|
989
|
+
HTML:true,//if true, entities are escaped ( <, >, \t, space and \n )
|
990
|
+
indentChar:' ',//indentation unit
|
991
|
+
multiline:true //if true, items in a collection, are separated by a \n, else just a space.
|
992
|
+
};
|
993
|
+
|
994
|
+
return jsDump;
|
995
|
+
})();
|
996
|
+
|
997
|
+
})(this);
|