jdl 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ $(document).ready(function() {
2
+
3
+ module("Backbone.noConflict");
4
+
5
+ test('noConflict', 2, function() {
6
+ var noconflictBackbone = Backbone.noConflict();
7
+ equal(window.Backbone, undefined, 'Returned window.Backbone');
8
+ window.Backbone = noconflictBackbone;
9
+ equal(window.Backbone, noconflictBackbone, 'Backbone is still pointing to the original Backbone');
10
+ });
11
+
12
+ });
data/test/router.js ADDED
@@ -0,0 +1,689 @@
1
+ $(document).ready(function() {
2
+
3
+ var router = null;
4
+ var location = null;
5
+ var lastRoute = null;
6
+ var lastArgs = [];
7
+
8
+ function onRoute(router, route, args) {
9
+ lastRoute = route;
10
+ lastArgs = args;
11
+ }
12
+
13
+ var Location = function(href) {
14
+ this.replace(href);
15
+ };
16
+
17
+ _.extend(Location.prototype, {
18
+
19
+ replace: function(href) {
20
+ _.extend(this, _.pick($('<a></a>', {href: href})[0],
21
+ 'href',
22
+ 'hash',
23
+ 'host',
24
+ 'search',
25
+ 'fragment',
26
+ 'pathname',
27
+ 'protocol'
28
+ ));
29
+ // In IE, anchor.pathname does not contain a leading slash though
30
+ // window.location.pathname does.
31
+ if (!/^\//.test(this.pathname)) this.pathname = '/' + this.pathname;
32
+ },
33
+
34
+ toString: function() {
35
+ return this.href;
36
+ }
37
+
38
+ });
39
+
40
+ module("Backbone.Router", {
41
+
42
+ setup: function() {
43
+ location = new Location('http://example.com');
44
+ Backbone.history = _.extend(new Backbone.History, {location: location});
45
+ router = new Router({testing: 101});
46
+ Backbone.history.interval = 9;
47
+ Backbone.history.start({pushState: false});
48
+ lastRoute = null;
49
+ lastArgs = [];
50
+ Backbone.history.on('route', onRoute);
51
+ },
52
+
53
+ teardown: function() {
54
+ Backbone.history.stop();
55
+ Backbone.history.off('route', onRoute);
56
+ }
57
+
58
+ });
59
+
60
+ var ExternalObject = {
61
+ value: 'unset',
62
+
63
+ routingFunction: function(value) {
64
+ this.value = value;
65
+ }
66
+ };
67
+ _.bindAll(ExternalObject);
68
+
69
+ var Router = Backbone.Router.extend({
70
+
71
+ count: 0,
72
+
73
+ routes: {
74
+ "noCallback": "noCallback",
75
+ "counter": "counter",
76
+ "search/:query": "search",
77
+ "search/:query/p:page": "search",
78
+ "contacts": "contacts",
79
+ "contacts/new": "newContact",
80
+ "contacts/:id": "loadContact",
81
+ "route-event/:arg": "routeEvent",
82
+ "optional(/:item)": "optionalItem",
83
+ "named/optional/(y:z)": "namedOptional",
84
+ "splat/*args/end": "splat",
85
+ ":repo/compare/*from...*to": "github",
86
+ "decode/:named/*splat": "decode",
87
+ "*first/complex-*part/*rest": "complex",
88
+ ":entity?*args": "query",
89
+ "function/:value": ExternalObject.routingFunction,
90
+ "*anything": "anything"
91
+ },
92
+
93
+ initialize : function(options) {
94
+ this.testing = options.testing;
95
+ this.route('implicit', 'implicit');
96
+ },
97
+
98
+ counter: function() {
99
+ this.count++;
100
+ },
101
+
102
+ implicit: function() {
103
+ this.count++;
104
+ },
105
+
106
+ search : function(query, page) {
107
+ this.query = query;
108
+ this.page = page;
109
+ },
110
+
111
+ contacts: function(){
112
+ this.contact = 'index';
113
+ },
114
+
115
+ newContact: function(){
116
+ this.contact = 'new';
117
+ },
118
+
119
+ loadContact: function(){
120
+ this.contact = 'load';
121
+ },
122
+
123
+ optionalItem: function(arg){
124
+ this.arg = arg != void 0 ? arg : null;
125
+ },
126
+
127
+ splat: function(args) {
128
+ this.args = args;
129
+ },
130
+
131
+ github: function(repo, from, to) {
132
+ this.repo = repo;
133
+ this.from = from;
134
+ this.to = to;
135
+ },
136
+
137
+ complex: function(first, part, rest) {
138
+ this.first = first;
139
+ this.part = part;
140
+ this.rest = rest;
141
+ },
142
+
143
+ query: function(entity, args) {
144
+ this.entity = entity;
145
+ this.queryArgs = args;
146
+ },
147
+
148
+ anything: function(whatever) {
149
+ this.anything = whatever;
150
+ },
151
+
152
+ namedOptional: function(z) {
153
+ this.z = z;
154
+ },
155
+
156
+ decode: function(named, path) {
157
+ this.named = named;
158
+ this.path = path;
159
+ },
160
+
161
+ routeEvent: function(arg) {
162
+ }
163
+
164
+ });
165
+
166
+ test("initialize", 1, function() {
167
+ equal(router.testing, 101);
168
+ });
169
+
170
+ test("routes (simple)", 4, function() {
171
+ location.replace('http://example.com#search/news');
172
+ Backbone.history.checkUrl();
173
+ equal(router.query, 'news');
174
+ equal(router.page, void 0);
175
+ equal(lastRoute, 'search');
176
+ equal(lastArgs[0], 'news');
177
+ });
178
+
179
+ test("routes (simple, but unicode)", 4, function() {
180
+ location.replace('http://example.com#search/тест');
181
+ Backbone.history.checkUrl();
182
+ equal(router.query, "тест");
183
+ equal(router.page, void 0);
184
+ equal(lastRoute, 'search');
185
+ equal(lastArgs[0], "тест");
186
+ });
187
+
188
+ test("routes (two part)", 2, function() {
189
+ location.replace('http://example.com#search/nyc/p10');
190
+ Backbone.history.checkUrl();
191
+ equal(router.query, 'nyc');
192
+ equal(router.page, '10');
193
+ });
194
+
195
+ test("routes via navigate", 2, function() {
196
+ Backbone.history.navigate('search/manhattan/p20', {trigger: true});
197
+ equal(router.query, 'manhattan');
198
+ equal(router.page, '20');
199
+ });
200
+
201
+ test("routes via navigate for backwards-compatibility", 2, function() {
202
+ Backbone.history.navigate('search/manhattan/p20', true);
203
+ equal(router.query, 'manhattan');
204
+ equal(router.page, '20');
205
+ });
206
+
207
+ test("reports matched route via nagivate", 1, function() {
208
+ ok(Backbone.history.navigate('search/manhattan/p20', true));
209
+ });
210
+
211
+ test("route precedence via navigate", 6, function(){
212
+ // check both 0.9.x and backwards-compatibility options
213
+ _.each([ { trigger: true }, true ], function( options ){
214
+ Backbone.history.navigate('contacts', options);
215
+ equal(router.contact, 'index');
216
+ Backbone.history.navigate('contacts/new', options);
217
+ equal(router.contact, 'new');
218
+ Backbone.history.navigate('contacts/foo', options);
219
+ equal(router.contact, 'load');
220
+ });
221
+ });
222
+
223
+ test("loadUrl is not called for identical routes.", 0, function() {
224
+ Backbone.history.loadUrl = function(){ ok(false); };
225
+ location.replace('http://example.com#route');
226
+ Backbone.history.navigate('route');
227
+ Backbone.history.navigate('/route');
228
+ Backbone.history.navigate('/route');
229
+ });
230
+
231
+ test("use implicit callback if none provided", 1, function() {
232
+ router.count = 0;
233
+ router.navigate('implicit', {trigger: true});
234
+ equal(router.count, 1);
235
+ });
236
+
237
+ test("routes via navigate with {replace: true}", 1, function() {
238
+ location.replace('http://example.com#start_here');
239
+ Backbone.history.checkUrl();
240
+ location.replace = function(href) {
241
+ strictEqual(href, new Location('http://example.com#end_here').href);
242
+ };
243
+ Backbone.history.navigate('end_here', {replace: true});
244
+ });
245
+
246
+ test("routes (splats)", 1, function() {
247
+ location.replace('http://example.com#splat/long-list/of/splatted_99args/end');
248
+ Backbone.history.checkUrl();
249
+ equal(router.args, 'long-list/of/splatted_99args');
250
+ });
251
+
252
+ test("routes (github)", 3, function() {
253
+ location.replace('http://example.com#backbone/compare/1.0...braddunbar:with/slash');
254
+ Backbone.history.checkUrl();
255
+ equal(router.repo, 'backbone');
256
+ equal(router.from, '1.0');
257
+ equal(router.to, 'braddunbar:with/slash');
258
+ });
259
+
260
+ test("routes (optional)", 2, function() {
261
+ location.replace('http://example.com#optional');
262
+ Backbone.history.checkUrl();
263
+ ok(!router.arg);
264
+ location.replace('http://example.com#optional/thing');
265
+ Backbone.history.checkUrl();
266
+ equal(router.arg, 'thing');
267
+ });
268
+
269
+ test("routes (complex)", 3, function() {
270
+ location.replace('http://example.com#one/two/three/complex-part/four/five/six/seven');
271
+ Backbone.history.checkUrl();
272
+ equal(router.first, 'one/two/three');
273
+ equal(router.part, 'part');
274
+ equal(router.rest, 'four/five/six/seven');
275
+ });
276
+
277
+ test("routes (query)", 5, function() {
278
+ location.replace('http://example.com#mandel?a=b&c=d');
279
+ Backbone.history.checkUrl();
280
+ equal(router.entity, 'mandel');
281
+ equal(router.queryArgs, 'a=b&c=d');
282
+ equal(lastRoute, 'query');
283
+ equal(lastArgs[0], 'mandel');
284
+ equal(lastArgs[1], 'a=b&c=d');
285
+ });
286
+
287
+ test("routes (anything)", 1, function() {
288
+ location.replace('http://example.com#doesnt-match-a-route');
289
+ Backbone.history.checkUrl();
290
+ equal(router.anything, 'doesnt-match-a-route');
291
+ });
292
+
293
+ test("routes (function)", 3, function() {
294
+ router.on('route', function(name) {
295
+ ok(name === '');
296
+ });
297
+ equal(ExternalObject.value, 'unset');
298
+ location.replace('http://example.com#function/set');
299
+ Backbone.history.checkUrl();
300
+ equal(ExternalObject.value, 'set');
301
+ });
302
+
303
+ test("Decode named parameters, not splats.", 2, function() {
304
+ location.replace('http://example.com#decode/a%2Fb/c%2Fd/e');
305
+ Backbone.history.checkUrl();
306
+ strictEqual(router.named, 'a/b');
307
+ strictEqual(router.path, 'c/d/e');
308
+ });
309
+
310
+ test("fires event when router doesn't have callback on it", 1, function() {
311
+ router.on("route:noCallback", function(){ ok(true); });
312
+ location.replace('http://example.com#noCallback');
313
+ Backbone.history.checkUrl();
314
+ });
315
+
316
+ test("#933, #908 - leading slash", 2, function() {
317
+ location.replace('http://example.com/root/foo');
318
+
319
+ Backbone.history.stop();
320
+ Backbone.history = _.extend(new Backbone.History, {location: location});
321
+ Backbone.history.start({root: '/root', hashChange: false, silent: true});
322
+ strictEqual(Backbone.history.getFragment(), 'foo');
323
+
324
+ Backbone.history.stop();
325
+ Backbone.history = _.extend(new Backbone.History, {location: location});
326
+ Backbone.history.start({root: '/root/', hashChange: false, silent: true});
327
+ strictEqual(Backbone.history.getFragment(), 'foo');
328
+ });
329
+
330
+ test("#1003 - History is started before navigate is called", 1, function() {
331
+ Backbone.history.stop();
332
+ Backbone.history.navigate = function(){ ok(Backbone.History.started); };
333
+ Backbone.history.start();
334
+ // If this is not an old IE navigate will not be called.
335
+ if (!Backbone.history.iframe) ok(true);
336
+ });
337
+
338
+ test("#967 - Route callback gets passed encoded values.", 3, function() {
339
+ var route = 'has%2Fslash/complex-has%23hash/has%20space';
340
+ Backbone.history.navigate(route, {trigger: true});
341
+ strictEqual(router.first, 'has/slash');
342
+ strictEqual(router.part, 'has#hash');
343
+ strictEqual(router.rest, 'has space');
344
+ });
345
+
346
+ test("correctly handles URLs with % (#868)", 3, function() {
347
+ location.replace('http://example.com#search/fat%3A1.5%25');
348
+ Backbone.history.checkUrl();
349
+ location.replace('http://example.com#search/fat');
350
+ Backbone.history.checkUrl();
351
+ equal(router.query, 'fat');
352
+ equal(router.page, void 0);
353
+ equal(lastRoute, 'search');
354
+ });
355
+
356
+ test("#1185 - Use pathname when hashChange is not wanted.", 1, function() {
357
+ Backbone.history.stop();
358
+ location.replace('http://example.com/path/name#hash');
359
+ Backbone.history = _.extend(new Backbone.History, {location: location});
360
+ Backbone.history.start({hashChange: false});
361
+ var fragment = Backbone.history.getFragment();
362
+ strictEqual(fragment, location.pathname.replace(/^\//, ''));
363
+ });
364
+
365
+ test("#1206 - Strip leading slash before location.assign.", 1, function() {
366
+ Backbone.history.stop();
367
+ location.replace('http://example.com/root/');
368
+ Backbone.history = _.extend(new Backbone.History, {location: location});
369
+ Backbone.history.start({hashChange: false, root: '/root/'});
370
+ location.assign = function(pathname) {
371
+ strictEqual(pathname, '/root/fragment');
372
+ };
373
+ Backbone.history.navigate('/fragment');
374
+ });
375
+
376
+ test("#1387 - Root fragment without trailing slash.", 1, function() {
377
+ Backbone.history.stop();
378
+ location.replace('http://example.com/root');
379
+ Backbone.history = _.extend(new Backbone.History, {location: location});
380
+ Backbone.history.start({hashChange: false, root: '/root/', silent: true});
381
+ strictEqual(Backbone.history.getFragment(), '');
382
+ });
383
+
384
+ test("#1366 - History does not prepend root to fragment.", 2, function() {
385
+ Backbone.history.stop();
386
+ location.replace('http://example.com/root/');
387
+ Backbone.history = _.extend(new Backbone.History, {
388
+ location: location,
389
+ history: {
390
+ pushState: function(state, title, url) {
391
+ strictEqual(url, '/root/x');
392
+ }
393
+ }
394
+ });
395
+ Backbone.history.start({
396
+ root: '/root/',
397
+ pushState: true,
398
+ hashChange: false
399
+ });
400
+ Backbone.history.navigate('x');
401
+ strictEqual(Backbone.history.fragment, 'x');
402
+ });
403
+
404
+ test("Normalize root.", 1, function() {
405
+ Backbone.history.stop();
406
+ location.replace('http://example.com/root');
407
+ Backbone.history = _.extend(new Backbone.History, {
408
+ location: location,
409
+ history: {
410
+ pushState: function(state, title, url) {
411
+ strictEqual(url, '/root/fragment');
412
+ }
413
+ }
414
+ });
415
+ Backbone.history.start({
416
+ pushState: true,
417
+ root: '/root',
418
+ hashChange: false
419
+ });
420
+ Backbone.history.navigate('fragment');
421
+ });
422
+
423
+ test("Normalize root.", 1, function() {
424
+ Backbone.history.stop();
425
+ location.replace('http://example.com/root#fragment');
426
+ Backbone.history = _.extend(new Backbone.History, {
427
+ location: location,
428
+ history: {
429
+ pushState: function(state, title, url) {},
430
+ replaceState: function(state, title, url) {
431
+ strictEqual(url, '/root/fragment');
432
+ }
433
+ }
434
+ });
435
+ Backbone.history.start({
436
+ pushState: true,
437
+ root: '/root'
438
+ });
439
+ });
440
+
441
+ test("Normalize root.", 1, function() {
442
+ Backbone.history.stop();
443
+ location.replace('http://example.com/root');
444
+ Backbone.history = _.extend(new Backbone.History, {location: location});
445
+ Backbone.history.loadUrl = function() { ok(true); };
446
+ Backbone.history.start({
447
+ pushState: true,
448
+ root: '/root'
449
+ });
450
+ });
451
+
452
+ test("Normalize root - leading slash.", 1, function() {
453
+ Backbone.history.stop();
454
+ location.replace('http://example.com/root');
455
+ Backbone.history = _.extend(new Backbone.History, {
456
+ location: location,
457
+ history: {
458
+ pushState: function(){},
459
+ replaceState: function(){}
460
+ }
461
+ });
462
+ Backbone.history.start({root: 'root'});
463
+ strictEqual(Backbone.history.root, '/root/');
464
+ });
465
+
466
+ test("Transition from hashChange to pushState.", 1, function() {
467
+ Backbone.history.stop();
468
+ location.replace('http://example.com/root#x/y');
469
+ Backbone.history = _.extend(new Backbone.History, {
470
+ location: location,
471
+ history: {
472
+ pushState: function(){},
473
+ replaceState: function(state, title, url){
474
+ strictEqual(url, '/root/x/y');
475
+ }
476
+ }
477
+ });
478
+ Backbone.history.start({
479
+ root: 'root',
480
+ pushState: true
481
+ });
482
+ });
483
+
484
+ test("#1619: Router: Normalize empty root", 1, function() {
485
+ Backbone.history.stop();
486
+ location.replace('http://example.com/');
487
+ Backbone.history = _.extend(new Backbone.History, {
488
+ location: location,
489
+ history: {
490
+ pushState: function(){},
491
+ replaceState: function(){}
492
+ }
493
+ });
494
+ Backbone.history.start({root: ''});
495
+ strictEqual(Backbone.history.root, '/');
496
+ });
497
+
498
+ test("#1619: Router: nagivate with empty root", 1, function() {
499
+ Backbone.history.stop();
500
+ location.replace('http://example.com/');
501
+ Backbone.history = _.extend(new Backbone.History, {
502
+ location: location,
503
+ history: {
504
+ pushState: function(state, title, url) {
505
+ strictEqual(url, '/fragment');
506
+ }
507
+ }
508
+ });
509
+ Backbone.history.start({
510
+ pushState: true,
511
+ root: '',
512
+ hashChange: false
513
+ });
514
+ Backbone.history.navigate('fragment');
515
+ });
516
+
517
+ test("Transition from pushState to hashChange.", 1, function() {
518
+ Backbone.history.stop();
519
+ location.replace('http://example.com/root/x/y?a=b');
520
+ location.replace = function(url) {
521
+ strictEqual(url, '/root/?a=b#x/y');
522
+ };
523
+ Backbone.history = _.extend(new Backbone.History, {
524
+ location: location,
525
+ history: {
526
+ pushState: null,
527
+ replaceState: null
528
+ }
529
+ });
530
+ Backbone.history.start({
531
+ root: 'root',
532
+ pushState: true
533
+ });
534
+ });
535
+
536
+ test("#1695 - hashChange to pushState with search.", 1, function() {
537
+ Backbone.history.stop();
538
+ location.replace('http://example.com/root?a=b#x/y');
539
+ Backbone.history = _.extend(new Backbone.History, {
540
+ location: location,
541
+ history: {
542
+ pushState: function(){},
543
+ replaceState: function(state, title, url){
544
+ strictEqual(url, '/root/x/y?a=b');
545
+ }
546
+ }
547
+ });
548
+ Backbone.history.start({
549
+ root: 'root',
550
+ pushState: true
551
+ });
552
+ });
553
+
554
+ test("#1746 - Router allows empty route.", 1, function() {
555
+ var Router = Backbone.Router.extend({
556
+ routes: {'': 'empty'},
557
+ empty: function(){},
558
+ route: function(route){
559
+ strictEqual(route, '');
560
+ }
561
+ });
562
+ new Router;
563
+ });
564
+
565
+ test("#1794 - Trailing space in fragments.", 1, function() {
566
+ var history = new Backbone.History;
567
+ strictEqual(history.getFragment('fragment '), 'fragment');
568
+ });
569
+
570
+ test("#1820 - Leading slash and trailing space.", 1, function() {
571
+ var history = new Backbone.History;
572
+ strictEqual(history.getFragment('/fragment '), 'fragment');
573
+ });
574
+
575
+ test("#1980 - Optional parameters.", 2, function() {
576
+ location.replace('http://example.com#named/optional/y');
577
+ Backbone.history.checkUrl();
578
+ strictEqual(router.z, undefined);
579
+ location.replace('http://example.com#named/optional/y123');
580
+ Backbone.history.checkUrl();
581
+ strictEqual(router.z, '123');
582
+ });
583
+
584
+ test("#2062 - Trigger 'route' event on router instance.", 2, function() {
585
+ router.on('route', function(name, args) {
586
+ strictEqual(name, 'routeEvent');
587
+ deepEqual(args, ['x']);
588
+ });
589
+ location.replace('http://example.com#route-event/x');
590
+ Backbone.history.checkUrl();
591
+ });
592
+
593
+ test("#2255 - Extend routes by making routes a function.", 1, function() {
594
+ var RouterBase = Backbone.Router.extend({
595
+ routes: function() {
596
+ return {
597
+ home: "root",
598
+ index: "index.html"
599
+ };
600
+ }
601
+ });
602
+
603
+ var RouterExtended = RouterBase.extend({
604
+ routes: function() {
605
+ var _super = RouterExtended.__super__.routes;
606
+ return _.extend(_super(),
607
+ { show: "show",
608
+ search: "search" });
609
+ }
610
+ });
611
+
612
+ var router = new RouterExtended();
613
+ deepEqual({home: "root", index: "index.html", show: "show", search: "search"}, router.routes);
614
+ });
615
+
616
+ test("#2538 - hashChange to pushState only if both requested.", 0, function() {
617
+ Backbone.history.stop();
618
+ location.replace('http://example.com/root?a=b#x/y');
619
+ Backbone.history = _.extend(new Backbone.History, {
620
+ location: location,
621
+ history: {
622
+ pushState: function(){},
623
+ replaceState: function(){ ok(false); }
624
+ }
625
+ });
626
+ Backbone.history.start({
627
+ root: 'root',
628
+ pushState: true,
629
+ hashChange: false
630
+ });
631
+ });
632
+
633
+ test('No hash fallback.', 0, function() {
634
+ Backbone.history.stop();
635
+ Backbone.history = _.extend(new Backbone.History, {
636
+ location: location,
637
+ history: {
638
+ pushState: function(){},
639
+ replaceState: function(){}
640
+ }
641
+ });
642
+
643
+ var Router = Backbone.Router.extend({
644
+ routes: {
645
+ hash: function() { ok(false); }
646
+ }
647
+ });
648
+ var router = new Router;
649
+
650
+ location.replace('http://example.com/');
651
+ Backbone.history.start({
652
+ pushState: true,
653
+ hashChange: false
654
+ });
655
+ location.replace('http://example.com/nomatch#hash');
656
+ Backbone.history.checkUrl();
657
+ });
658
+
659
+ test('#2656 - No trailing slash on root.', 1, function() {
660
+ Backbone.history.stop();
661
+ Backbone.history = _.extend(new Backbone.History, {
662
+ location: location,
663
+ history: {
664
+ pushState: function(state, title, url){
665
+ strictEqual(url, '/root');
666
+ }
667
+ }
668
+ });
669
+ location.replace('http://example.com/root/path');
670
+ Backbone.history.start({pushState: true, root: 'root'});
671
+ Backbone.history.navigate('');
672
+ });
673
+
674
+ test('#2656 - No trailing slash on root.', 1, function() {
675
+ Backbone.history.stop();
676
+ Backbone.history = _.extend(new Backbone.History, {
677
+ location: location,
678
+ history: {
679
+ pushState: function(state, title, url){
680
+ strictEqual(url, '/');
681
+ }
682
+ }
683
+ });
684
+ location.replace('http://example.com/path');
685
+ Backbone.history.start({pushState: true});
686
+ Backbone.history.navigate('');
687
+ });
688
+
689
+ });