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 void testInvalidArguments() { | |
8 } | |
9 | |
10 void testPath() { | |
11 test(s, uri) { | |
12 Expect.equals(s, uri.toString()); | |
13 Expect.equals(uri, Uri.parse(s)); | |
14 } | |
15 | |
16 test("urn:", new Uri(scheme: "urn")); | |
17 test("urn:xxx", new Uri(scheme: "urn", path: "xxx")); | |
18 test("urn:xxx:yyy", new Uri(scheme: "urn", path: "xxx:yyy")); | |
19 } | |
20 | |
21 void testPathSegments() { | |
22 test(String path, List<String> segments) { | |
23 void check(uri) { | |
24 Expect.equals(path, uri.path); | |
25 Expect.equals(path, uri.toString()); | |
26 Expect.listEquals(segments, uri.pathSegments); | |
27 } | |
28 | |
29 var uri1 = new Uri(pathSegments: segments); | |
30 var uri2 = new Uri(path: path); | |
31 var uri3 = Uri.parse(path); | |
32 check(uri1); | |
33 check(uri2); | |
34 check(uri3); | |
35 Expect.equals(uri1, uri3); | |
36 Expect.equals(uri2, uri3); | |
37 } | |
38 | |
39 test("", []); | |
40 test("%20", [" "]); | |
41 test("%20/%20%20", [" ", " "]); | |
42 test("A", ["A"]); | |
43 test("%C3%B8", ["ø"]); | |
44 test("%C3%B8/%C3%A5", ["ø", "å"]); | |
45 test("%C8%A4/%E5%B9%B3%E4%BB%AE%E5%90%8D", ["Ȥ", "平仮名"]); | |
floitsch
2013/05/24 20:37:27
I'm not sure if we don't prefer escaping these cha
Søren Gjesse
2013/05/27 10:47:21
We already have quite a few tests with literal non
| |
46 test("A/b", ["A", "b"]); | |
47 test("A/%25", ["A", "%"]); | |
48 test("%2F/a%2Fb", ["/", "a/b"]); | |
49 test("name;v=1.1", ["name;v=1.1"]); | |
50 test("name,v=1.1", ["name,v=1.1"]); | |
51 test("name;v=1.1/name,v=1.1", ["name;v=1.1", "name,v=1.1"]); | |
52 | |
53 var unreserved = "-._~0123456789" | |
54 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
55 "abcdefghijklmnopqrstuvwxyz"; | |
56 var subDelimiters = r"!$&'()*+,;="; | |
57 var additionalPathChars = ":@"; | |
58 var pchar = unreserved + subDelimiters + additionalPathChars; | |
59 | |
60 var encoded = new StringBuffer(); | |
61 var unencoded = new StringBuffer(); | |
62 for (int i = 32; i < 128; i++) { | |
63 if (pchar.indexOf(new String.fromCharCode(i)) != -1) { | |
64 encoded.writeCharCode(i); | |
65 } else { | |
66 encoded.write("%"); | |
67 encoded.write(i.toRadixString(16).toUpperCase()); | |
68 } | |
69 unencoded.writeCharCode(i); | |
70 } | |
71 encoded = encoded.toString(); | |
72 unencoded = unencoded.toString(); | |
73 print(encoded); | |
74 print(unencoded); | |
75 test(encoded, [unencoded]); | |
76 test(encoded + "/" + encoded, [unencoded, unencoded]); | |
77 } | |
78 | |
79 main() { | |
80 testInvalidArguments(); | |
81 testPath(); | |
82 testPathSegments(); | |
83 } | |
OLD | NEW |