OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 import 'package:compiler/src/util/uri_extras.dart'; | 7 import 'package:compiler/src/util/uri_extras.dart'; |
8 | 8 |
9 | |
10 void testRelativize() { | 9 void testRelativize() { |
11 void c(String expected, String base, String path, bool isWindows) { | 10 void c(String expected, String base, String path, bool isWindows) { |
12 if (isWindows == null) { | 11 if (isWindows == null) { |
13 c(expected, base, path, true); | 12 c(expected, base, path, true); |
14 c(expected, base, path, false); | 13 c(expected, base, path, false); |
15 return; | 14 return; |
16 } | 15 } |
17 | 16 |
18 test(Uri base, Uri uri) { | 17 test(Uri base, Uri uri) { |
19 String r = relativize(base, uri, isWindows); | 18 String r = relativize(base, uri, isWindows); |
20 Uri resolved = base.resolve(r); | 19 Uri resolved = base.resolve(r); |
21 Expect.equals(uri.scheme.toLowerCase(), resolved.scheme.toLowerCase()); | 20 Expect.equals(uri.scheme.toLowerCase(), resolved.scheme.toLowerCase()); |
22 if (isWindows) { | 21 if (isWindows) { |
23 Expect.equals(uri.path.toLowerCase(), resolved.path.toLowerCase()); | 22 Expect.equals(uri.path.toLowerCase(), resolved.path.toLowerCase()); |
24 } else { | 23 } else { |
25 Expect.equals(uri.path, resolved.path); | 24 Expect.equals(uri.path, resolved.path); |
26 } | 25 } |
27 Expect.stringEquals(expected, r); | 26 Expect.stringEquals(expected, r); |
28 } | 27 } |
29 | 28 |
30 test(Uri.parse('file:$base'), | 29 test(Uri.parse('file:$base'), Uri.parse('file:$path')); |
31 Uri.parse('file:$path')); | |
32 | 30 |
33 test(Uri.parse('FILE:$base'), | 31 test(Uri.parse('FILE:$base'), Uri.parse('FILE:$path')); |
34 Uri.parse('FILE:$path')); | |
35 | 32 |
36 test(Uri.parse('file:$base'), | 33 test(Uri.parse('file:$base'), Uri.parse('FILE:$path')); |
37 Uri.parse('FILE:$path')); | |
38 | 34 |
39 test(Uri.parse('FILE:$base'), | 35 test(Uri.parse('FILE:$base'), Uri.parse('file:$path')); |
40 Uri.parse('file:$path')); | |
41 } | 36 } |
42 c('bar', '/', '/bar', null); | 37 c('bar', '/', '/bar', null); |
43 c('bar', '/foo', '/bar', null); | 38 c('bar', '/foo', '/bar', null); |
44 c('/bar', '/foo/', '/bar', null); | 39 c('/bar', '/foo/', '/bar', null); |
45 | 40 |
46 c('bar', '///c:/', '///c:/bar', true); | 41 c('bar', '///c:/', '///c:/bar', true); |
47 c('bar', '///c:/foo', '///c:/bar', true); | 42 c('bar', '///c:/foo', '///c:/bar', true); |
48 c('/c:/bar', '///c:/foo/', '///c:/bar', true); | 43 c('/c:/bar', '///c:/foo/', '///c:/bar', true); |
49 | 44 |
50 c('BAR', '///c:/', '///c:/BAR', true); | 45 c('BAR', '///c:/', '///c:/BAR', true); |
51 c('BAR', '///c:/foo', '///c:/BAR', true); | 46 c('BAR', '///c:/foo', '///c:/BAR', true); |
52 c('/c:/BAR', '///c:/foo/', '///c:/BAR', true); | 47 c('/c:/BAR', '///c:/foo/', '///c:/BAR', true); |
53 | 48 |
54 c('../sdk/lib/_internal/compiler/implementation/dart2js.dart', | 49 c( |
55 '///C:/Users/person/dart_checkout_for_stuff/dart/ReleaseIA32/dart.exe', | 50 '../sdk/lib/_internal/compiler/implementation/dart2js.dart', |
56 '///c:/Users/person/dart_checkout_for_stuff/dart/sdk/lib/_internal/compiler/
' | 51 '///C:/Users/person/dart_checkout_for_stuff/dart/ReleaseIA32/dart.exe', |
57 'implementation/dart2js.dart', | 52 '///c:/Users/person/dart_checkout_for_stuff/dart/sdk/lib/_internal/compile
r/' |
58 true); | 53 'implementation/dart2js.dart', |
| 54 true); |
59 | 55 |
60 c('/Users/person/file.dart', '/users/person/', '/Users/person/file.dart', | 56 c('/Users/person/file.dart', '/users/person/', '/Users/person/file.dart', |
61 false); | 57 false); |
62 | 58 |
63 c('file.dart', '/Users/person/', '/Users/person/file.dart', null); | 59 c('file.dart', '/Users/person/', '/Users/person/file.dart', null); |
64 | 60 |
65 c('../person/file.dart', '/Users/other/', '/Users/person/file.dart', false); | 61 c('../person/file.dart', '/Users/other/', '/Users/person/file.dart', false); |
66 | 62 |
67 c('/Users/person/file.dart', '/Users/other/', '/Users/person/file.dart', | 63 c('/Users/person/file.dart', '/Users/other/', '/Users/person/file.dart', |
68 true); | 64 true); |
69 | 65 |
70 c('out.js.map', '/Users/person/out.js', '/Users/person/out.js.map', null); | 66 c('out.js.map', '/Users/person/out.js', '/Users/person/out.js.map', null); |
71 | 67 |
72 c('../person/out.js.map', | 68 c('../person/out.js.map', '/Users/other/out.js', '/Users/person/out.js.map', |
73 '/Users/other/out.js', | 69 false); |
74 '/Users/person/out.js.map', false); | |
75 | 70 |
76 c('/Users/person/out.js.map', | 71 c('/Users/person/out.js.map', '/Users/other/out.js', |
77 '/Users/other/out.js', | 72 '/Users/person/out.js.map', true); |
78 '/Users/person/out.js.map', true); | |
79 | 73 |
80 c('out.js', '/Users/person/out.js.map', '/Users/person/out.js', null); | 74 c('out.js', '/Users/person/out.js.map', '/Users/person/out.js', null); |
81 | 75 |
82 c('../person/out.js', | 76 c('../person/out.js', '/Users/other/out.js.map', '/Users/person/out.js', |
83 '/Users/other/out.js.map', | 77 false); |
84 '/Users/person/out.js', false); | |
85 | 78 |
86 c('/Users/person/out.js', | 79 c('/Users/person/out.js', '/Users/other/out.js.map', '/Users/person/out.js', |
87 '/Users/other/out.js.map', | 80 true); |
88 '/Users/person/out.js', true); | |
89 | 81 |
90 c('out.js', '/out.js.map', '/out.js', null); | 82 c('out.js', '/out.js.map', '/out.js', null); |
91 | |
92 } | 83 } |
93 | 84 |
94 void main() { | 85 void main() { |
95 testRelativize(); | 86 testRelativize(); |
96 } | 87 } |
OLD | NEW |