OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 | |
7 testNormalizePath() { | |
8 test(String expected, String path, {String scheme, String host}) { | |
9 var uri = new Uri(scheme: scheme, host: host, path: path); | |
10 Expect.equals(expected, uri.toString()); | |
11 if (scheme == null && host == null) { | |
12 Expect.equals(expected, uri.path); | |
13 } | |
14 } | |
15 | |
16 var unreserved = "-._~0123456789" | |
17 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
18 "abcdefghijklmnopqrstuvwxyz"; | |
19 | |
20 test("A", "%41"); | |
21 test("AB", "%41%42"); | |
22 test("%40AB", "%40%41%42"); | |
23 test("a", "%61"); | |
24 test("ab", "%61%62"); | |
25 test("%60ab", "%60%61%62"); | |
26 test(unreserved, unreserved); | |
27 | |
28 var x = new StringBuffer(); | |
29 for (int i = 32; i < 128; i++) { | |
30 if (unreserved.indexOf(new String.fromCharCode(i)) != -1) { | |
31 x.writeCharCode(i); | |
32 } else { | |
33 x.write("%"); | |
34 x.write(i.toRadixString(16)); | |
35 } | |
36 } | |
37 Expect.equals(x.toString().toUpperCase(), | |
38 new Uri(path: x.toString()).toString().toUpperCase()); | |
39 | |
40 // Normalized paths. | |
41 | |
42 // Full absolute path normalization for absolute paths. | |
43 test("/a/b/c/", "/../a/./b/z/../c/d/.."); | |
44 test("/a/b/c/", "/./a/b/c/"); | |
45 test("/a/b/c/", "/./../a/b/c/"); | |
46 test("/a/b/c/", "/./../a/b/c/."); | |
47 test("/a/b/c/", "/./../a/b/c/z/./.."); | |
48 test("/", "/a/.."); | |
49 // Full absolute path normalization for URIs with scheme. | |
50 test("s:a/b/c/", "../a/./b/z/../c/d/..", scheme: "s"); | |
51 test("s:a/b/c/", "./a/b/c/", scheme: "s"); | |
52 test("s:a/b/c/", "./../a/b/c/", scheme: "s"); | |
53 test("s:a/b/c/", "./../a/b/c/.", scheme: "s"); | |
54 test("s:a/b/c/", "./../a/b/c/z/./..", scheme: "s"); | |
55 test("s:/", "/a/..", scheme: "s"); | |
56 test("s:/", "a/..", scheme: "s"); | |
57 // Full absolute path normalization for URIs with authority. | |
58 test("//h/a/b/c/", "../a/./b/z/../c/d/..", host: "h"); | |
59 test("//h/a/b/c/", "./a/b/c/", host: "h"); | |
60 test("//h/a/b/c/", "./../a/b/c/", host: "h"); | |
61 test("//h/a/b/c/", "./../a/b/c/.", host: "h"); | |
62 test("//h/a/b/c/", "./../a/b/c/z/./..", host: "h"); | |
63 test("//h/", "/a/..", host: "h"); | |
64 test("//h/", "a/..", host: "h"); | |
65 // Partial relative normalization (allowing leading .. or ./ for current dir). | |
66 test("../a/b/c/", "../a/./b/z/../c/d/.."); | |
67 test("a/b/c/", "./a/b/c/"); | |
68 test("../a/b/c/", "./../a/b/c/"); | |
69 test("../a/b/c/", "./../a/b/c/."); | |
70 test("../a/b/c/", "./../a/b/c/z/./.."); | |
71 test("/", "/a/.."); | |
72 test("./", "a/.."); | |
73 } | |
74 | |
75 main() { | |
76 testNormalizePath(); | |
77 } | |
OLD | NEW |