Home | History | Annotate | Download | only in script-tests
      1 description("Test URL segmentation");
      2 
      3 cases = [ 
      4   // [URL, [SCHEME, HOST, PORT, PATH, QUERY, REF]]
      5   ["http://user:pass@foo:21/bar;par?b#c",    ["http:","foo","21","/bar;par","?b","#c"]],
      6   ["http:foo.com",                           ["http:","example.org","0","/foo/foo.com","",""]],
      7   ["\\t   :foo.com   \\n",                   ["http:","example.org","0","/foo/:foo.com","",""]],
      8   [" foo.com  ",                             ["http:","example.org","0","/foo/foo.com","",""]],
      9   ["a:\\t foo.com",                          ["a:","","0"," foo.com","",""]],
     10   ["http://f:21/ b ? d # e ",                ["http:","f","21","/%20b%20","?%20d%20","# e"]],
     11   ["http://f:/c",                            ["http:","f","0","/c","",""]],
     12   ["http://f:0/c",                           ["http:","f","0","/c","",""]],
     13   ["http://f:00000000000000/c",              ["http:","f","0","/c","",""]],
     14   ["http://f:00000000000000000000080/c",     ["http:","f","0","/c","",""]],
     15   ["http://f:b/c",                           [":","","0","","",""]],
     16   ["http://f: /c",                           [":","","0","","",""]],
     17   ["http://f:\\n/c",                         [":","","0","","",""]],
     18   ["http://f:fifty-two/c",                   [":","","0","","",""]],
     19   ["http://f:999999/c",                      [":","","0","","",""]],
     20   ["http://f: 21 / b ? d # e ",              [":","","0","","",""]],
     21   ["",                                       ["http:","example.org","0","/foo/bar","",""]],
     22   ["  \\t",                                  ["http:","example.org","0","/foo/bar","",""]],
     23   [":foo.com/",                              ["http:","example.org","0","/foo/:foo.com/","",""]],
     24   [":foo.com\\\\",                           ["http:","example.org","0","/foo/:foo.com/","",""]],
     25   [":",                                      ["http:","example.org","0","/foo/:","",""]],
     26   [":a",                                     ["http:","example.org","0","/foo/:a","",""]],
     27   [":/",                                     ["http:","example.org","0","/foo/:/","",""]],
     28   [":\\\\",                                  ["http:","example.org","0","/foo/:/","",""]],
     29   [":#",                                     ["http:","example.org","0","/foo/:","",""]],
     30   ["#",                                      ["http:","example.org","0","/foo/bar","",""]],
     31   ["#/",                                     ["http:","example.org","0","/foo/bar","","#/"]],
     32   ["#\\\\",                                  ["http:","example.org","0","/foo/bar","","#\\\\"]],
     33   ["#;?",                                    ["http:","example.org","0","/foo/bar","","#;?"]],
     34   ["?",                                      ["http:","example.org","0","/foo/bar","",""]],
     35   ["/",                                      ["http:","example.org","0","/","",""]],
     36   [":23",                                    ["http:","example.org","0","/foo/:23","",""]],
     37   ["/:23",                                   ["http:","example.org","0","/:23","",""]],
     38   ["//",                                     [":","","0","","",""]],
     39   ["::",                                     ["http:","example.org","0","/foo/::","",""]],
     40   ["::23",                                   ["http:","example.org","0","/foo/::23","",""]],
     41   ["foo://",                                 ["foo:","","0","//","",""]],
     42   ["http://a:b@c:29/d",                      ["http:","c","29","/d","",""]],
     43   ["http::@c:29",                            ["http:","example.org","0","/foo/:@c:29","",""]],
     44   ["http://&a:foo(b]c@d:2/",                 ["http:","d","2","/","",""]],
     45   ["http://::@c@d:2",                        ["http:","d","2","/","",""]],
     46   ["http://foo.com:b@d/",                    ["http:","d","0","/","",""]],
     47   ["http://foo.com/\\\\@",                   ["http:","foo.com","0","//@","",""]],
     48   ["http:\\\\\\\\foo.com\\\\",               ["http:","foo.com","0","/","",""]],
     49   ["http:\\\\\\\\a\\\\b:c\\\\d (a] foo.com\\\\", ["http:","a","0","/b:c/d (a] foo.com/","",""]],
     50   ["foo:/",                                  ["foo:","","0","/","",""]],
     51   ["foo:/bar.com/",                          ["foo:","","0","/bar.com/","",""]],
     52   ["foo://///////",                          ["foo:","","0","/////////","",""]],
     53   ["foo://///////bar.com/",                  ["foo:","","0","/////////bar.com/","",""]],
     54   ["foo:////://///",                         ["foo:","","0","////://///","",""]],
     55   ["c:/foo",                                 ["c:","","0","/foo","",""]],
     56   ["//foo/bar",                              ["http:","foo","0","/bar","",""]],
     57   ["http://foo/path;a??e#f#g",               ["http:","foo","0","/path;a","??e","#f#g"]],
     58   ["http://foo/abcd?efgh?ijkl",              ["http:","foo","0","/abcd","?efgh?ijkl",""]],
     59   ["http://foo/abcd#foo?bar",                ["http:","foo","0","/abcd","","#foo?bar"]],
     60   ["[61:24:74]:98",                          ["http:","example.org","0","/foo/[61:24:74]:98","",""]],
     61   ["http://[61:27]:98",                      [":","","0","","",""]],
     62   ["http:[61:27]/:foo",                      ["http:","example.org","0","/foo/[61:27]/:foo","",""]],
     63   ["http://[1::2]:3:4",                      [":","","0","","",""]],
     64   ["http://2001::1",                         [":","","0","","",""]],
     65   ["http://[2001::1",                        [":","","0","","",""]],
     66   ["http://2001::1]",                        [":","","0","","",""]],
     67   ["http://2001::1]:80",                     [":","","0","","",""]],
     68   ["http://[2001::1]",                       ["http:","[2001::1]","0","/","",""]],
     69   ["http://[2001::1]:80",                    ["http:","[2001::1]","0","/","",""]],
     70   ["http://[[::]]",                          [":","","0","","",""]],
     71 ];
     72 
     73 var originalBaseURL = canonicalize(".");
     74 setBaseURL("http://example.org/foo/bar");
     75 
     76 for (var i = 0; i < cases.length; ++i) {
     77   shouldBe("segments('" + cases[i][0] + "')",
     78            "'" + JSON.stringify(cases[i][1]) + "'");
     79 }
     80 
     81 setBaseURL(originalBaseURL);
     82 
     83 var successfullyParsed = true;
     84