aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/URI.js/test/test_fragmentQuery.js
blob: a98406bfe00464761e3fccdb902fbc0cc0b6a19c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(function() {
  'use strict';
  /*global URI, test, equal, deepEqual */

  module('URI.fragmentQuery');
  test('storing query-data in fragment', function() {
    var u = URI('http://example.org');
  
    deepEqual(u.fragment(true), {}, 'empty map for missing fragment');

    u = URI('http://example.org/#');
    deepEqual(u.fragment(true), {}, 'empty map for empty fragment');
  
    u = URI('http://example.org/#?hello=world');
    deepEqual(u.fragment(true), {hello: 'world'}, 'reading data object');
  
    u.fragment({bar: 'foo'});
    deepEqual(u.fragment(true), {bar: 'foo'}, 'setting data object');
    equal(u.toString(), 'http://example.org/#?bar=foo', 'setting data object serialized');

    u.addFragment('name', 'value');
    deepEqual(u.fragment(true), {bar: 'foo', name: 'value'}, 'adding value');
    equal(u.toString(), 'http://example.org/#?bar=foo&name=value', 'adding value serialized');
  
    u.removeFragment('bar');
    deepEqual(u.fragment(true), {name: 'value'}, 'removing value bar');
    equal(u.toString(), 'http://example.org/#?name=value', 'removing value bar serialized');
  
    u.removeFragment('name');
    deepEqual(u.fragment(true), {}, 'removing value name');
    equal(u.toString(), 'http://example.org/#?', 'removing value name serialized');
  });
  test('fragmentPrefix', function() {
    var u;
  
    URI.fragmentPrefix = '!';
    u = URI('http://example.org');
    equal(u._parts.fragmentPrefix, '!', 'init using global property');
  
    u.fragment('#?hello=world');
    equal(u.fragment(), '?hello=world', 'unparsed ?');
    deepEqual(u.fragment(true), {}, 'parsing ? prefix');
  
    u.fragment('#!hello=world');
    equal(u.fragment(), '!hello=world', 'unparsed !');
    deepEqual(u.fragment(true), {hello: 'world'}, 'parsing ! prefix');
  
    u.fragmentPrefix('§');
    equal(u.fragment(), '!hello=world', 'unparsed §');
    deepEqual(u.fragment(true), {}, 'parsing § prefix');
  
    u.fragment('#§hello=world');
    equal(u.fragment(), '§hello=world', 'unparsed §');
    deepEqual(u.fragment(true), {hello: 'world'}, 'parsing § prefix');
  
    URI.fragmentPrefix = '?';
  });

})();