alpha-simprini-engine 0.0.1

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