| 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 library pathos_posix_test; | |
| 6 | |
| 7 import 'dart:io' as io; | 5 import 'dart:io' as io; |
| 8 | 6 |
| 9 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 10 import 'package:pathos/path.dart' as path; | 8 import 'package:pathos/path.dart' as path; |
| 11 | 9 |
| 12 main() { | 10 main() { |
| 13 var builder = new path.Builder(style: path.Style.posix, root: '/root/path'); | 11 var builder = new path.Builder(style: path.Style.url, |
| 14 | 12 root: 'http://dartlang.org/root/path'); |
| 15 if (new path.Builder().style == path.Style.posix) { | |
| 16 group('absolute', () { | |
| 17 expect(path.absolute('a/b.txt'), path.join(path.current, 'a/b.txt')); | |
| 18 expect(path.absolute('/a/b.txt'), '/a/b.txt'); | |
| 19 }); | |
| 20 } | |
| 21 | 13 |
| 22 test('separator', () { | 14 test('separator', () { |
| 23 expect(builder.separator, '/'); | 15 expect(builder.separator, '/'); |
| 24 }); | 16 }); |
| 25 | 17 |
| 26 test('extension', () { | 18 test('extension', () { |
| 27 expect(builder.extension(''), ''); | 19 expect(builder.extension(''), ''); |
| 28 expect(builder.extension('foo.dart'), '.dart'); | 20 expect(builder.extension('foo.dart'), '.dart'); |
| 29 expect(builder.extension('foo.dart.js'), '.js'); | 21 expect(builder.extension('foo.dart.js'), '.js'); |
| 30 expect(builder.extension('a.b/c'), ''); | 22 expect(builder.extension('a.b/c'), ''); |
| 31 expect(builder.extension('a.b/c.d'), '.d'); | 23 expect(builder.extension('a.b/c.d'), '.d'); |
| 32 expect(builder.extension('~/.bashrc'), ''); | |
| 33 expect(builder.extension(r'a.b\c'), r'.b\c'); | 24 expect(builder.extension(r'a.b\c'), r'.b\c'); |
| 34 }); | 25 }); |
| 35 | 26 |
| 36 test('rootPrefix', () { | 27 test('rootPrefix', () { |
| 37 expect(builder.rootPrefix(''), ''); | 28 expect(builder.rootPrefix(''), ''); |
| 38 expect(builder.rootPrefix('a'), ''); | 29 expect(builder.rootPrefix('a'), ''); |
| 39 expect(builder.rootPrefix('a/b'), ''); | 30 expect(builder.rootPrefix('a/b'), ''); |
| 31 expect(builder.rootPrefix('http://dartlang.org/a/c'), |
| 32 'http://dartlang.org'); |
| 33 expect(builder.rootPrefix('file:///a/c'), 'file://'); |
| 40 expect(builder.rootPrefix('/a/c'), '/'); | 34 expect(builder.rootPrefix('/a/c'), '/'); |
| 35 expect(builder.rootPrefix('http://dartlang.org/'), 'http://dartlang.org'); |
| 36 expect(builder.rootPrefix('file:///'), 'file://'); |
| 37 expect(builder.rootPrefix('http://dartlang.org'), 'http://dartlang.org'); |
| 38 expect(builder.rootPrefix('file://'), 'file://'); |
| 41 expect(builder.rootPrefix('/'), '/'); | 39 expect(builder.rootPrefix('/'), '/'); |
| 42 }); | 40 }); |
| 43 | 41 |
| 44 test('dirname', () { | 42 test('dirname', () { |
| 45 expect(builder.dirname(''), '.'); | 43 expect(builder.dirname(''), '.'); |
| 46 expect(builder.dirname('a'), '.'); | 44 expect(builder.dirname('a'), '.'); |
| 47 expect(builder.dirname('a/b'), 'a'); | 45 expect(builder.dirname('a/b'), 'a'); |
| 48 expect(builder.dirname('a/b/c'), 'a/b'); | 46 expect(builder.dirname('a/b/c'), 'a/b'); |
| 49 expect(builder.dirname('a/b.c'), 'a'); | 47 expect(builder.dirname('a/b.c'), 'a'); |
| 50 expect(builder.dirname('a/'), '.'); | 48 expect(builder.dirname('a/'), '.'); |
| 51 expect(builder.dirname('a/.'), 'a'); | 49 expect(builder.dirname('a/.'), 'a'); |
| 52 expect(builder.dirname(r'a\b/c'), r'a\b'); | 50 expect(builder.dirname(r'a\b/c'), r'a\b'); |
| 51 expect(builder.dirname('http://dartlang.org/a'), 'http://dartlang.org'); |
| 52 expect(builder.dirname('file:///a'), 'file://'); |
| 53 expect(builder.dirname('/a'), '/'); | 53 expect(builder.dirname('/a'), '/'); |
| 54 expect(builder.dirname('http://dartlang.org///a'), 'http://dartlang.org'); |
| 55 expect(builder.dirname('file://///a'), 'file://'); |
| 54 expect(builder.dirname('///a'), '/'); | 56 expect(builder.dirname('///a'), '/'); |
| 57 expect(builder.dirname('http://dartlang.org/'), 'http://dartlang.org'); |
| 58 expect(builder.dirname('http://dartlang.org'), 'http://dartlang.org'); |
| 59 expect(builder.dirname('file:///'), 'file://'); |
| 60 expect(builder.dirname('file://'), 'file://'); |
| 55 expect(builder.dirname('/'), '/'); | 61 expect(builder.dirname('/'), '/'); |
| 62 expect(builder.dirname('http://dartlang.org///'), 'http://dartlang.org'); |
| 63 expect(builder.dirname('file://///'), 'file://'); |
| 56 expect(builder.dirname('///'), '/'); | 64 expect(builder.dirname('///'), '/'); |
| 57 expect(builder.dirname('a/b/'), 'a'); | 65 expect(builder.dirname('a/b/'), 'a'); |
| 58 expect(builder.dirname(r'a/b\c'), 'a'); | 66 expect(builder.dirname(r'a/b\c'), 'a'); |
| 59 expect(builder.dirname('a//'), '.'); | 67 expect(builder.dirname('a//'), '.'); |
| 60 expect(builder.dirname('a/b//'), 'a'); | 68 expect(builder.dirname('a/b//'), 'a'); |
| 61 expect(builder.dirname('a//b'), 'a'); | 69 expect(builder.dirname('a//b'), 'a'); |
| 62 }); | 70 }); |
| 63 | 71 |
| 64 test('basename', () { | 72 test('basename', () { |
| 65 expect(builder.basename(''), ''); | 73 expect(builder.basename(''), ''); |
| 66 expect(builder.basename('a'), 'a'); | 74 expect(builder.basename('a'), 'a'); |
| 67 expect(builder.basename('a/b'), 'b'); | 75 expect(builder.basename('a/b'), 'b'); |
| 68 expect(builder.basename('a/b/c'), 'c'); | 76 expect(builder.basename('a/b/c'), 'c'); |
| 69 expect(builder.basename('a/b.c'), 'b.c'); | 77 expect(builder.basename('a/b.c'), 'b.c'); |
| 70 expect(builder.basename('a/'), 'a'); | 78 expect(builder.basename('a/'), 'a'); |
| 71 expect(builder.basename('a/.'), '.'); | 79 expect(builder.basename('a/.'), '.'); |
| 72 expect(builder.basename(r'a\b/c'), 'c'); | 80 expect(builder.basename(r'a\b/c'), 'c'); |
| 81 expect(builder.basename('http://dartlang.org/a'), 'a'); |
| 82 expect(builder.basename('file:///a'), 'a'); |
| 73 expect(builder.basename('/a'), 'a'); | 83 expect(builder.basename('/a'), 'a'); |
| 84 expect(builder.basename('http://dartlang.org/'), 'http://dartlang.org'); |
| 85 expect(builder.basename('http://dartlang.org'), 'http://dartlang.org'); |
| 86 expect(builder.basename('file:///'), 'file://'); |
| 87 expect(builder.basename('file://'), 'file://'); |
| 74 expect(builder.basename('/'), '/'); | 88 expect(builder.basename('/'), '/'); |
| 75 expect(builder.basename('a/b/'), 'b'); | 89 expect(builder.basename('a/b/'), 'b'); |
| 76 expect(builder.basename(r'a/b\c'), r'b\c'); | 90 expect(builder.basename(r'a/b\c'), r'b\c'); |
| 77 expect(builder.basename('a//'), 'a'); | 91 expect(builder.basename('a//'), 'a'); |
| 78 expect(builder.basename('a/b//'), 'b'); | 92 expect(builder.basename('a/b//'), 'b'); |
| 79 expect(builder.basename('a//b'), 'b'); | 93 expect(builder.basename('a//b'), 'b'); |
| 80 }); | 94 }); |
| 81 | 95 |
| 82 test('basenameWithoutExtension', () { | 96 test('basenameWithoutExtension', () { |
| 83 expect(builder.basenameWithoutExtension(''), ''); | 97 expect(builder.basenameWithoutExtension(''), ''); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 94 expect(builder.basenameWithoutExtension('a/b//'), 'b'); | 108 expect(builder.basenameWithoutExtension('a/b//'), 'b'); |
| 95 expect(builder.basenameWithoutExtension('a//b'), 'b'); | 109 expect(builder.basenameWithoutExtension('a//b'), 'b'); |
| 96 expect(builder.basenameWithoutExtension('a/b.c/'), 'b'); | 110 expect(builder.basenameWithoutExtension('a/b.c/'), 'b'); |
| 97 expect(builder.basenameWithoutExtension('a/b.c//'), 'b'); | 111 expect(builder.basenameWithoutExtension('a/b.c//'), 'b'); |
| 98 }); | 112 }); |
| 99 | 113 |
| 100 test('isAbsolute', () { | 114 test('isAbsolute', () { |
| 101 expect(builder.isAbsolute(''), false); | 115 expect(builder.isAbsolute(''), false); |
| 102 expect(builder.isAbsolute('a'), false); | 116 expect(builder.isAbsolute('a'), false); |
| 103 expect(builder.isAbsolute('a/b'), false); | 117 expect(builder.isAbsolute('a/b'), false); |
| 118 expect(builder.isAbsolute('http://dartlang.org/a'), true); |
| 119 expect(builder.isAbsolute('file:///a'), true); |
| 104 expect(builder.isAbsolute('/a'), true); | 120 expect(builder.isAbsolute('/a'), true); |
| 121 expect(builder.isAbsolute('http://dartlang.org/a/b'), true); |
| 122 expect(builder.isAbsolute('file:///a/b'), true); |
| 105 expect(builder.isAbsolute('/a/b'), true); | 123 expect(builder.isAbsolute('/a/b'), true); |
| 124 expect(builder.isAbsolute('http://dartlang.org/'), true); |
| 125 expect(builder.isAbsolute('file:///'), true); |
| 126 expect(builder.isAbsolute('http://dartlang.org'), true); |
| 127 expect(builder.isAbsolute('file://'), true); |
| 128 expect(builder.isAbsolute('/'), true); |
| 106 expect(builder.isAbsolute('~'), false); | 129 expect(builder.isAbsolute('~'), false); |
| 107 expect(builder.isAbsolute('.'), false); | 130 expect(builder.isAbsolute('.'), false); |
| 108 expect(builder.isAbsolute('../a'), false); | 131 expect(builder.isAbsolute('../a'), false); |
| 109 expect(builder.isAbsolute('C:/a'), false); | 132 expect(builder.isAbsolute('C:/a'), false); |
| 110 expect(builder.isAbsolute(r'C:\a'), false); | 133 expect(builder.isAbsolute(r'C:\a'), false); |
| 111 expect(builder.isAbsolute(r'\\a'), false); | 134 expect(builder.isAbsolute(r'\\a'), false); |
| 112 }); | 135 }); |
| 113 | 136 |
| 114 test('isRelative', () { | 137 test('isRelative', () { |
| 115 expect(builder.isRelative(''), true); | 138 expect(builder.isRelative(''), true); |
| 116 expect(builder.isRelative('a'), true); | 139 expect(builder.isRelative('a'), true); |
| 117 expect(builder.isRelative('a/b'), true); | 140 expect(builder.isRelative('a/b'), true); |
| 141 expect(builder.isRelative('http://dartlang.org/a'), false); |
| 142 expect(builder.isRelative('file:///a'), false); |
| 118 expect(builder.isRelative('/a'), false); | 143 expect(builder.isRelative('/a'), false); |
| 144 expect(builder.isRelative('http://dartlang.org/a/b'), false); |
| 145 expect(builder.isRelative('file:///a/b'), false); |
| 119 expect(builder.isRelative('/a/b'), false); | 146 expect(builder.isRelative('/a/b'), false); |
| 147 expect(builder.isRelative('http://dartlang.org/'), false); |
| 148 expect(builder.isRelative('file:///'), false); |
| 149 expect(builder.isRelative('http://dartlang.org'), false); |
| 150 expect(builder.isRelative('file://'), false); |
| 151 expect(builder.isRelative('/'), false); |
| 120 expect(builder.isRelative('~'), true); | 152 expect(builder.isRelative('~'), true); |
| 121 expect(builder.isRelative('.'), true); | 153 expect(builder.isRelative('.'), true); |
| 122 expect(builder.isRelative('../a'), true); | 154 expect(builder.isRelative('../a'), true); |
| 123 expect(builder.isRelative('C:/a'), true); | 155 expect(builder.isRelative('C:/a'), true); |
| 124 expect(builder.isRelative(r'C:\a'), true); | 156 expect(builder.isRelative(r'C:\a'), true); |
| 125 expect(builder.isRelative(r'\\a'), true); | 157 expect(builder.isRelative(r'\\a'), true); |
| 126 }); | 158 }); |
| 127 | 159 |
| 160 test('isRootRelative', () { |
| 161 expect(builder.isRootRelative(''), false); |
| 162 expect(builder.isRootRelative('a'), false); |
| 163 expect(builder.isRootRelative('a/b'), false); |
| 164 expect(builder.isRootRelative('http://dartlang.org/a'), false); |
| 165 expect(builder.isRootRelative('file:///a'), false); |
| 166 expect(builder.isRootRelative('/a'), true); |
| 167 expect(builder.isRootRelative('http://dartlang.org/a/b'), false); |
| 168 expect(builder.isRootRelative('file:///a/b'), false); |
| 169 expect(builder.isRootRelative('/a/b'), true); |
| 170 expect(builder.isRootRelative('http://dartlang.org/'), false); |
| 171 expect(builder.isRootRelative('file:///'), false); |
| 172 expect(builder.isRootRelative('http://dartlang.org'), false); |
| 173 expect(builder.isRootRelative('file://'), false); |
| 174 expect(builder.isRootRelative('/'), true); |
| 175 expect(builder.isRootRelative('~'), false); |
| 176 expect(builder.isRootRelative('.'), false); |
| 177 expect(builder.isRootRelative('../a'), false); |
| 178 expect(builder.isRootRelative('C:/a'), false); |
| 179 expect(builder.isRootRelative(r'C:\a'), false); |
| 180 expect(builder.isRootRelative(r'\\a'), false); |
| 181 }); |
| 182 |
| 128 group('join', () { | 183 group('join', () { |
| 129 test('allows up to eight parts', () { | 184 test('allows up to eight parts', () { |
| 130 expect(builder.join('a'), 'a'); | 185 expect(builder.join('a'), 'a'); |
| 131 expect(builder.join('a', 'b'), 'a/b'); | 186 expect(builder.join('a', 'b'), 'a/b'); |
| 132 expect(builder.join('a', 'b', 'c'), 'a/b/c'); | 187 expect(builder.join('a', 'b', 'c'), 'a/b/c'); |
| 133 expect(builder.join('a', 'b', 'c', 'd'), 'a/b/c/d'); | 188 expect(builder.join('a', 'b', 'c', 'd'), 'a/b/c/d'); |
| 134 expect(builder.join('a', 'b', 'c', 'd', 'e'), 'a/b/c/d/e'); | 189 expect(builder.join('a', 'b', 'c', 'd', 'e'), 'a/b/c/d/e'); |
| 135 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f'), 'a/b/c/d/e/f'); | 190 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f'), 'a/b/c/d/e/f'); |
| 136 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), 'a/b/c/d/e/f/g'); | 191 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), 'a/b/c/d/e/f/g'); |
| 137 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), | 192 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), |
| 138 'a/b/c/d/e/f/g/h'); | 193 'a/b/c/d/e/f/g/h'); |
| 139 }); | 194 }); |
| 140 | 195 |
| 141 test('does not add separator if a part ends in one', () { | 196 test('does not add separator if a part ends in one', () { |
| 142 expect(builder.join('a/', 'b', 'c/', 'd'), 'a/b/c/d'); | 197 expect(builder.join('a/', 'b', 'c/', 'd'), 'a/b/c/d'); |
| 143 expect(builder.join('a\\', 'b'), r'a\/b'); | 198 expect(builder.join('a\\', 'b'), r'a\/b'); |
| 144 }); | 199 }); |
| 145 | 200 |
| 146 test('ignores parts before an absolute path', () { | 201 test('ignores parts before an absolute path', () { |
| 202 expect(builder.join('a', 'http://dartlang.org', 'b', 'c'), |
| 203 'http://dartlang.org/b/c'); |
| 204 expect(builder.join('a', 'file://', 'b', 'c'), 'file:///b/c'); |
| 147 expect(builder.join('a', '/', 'b', 'c'), '/b/c'); | 205 expect(builder.join('a', '/', 'b', 'c'), '/b/c'); |
| 206 expect(builder.join('a', '/b', 'http://dartlang.org/c', 'd'), |
| 207 'http://dartlang.org/c/d'); |
| 208 expect(builder.join( |
| 209 'a', 'http://google.com/b', 'http://dartlang.org/c', 'd'), |
| 210 'http://dartlang.org/c/d'); |
| 148 expect(builder.join('a', '/b', '/c', 'd'), '/c/d'); | 211 expect(builder.join('a', '/b', '/c', 'd'), '/c/d'); |
| 149 expect(builder.join('a', r'c:\b', 'c', 'd'), r'a/c:\b/c/d'); | 212 expect(builder.join('a', r'c:\b', 'c', 'd'), r'a/c:\b/c/d'); |
| 150 expect(builder.join('a', r'\\b', 'c', 'd'), r'a/\\b/c/d'); | 213 expect(builder.join('a', r'\\b', 'c', 'd'), r'a/\\b/c/d'); |
| 151 }); | 214 }); |
| 152 | 215 |
| 216 test('preserves roots before a root-relative path', () { |
| 217 expect(builder.join('http://dartlang.org', 'a', '/b', 'c'), |
| 218 'http://dartlang.org/b/c'); |
| 219 expect(builder.join('file://', 'a', '/b', 'c'), 'file:///b/c'); |
| 220 expect(builder.join('file://', 'a', '/b', 'c', '/d'), 'file:///d'); |
| 221 }); |
| 222 |
| 153 test('ignores trailing nulls', () { | 223 test('ignores trailing nulls', () { |
| 154 expect(builder.join('a', null), equals('a')); | 224 expect(builder.join('a', null), equals('a')); |
| 155 expect(builder.join('a', 'b', 'c', null, null), equals('a/b/c')); | 225 expect(builder.join('a', 'b', 'c', null, null), equals('a/b/c')); |
| 156 }); | 226 }); |
| 157 | 227 |
| 158 test('disallows intermediate nulls', () { | 228 test('disallows intermediate nulls', () { |
| 159 expect(() => builder.join('a', null, 'b'), throwsArgumentError); | 229 expect(() => builder.join('a', null, 'b'), throwsArgumentError); |
| 160 expect(() => builder.join(null, 'a'), throwsArgumentError); | 230 expect(() => builder.join(null, 'a'), throwsArgumentError); |
| 161 }); | 231 }); |
| 162 }); | 232 }); |
| 163 | 233 |
| 164 group('joinAll', () { | 234 group('joinAll', () { |
| 165 test('allows more than eight parts', () { | 235 test('allows more than eight parts', () { |
| 166 expect(builder.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']), | 236 expect(builder.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']), |
| 167 'a/b/c/d/e/f/g/h/i'); | 237 'a/b/c/d/e/f/g/h/i'); |
| 168 }); | 238 }); |
| 169 | 239 |
| 170 test('does not add separator if a part ends in one', () { | |
| 171 expect(builder.joinAll(['a/', 'b', 'c/', 'd']), 'a/b/c/d'); | |
| 172 expect(builder.joinAll(['a\\', 'b']), r'a\/b'); | |
| 173 }); | |
| 174 | |
| 175 test('ignores parts before an absolute path', () { | 240 test('ignores parts before an absolute path', () { |
| 241 expect(builder.joinAll(['a', 'http://dartlang.org', 'b', 'c']), |
| 242 'http://dartlang.org/b/c'); |
| 243 expect(builder.joinAll(['a', 'file://', 'b', 'c']), 'file:///b/c'); |
| 176 expect(builder.joinAll(['a', '/', 'b', 'c']), '/b/c'); | 244 expect(builder.joinAll(['a', '/', 'b', 'c']), '/b/c'); |
| 245 expect(builder.joinAll(['a', '/b', 'http://dartlang.org/c', 'd']), |
| 246 'http://dartlang.org/c/d'); |
| 247 expect(builder.joinAll( |
| 248 ['a', 'http://google.com/b', 'http://dartlang.org/c', 'd']), |
| 249 'http://dartlang.org/c/d'); |
| 177 expect(builder.joinAll(['a', '/b', '/c', 'd']), '/c/d'); | 250 expect(builder.joinAll(['a', '/b', '/c', 'd']), '/c/d'); |
| 178 expect(builder.joinAll(['a', r'c:\b', 'c', 'd']), r'a/c:\b/c/d'); | 251 expect(builder.joinAll(['a', r'c:\b', 'c', 'd']), r'a/c:\b/c/d'); |
| 179 expect(builder.joinAll(['a', r'\\b', 'c', 'd']), r'a/\\b/c/d'); | 252 expect(builder.joinAll(['a', r'\\b', 'c', 'd']), r'a/\\b/c/d'); |
| 180 }); | 253 }); |
| 254 |
| 255 test('preserves roots before a root-relative path', () { |
| 256 expect(builder.joinAll(['http://dartlang.org', 'a', '/b', 'c']), |
| 257 'http://dartlang.org/b/c'); |
| 258 expect(builder.joinAll(['file://', 'a', '/b', 'c']), 'file:///b/c'); |
| 259 expect(builder.joinAll(['file://', 'a', '/b', 'c', '/d']), 'file:///d'); |
| 260 }); |
| 181 }); | 261 }); |
| 182 | 262 |
| 183 group('split', () { | 263 group('split', () { |
| 184 test('simple cases', () { | 264 test('simple cases', () { |
| 185 expect(builder.split(''), []); | 265 expect(builder.split(''), []); |
| 186 expect(builder.split('.'), ['.']); | 266 expect(builder.split('.'), ['.']); |
| 187 expect(builder.split('..'), ['..']); | 267 expect(builder.split('..'), ['..']); |
| 188 expect(builder.split('foo'), equals(['foo'])); | 268 expect(builder.split('foo'), equals(['foo'])); |
| 189 expect(builder.split('foo/bar.txt'), equals(['foo', 'bar.txt'])); | 269 expect(builder.split('foo/bar.txt'), equals(['foo', 'bar.txt'])); |
| 190 expect(builder.split('foo/bar/baz'), equals(['foo', 'bar', 'baz'])); | 270 expect(builder.split('foo/bar/baz'), equals(['foo', 'bar', 'baz'])); |
| 191 expect(builder.split('foo/../bar/./baz'), | 271 expect(builder.split('foo/../bar/./baz'), |
| 192 equals(['foo', '..', 'bar', '.', 'baz'])); | 272 equals(['foo', '..', 'bar', '.', 'baz'])); |
| 193 expect(builder.split('foo//bar///baz'), equals(['foo', 'bar', 'baz'])); | 273 expect(builder.split('foo//bar///baz'), equals(['foo', 'bar', 'baz'])); |
| 194 expect(builder.split('foo/\\/baz'), equals(['foo', '\\', 'baz'])); | 274 expect(builder.split('foo/\\/baz'), equals(['foo', '\\', 'baz'])); |
| 195 expect(builder.split('.'), equals(['.'])); | 275 expect(builder.split('.'), equals(['.'])); |
| 196 expect(builder.split(''), equals([])); | 276 expect(builder.split(''), equals([])); |
| 197 expect(builder.split('foo/'), equals(['foo'])); | 277 expect(builder.split('foo/'), equals(['foo'])); |
| 278 expect(builder.split('http://dartlang.org//'), |
| 279 equals(['http://dartlang.org'])); |
| 280 expect(builder.split('file:////'), equals(['file://'])); |
| 198 expect(builder.split('//'), equals(['/'])); | 281 expect(builder.split('//'), equals(['/'])); |
| 199 }); | 282 }); |
| 200 | 283 |
| 201 test('includes the root for absolute paths', () { | 284 test('includes the root for absolute paths', () { |
| 285 expect(builder.split('http://dartlang.org/foo/bar/baz'), |
| 286 equals(['http://dartlang.org', 'foo', 'bar', 'baz'])); |
| 287 expect(builder.split('file:///foo/bar/baz'), |
| 288 equals(['file://', 'foo', 'bar', 'baz'])); |
| 202 expect(builder.split('/foo/bar/baz'), equals(['/', 'foo', 'bar', 'baz'])); | 289 expect(builder.split('/foo/bar/baz'), equals(['/', 'foo', 'bar', 'baz'])); |
| 290 expect(builder.split('http://dartlang.org/'), |
| 291 equals(['http://dartlang.org'])); |
| 292 expect(builder.split('http://dartlang.org'), |
| 293 equals(['http://dartlang.org'])); |
| 294 expect(builder.split('file:///'), equals(['file://'])); |
| 295 expect(builder.split('file://'), equals(['file://'])); |
| 203 expect(builder.split('/'), equals(['/'])); | 296 expect(builder.split('/'), equals(['/'])); |
| 204 }); | 297 }); |
| 205 }); | 298 }); |
| 206 | 299 |
| 207 group('normalize', () { | 300 group('normalize', () { |
| 208 test('simple cases', () { | 301 test('simple cases', () { |
| 209 expect(builder.normalize(''), ''); | 302 expect(builder.normalize(''), ''); |
| 210 expect(builder.normalize('.'), '.'); | 303 expect(builder.normalize('.'), '.'); |
| 211 expect(builder.normalize('..'), '..'); | 304 expect(builder.normalize('..'), '..'); |
| 212 expect(builder.normalize('a'), 'a'); | 305 expect(builder.normalize('a'), 'a'); |
| 306 expect(builder.normalize('http://dartlang.org/'), 'http://dartlang.org'); |
| 307 expect(builder.normalize('http://dartlang.org'), 'http://dartlang.org'); |
| 308 expect(builder.normalize('file://'), 'file://'); |
| 309 expect(builder.normalize('file:///'), 'file://'); |
| 213 expect(builder.normalize('/'), '/'); | 310 expect(builder.normalize('/'), '/'); |
| 214 expect(builder.normalize(r'\'), r'\'); | 311 expect(builder.normalize(r'\'), r'\'); |
| 215 }); | 312 }); |
| 216 | 313 |
| 217 test('collapses redundant separators', () { | 314 test('collapses redundant separators', () { |
| 218 expect(builder.normalize(r'a/b/c'), r'a/b/c'); | 315 expect(builder.normalize(r'a/b/c'), r'a/b/c'); |
| 219 expect(builder.normalize(r'a//b///c////d'), r'a/b/c/d'); | 316 expect(builder.normalize(r'a//b///c////d'), r'a/b/c/d'); |
| 220 }); | 317 }); |
| 221 | 318 |
| 222 test('does not collapse separators for other platform', () { | 319 test('does not collapse separators for other platform', () { |
| 223 expect(builder.normalize(r'a\\b\\\c'), r'a\\b\\\c'); | 320 expect(builder.normalize(r'a\\b\\\c'), r'a\\b\\\c'); |
| 224 }); | 321 }); |
| 225 | 322 |
| 226 test('eliminates "." parts', () { | 323 test('eliminates "." parts', () { |
| 227 expect(builder.normalize('./'), '.'); | 324 expect(builder.normalize('./'), '.'); |
| 325 expect(builder.normalize('http://dartlang.org/.'), 'http://dartlang.org'); |
| 326 expect(builder.normalize('file:///.'), 'file://'); |
| 228 expect(builder.normalize('/.'), '/'); | 327 expect(builder.normalize('/.'), '/'); |
| 328 expect(builder.normalize('http://dartlang.org/./'), |
| 329 'http://dartlang.org'); |
| 330 expect(builder.normalize('file:///./'), 'file://'); |
| 229 expect(builder.normalize('/./'), '/'); | 331 expect(builder.normalize('/./'), '/'); |
| 230 expect(builder.normalize('./.'), '.'); | 332 expect(builder.normalize('./.'), '.'); |
| 231 expect(builder.normalize('a/./b'), 'a/b'); | 333 expect(builder.normalize('a/./b'), 'a/b'); |
| 232 expect(builder.normalize('a/.b/c'), 'a/.b/c'); | 334 expect(builder.normalize('a/.b/c'), 'a/.b/c'); |
| 233 expect(builder.normalize('a/././b/./c'), 'a/b/c'); | 335 expect(builder.normalize('a/././b/./c'), 'a/b/c'); |
| 234 expect(builder.normalize('././a'), 'a'); | 336 expect(builder.normalize('././a'), 'a'); |
| 235 expect(builder.normalize('a/./.'), 'a'); | 337 expect(builder.normalize('a/./.'), 'a'); |
| 236 }); | 338 }); |
| 237 | 339 |
| 238 test('eliminates ".." parts', () { | 340 test('eliminates ".." parts', () { |
| 239 expect(builder.normalize('..'), '..'); | 341 expect(builder.normalize('..'), '..'); |
| 240 expect(builder.normalize('../'), '..'); | 342 expect(builder.normalize('../'), '..'); |
| 241 expect(builder.normalize('../../..'), '../../..'); | 343 expect(builder.normalize('../../..'), '../../..'); |
| 242 expect(builder.normalize('../../../'), '../../..'); | 344 expect(builder.normalize('../../../'), '../../..'); |
| 345 expect(builder.normalize('http://dartlang.org/..'), |
| 346 'http://dartlang.org'); |
| 347 expect(builder.normalize('file:///..'), 'file://'); |
| 243 expect(builder.normalize('/..'), '/'); | 348 expect(builder.normalize('/..'), '/'); |
| 349 expect(builder.normalize('http://dartlang.org/../../..'), |
| 350 'http://dartlang.org'); |
| 351 expect(builder.normalize('file:///../../..'), 'file://'); |
| 244 expect(builder.normalize('/../../..'), '/'); | 352 expect(builder.normalize('/../../..'), '/'); |
| 353 expect(builder.normalize('http://dartlang.org/../../../a'), |
| 354 'http://dartlang.org/a'); |
| 355 expect(builder.normalize('file:///../../../a'), 'file:///a'); |
| 245 expect(builder.normalize('/../../../a'), '/a'); | 356 expect(builder.normalize('/../../../a'), '/a'); |
| 246 expect(builder.normalize('a/..'), '.'); | 357 expect(builder.normalize('a/..'), '.'); |
| 247 expect(builder.normalize('a/b/..'), 'a'); | 358 expect(builder.normalize('a/b/..'), 'a'); |
| 248 expect(builder.normalize('a/../b'), 'b'); | 359 expect(builder.normalize('a/../b'), 'b'); |
| 249 expect(builder.normalize('a/./../b'), 'b'); | 360 expect(builder.normalize('a/./../b'), 'b'); |
| 250 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); | 361 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); |
| 251 expect(builder.normalize('a/b/../../../../c'), '../../c'); | 362 expect(builder.normalize('a/b/../../../../c'), '../../c'); |
| 252 }); | 363 }); |
| 253 | 364 |
| 254 test('does not walk before root on absolute paths', () { | 365 test('does not walk before root on absolute paths', () { |
| 255 expect(builder.normalize('..'), '..'); | 366 expect(builder.normalize('..'), '..'); |
| 256 expect(builder.normalize('../'), '..'); | 367 expect(builder.normalize('../'), '..'); |
| 368 expect(builder.normalize('http://dartlang.org/..'), |
| 369 'http://dartlang.org'); |
| 370 expect(builder.normalize('file:///..'), 'file://'); |
| 257 expect(builder.normalize('/..'), '/'); | 371 expect(builder.normalize('/..'), '/'); |
| 258 expect(builder.normalize('a/..'), '.'); | 372 expect(builder.normalize('a/..'), '.'); |
| 259 expect(builder.normalize('a/b/..'), 'a'); | 373 expect(builder.normalize('a/b/..'), 'a'); |
| 260 expect(builder.normalize('a/../b'), 'b'); | 374 expect(builder.normalize('a/../b'), 'b'); |
| 261 expect(builder.normalize('a/./../b'), 'b'); | 375 expect(builder.normalize('a/./../b'), 'b'); |
| 262 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); | 376 expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d'); |
| 263 expect(builder.normalize('a/b/../../../../c'), '../../c'); | 377 expect(builder.normalize('a/b/../../../../c'), '../../c'); |
| 264 }); | 378 }); |
| 265 | 379 |
| 266 test('removes trailing separators', () { | 380 test('removes trailing separators', () { |
| 267 expect(builder.normalize('./'), '.'); | 381 expect(builder.normalize('./'), '.'); |
| 268 expect(builder.normalize('.//'), '.'); | 382 expect(builder.normalize('.//'), '.'); |
| 269 expect(builder.normalize('a/'), 'a'); | 383 expect(builder.normalize('a/'), 'a'); |
| 270 expect(builder.normalize('a/b/'), 'a/b'); | 384 expect(builder.normalize('a/b/'), 'a/b'); |
| 271 expect(builder.normalize('a/b///'), 'a/b'); | 385 expect(builder.normalize('a/b///'), 'a/b'); |
| 272 }); | 386 }); |
| 273 }); | 387 }); |
| 274 | 388 |
| 275 group('relative', () { | 389 group('relative', () { |
| 276 group('from absolute root', () { | 390 group('from absolute root', () { |
| 277 test('given absolute path in root', () { | 391 test('given absolute path in root', () { |
| 392 expect(builder.relative('http://dartlang.org'), '../..'); |
| 393 expect(builder.relative('http://dartlang.org/'), '../..'); |
| 278 expect(builder.relative('/'), '../..'); | 394 expect(builder.relative('/'), '../..'); |
| 395 expect(builder.relative('http://dartlang.org/root'), '..'); |
| 279 expect(builder.relative('/root'), '..'); | 396 expect(builder.relative('/root'), '..'); |
| 397 expect(builder.relative('http://dartlang.org/root/path'), '.'); |
| 280 expect(builder.relative('/root/path'), '.'); | 398 expect(builder.relative('/root/path'), '.'); |
| 399 expect(builder.relative('http://dartlang.org/root/path/a'), 'a'); |
| 281 expect(builder.relative('/root/path/a'), 'a'); | 400 expect(builder.relative('/root/path/a'), 'a'); |
| 401 expect(builder.relative('http://dartlang.org/root/path/a/b.txt'), |
| 402 'a/b.txt'); |
| 282 expect(builder.relative('/root/path/a/b.txt'), 'a/b.txt'); | 403 expect(builder.relative('/root/path/a/b.txt'), 'a/b.txt'); |
| 404 expect(builder.relative('http://dartlang.org/root/a/b.txt'), |
| 405 '../a/b.txt'); |
| 283 expect(builder.relative('/root/a/b.txt'), '../a/b.txt'); | 406 expect(builder.relative('/root/a/b.txt'), '../a/b.txt'); |
| 284 }); | 407 }); |
| 285 | 408 |
| 286 test('given absolute path outside of root', () { | 409 test('given absolute path outside of root', () { |
| 410 expect(builder.relative('http://dartlang.org/a/b'), '../../a/b'); |
| 287 expect(builder.relative('/a/b'), '../../a/b'); | 411 expect(builder.relative('/a/b'), '../../a/b'); |
| 412 expect(builder.relative('http://dartlang.org/root/path/a'), 'a'); |
| 288 expect(builder.relative('/root/path/a'), 'a'); | 413 expect(builder.relative('/root/path/a'), 'a'); |
| 289 expect(builder.relative('/root/path/a/b.txt'), 'a/b.txt'); | 414 expect(builder.relative('http://dartlang.org/root/path/a/b.txt'), |
| 290 expect(builder.relative('/root/a/b.txt'), '../a/b.txt'); | 415 'a/b.txt'); |
| 416 expect(builder.relative('http://dartlang.org/root/path/a/b.txt'), |
| 417 'a/b.txt'); |
| 418 expect(builder.relative('http://dartlang.org/root/a/b.txt'), |
| 419 '../a/b.txt'); |
| 420 }); |
| 421 |
| 422 test('given absolute path with different hostname/protocol', () { |
| 423 expect(builder.relative(r'http://google.com/a/b'), |
| 424 r'http://google.com/a/b'); |
| 425 expect(builder.relative(r'file:///a/b'), |
| 426 r'file:///a/b'); |
| 291 }); | 427 }); |
| 292 | 428 |
| 293 test('given relative path', () { | 429 test('given relative path', () { |
| 294 // The path is considered relative to the root, so it basically just | 430 // The path is considered relative to the root, so it basically just |
| 295 // normalizes. | 431 // normalizes. |
| 296 expect(builder.relative(''), '.'); | 432 expect(builder.relative(''), '.'); |
| 297 expect(builder.relative('.'), '.'); | 433 expect(builder.relative('.'), '.'); |
| 298 expect(builder.relative('a'), 'a'); | 434 expect(builder.relative('a'), 'a'); |
| 299 expect(builder.relative('a/b.txt'), 'a/b.txt'); | 435 expect(builder.relative('a/b.txt'), 'a/b.txt'); |
| 300 expect(builder.relative('../a/b.txt'), '../a/b.txt'); | 436 expect(builder.relative('../a/b.txt'), '../a/b.txt'); |
| 301 expect(builder.relative('a/./b/../c.txt'), 'a/c.txt'); | 437 expect(builder.relative('a/./b/../c.txt'), 'a/c.txt'); |
| 302 }); | 438 }); |
| 303 }); | 439 }); |
| 304 | 440 |
| 305 group('from relative root', () { | 441 group('from relative root', () { |
| 306 var r = new path.Builder(style: path.Style.posix, root: 'foo/bar'); | 442 var r = new path.Builder(style: path.Style.url, root: 'foo/bar'); |
| 307 | 443 |
| 308 test('given absolute path', () { | 444 test('given absolute path', () { |
| 445 expect(r.relative('http://google.com/'), equals('http://google.com')); |
| 446 expect(r.relative('http://google.com'), equals('http://google.com')); |
| 447 expect(r.relative('file:///'), equals('file://')); |
| 448 expect(r.relative('file://'), equals('file://')); |
| 309 expect(r.relative('/'), equals('/')); | 449 expect(r.relative('/'), equals('/')); |
| 310 expect(r.relative('/a/b'), equals('/a/b')); | 450 expect(r.relative('/a/b'), equals('/a/b')); |
| 311 }); | 451 }); |
| 312 | 452 |
| 313 test('given relative path', () { | 453 test('given relative path', () { |
| 314 // The path is considered relative to the root, so it basically just | 454 // The path is considered relative to the root, so it basically just |
| 315 // normalizes. | 455 // normalizes. |
| 316 expect(r.relative(''), '.'); | 456 expect(r.relative(''), '.'); |
| 317 expect(r.relative('.'), '.'); | 457 expect(r.relative('.'), '.'); |
| 318 expect(r.relative('..'), '..'); | 458 expect(r.relative('..'), '..'); |
| 319 expect(r.relative('a'), 'a'); | 459 expect(r.relative('a'), 'a'); |
| 320 expect(r.relative('a/b.txt'), 'a/b.txt'); | 460 expect(r.relative('a/b.txt'), 'a/b.txt'); |
| 321 expect(r.relative('../a/b.txt'), '../a/b.txt'); | 461 expect(r.relative('../a/b.txt'), '../a/b.txt'); |
| 322 expect(r.relative('a/./b/../c.txt'), 'a/c.txt'); | 462 expect(r.relative('a/./b/../c.txt'), 'a/c.txt'); |
| 323 }); | 463 }); |
| 324 }); | 464 }); |
| 325 | 465 |
| 466 group('from root-relative root', () { |
| 467 var r = new path.Builder(style: path.Style.url, root: '/foo/bar'); |
| 468 |
| 469 test('given absolute path', () { |
| 470 expect(r.relative('http://google.com/'), equals('http://google.com')); |
| 471 expect(r.relative('http://google.com'), equals('http://google.com')); |
| 472 expect(r.relative('file:///'), equals('file://')); |
| 473 expect(r.relative('file://'), equals('file://')); |
| 474 expect(r.relative('/'), equals('../..')); |
| 475 expect(r.relative('/a/b'), equals('../../a/b')); |
| 476 }); |
| 477 |
| 478 test('given relative path', () { |
| 479 // The path is considered relative to the root, so it basically just |
| 480 // normalizes. |
| 481 expect(r.relative(''), '.'); |
| 482 expect(r.relative('.'), '.'); |
| 483 expect(r.relative('..'), '..'); |
| 484 expect(r.relative('a'), 'a'); |
| 485 expect(r.relative('a/b.txt'), 'a/b.txt'); |
| 486 expect(r.relative('../a/b.txt'), '../a/b.txt'); |
| 487 expect(r.relative('a/./b/../c.txt'), 'a/c.txt'); |
| 488 }); |
| 489 }); |
| 490 |
| 326 test('from a root with extension', () { | 491 test('from a root with extension', () { |
| 327 var r = new path.Builder(style: path.Style.posix, root: '/dir.ext'); | 492 var r = new path.Builder(style: path.Style.url, root: '/dir.ext'); |
| 328 expect(r.relative('/dir.ext/file'), 'file'); | 493 expect(r.relative('/dir.ext/file'), 'file'); |
| 329 }); | 494 }); |
| 330 | 495 |
| 331 test('with a root parameter', () { | 496 test('with a root parameter', () { |
| 332 expect(builder.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz')); | 497 expect(builder.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz')); |
| 498 expect( |
| 499 builder.relative('/foo/bar/baz', from: 'http://dartlang.org/foo/bar'), |
| 500 equals('baz')); |
| 501 expect( |
| 502 builder.relative('http://dartlang.org/foo/bar/baz', from: '/foo/bar'), |
| 503 equals('baz')); |
| 504 expect(builder.relative('http://dartlang.org/foo/bar/baz', |
| 505 from: 'file:///foo/bar'), |
| 506 equals('http://dartlang.org/foo/bar/baz')); |
| 507 expect(builder.relative('http://dartlang.org/foo/bar/baz', |
| 508 from: 'http://dartlang.org/foo/bar'), equals('baz')); |
| 509 expect( |
| 510 builder.relative('/foo/bar/baz', from: 'file:///foo/bar'), |
| 511 equals('http://dartlang.org/foo/bar/baz')); |
| 512 expect( |
| 513 builder.relative('file:///foo/bar/baz', from: '/foo/bar'), |
| 514 equals('file:///foo/bar/baz')); |
| 515 |
| 333 expect(builder.relative('..', from: '/foo/bar'), equals('../../root')); | 516 expect(builder.relative('..', from: '/foo/bar'), equals('../../root')); |
| 517 expect(builder.relative('..', from: 'http://dartlang.org/foo/bar'), |
| 518 equals('../../root')); |
| 519 expect(builder.relative('..', from: 'file:///foo/bar'), |
| 520 equals('http://dartlang.org/root')); |
| 521 expect(builder.relative('..', from: '/foo/bar'), equals('../../root')); |
| 522 |
| 523 expect(builder.relative('http://dartlang.org/foo/bar/baz', |
| 524 from: 'foo/bar'), |
| 525 equals('../../../../foo/bar/baz')); |
| 526 expect(builder.relative('file:///foo/bar/baz', from: 'foo/bar'), |
| 527 equals('file:///foo/bar/baz')); |
| 334 expect(builder.relative('/foo/bar/baz', from: 'foo/bar'), | 528 expect(builder.relative('/foo/bar/baz', from: 'foo/bar'), |
| 335 equals('../../../../foo/bar/baz')); | 529 equals('../../../../foo/bar/baz')); |
| 530 |
| 336 expect(builder.relative('..', from: 'foo/bar'), equals('../../..')); | 531 expect(builder.relative('..', from: 'foo/bar'), equals('../../..')); |
| 337 }); | 532 }); |
| 338 | 533 |
| 339 test('with a root parameter and a relative root', () { | 534 test('with a root parameter and a relative root', () { |
| 340 var r = new path.Builder(style: path.Style.posix, root: 'relative/root'); | 535 var r = new path.Builder(style: path.Style.url, root: 'relative/root'); |
| 341 expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz')); | 536 expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz')); |
| 342 expect(() => r.relative('..', from: '/foo/bar'), throwsArgumentError); | 537 expect( |
| 538 r.relative('/foo/bar/baz', from: 'http://dartlang.org/foo/bar'), |
| 539 equals('/foo/bar/baz')); |
| 540 expect( |
| 541 r.relative('http://dartlang.org/foo/bar/baz', from: '/foo/bar'), |
| 542 equals('http://dartlang.org/foo/bar/baz')); |
| 543 expect(r.relative('http://dartlang.org/foo/bar/baz', |
| 544 from: 'file:///foo/bar'), |
| 545 equals('http://dartlang.org/foo/bar/baz')); |
| 546 expect(r.relative('http://dartlang.org/foo/bar/baz', |
| 547 from: 'http://dartlang.org/foo/bar'), equals('baz')); |
| 548 |
| 549 expect(r.relative('http://dartlang.org/foo/bar/baz', from: 'foo/bar'), |
| 550 equals('http://dartlang.org/foo/bar/baz')); |
| 551 expect(r.relative('file:///foo/bar/baz', from: 'foo/bar'), |
| 552 equals('file:///foo/bar/baz')); |
| 343 expect(r.relative('/foo/bar/baz', from: 'foo/bar'), | 553 expect(r.relative('/foo/bar/baz', from: 'foo/bar'), |
| 344 equals('/foo/bar/baz')); | 554 equals('/foo/bar/baz')); |
| 555 |
| 345 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); | 556 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); |
| 346 }); | 557 }); |
| 347 }); | 558 }); |
| 348 | 559 |
| 349 group('resolve', () { | 560 group('resolve', () { |
| 350 test('allows up to seven parts', () { | 561 test('allows up to seven parts', () { |
| 351 expect(builder.resolve('a'), '/root/path/a'); | 562 expect(builder.resolve('a'), 'http://dartlang.org/root/path/a'); |
| 352 expect(builder.resolve('a', 'b'), '/root/path/a/b'); | 563 expect(builder.resolve('a', 'b'), 'http://dartlang.org/root/path/a/b'); |
| 353 expect(builder.resolve('a', 'b', 'c'), '/root/path/a/b/c'); | 564 expect(builder.resolve('a', 'b', 'c'), |
| 354 expect(builder.resolve('a', 'b', 'c', 'd'), '/root/path/a/b/c/d'); | 565 'http://dartlang.org/root/path/a/b/c'); |
| 355 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), '/root/path/a/b/c/d/e'); | 566 expect(builder.resolve('a', 'b', 'c', 'd'), |
| 567 'http://dartlang.org/root/path/a/b/c/d'); |
| 568 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), |
| 569 'http://dartlang.org/root/path/a/b/c/d/e'); |
| 356 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'), | 570 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f'), |
| 357 '/root/path/a/b/c/d/e/f'); | 571 'http://dartlang.org/root/path/a/b/c/d/e/f'); |
| 358 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f', 'g'), | 572 expect(builder.resolve('a', 'b', 'c', 'd', 'e', 'f', 'g'), |
| 359 '/root/path/a/b/c/d/e/f/g'); | 573 'http://dartlang.org/root/path/a/b/c/d/e/f/g'); |
| 360 }); | 574 }); |
| 361 | 575 |
| 362 test('does not add separator if a part ends in one', () { | 576 test('does not add separator if a part ends in one', () { |
| 363 expect(builder.resolve('a/', 'b', 'c/', 'd'), '/root/path/a/b/c/d'); | 577 expect(builder.resolve('a/', 'b', 'c/', 'd'), |
| 364 expect(builder.resolve(r'a\', 'b'), r'/root/path/a\/b'); | 578 'http://dartlang.org/root/path/a/b/c/d'); |
| 579 expect(builder.resolve(r'a\', 'b'), |
| 580 r'http://dartlang.org/root/path/a\/b'); |
| 365 }); | 581 }); |
| 366 | 582 |
| 367 test('ignores parts before an absolute path', () { | 583 test('ignores parts before an absolute path', () { |
| 368 expect(builder.resolve('a', '/b', '/c', 'd'), '/c/d'); | 584 expect(builder.resolve('a', '/b', '/c', 'd'), 'http://dartlang.org/c/d'); |
| 369 expect(builder.resolve('a', r'c:\b', 'c', 'd'), r'/root/path/a/c:\b/c/d'); | 585 expect(builder.resolve('a', '/b', 'file:///c', 'd'), 'file:///c/d'); |
| 370 expect(builder.resolve('a', r'\\b', 'c', 'd'), r'/root/path/a/\\b/c/d'); | 586 expect(builder.resolve('a', r'c:\b', 'c', 'd'), |
| 587 r'http://dartlang.org/root/path/a/c:\b/c/d'); |
| 588 expect(builder.resolve('a', r'\\b', 'c', 'd'), |
| 589 r'http://dartlang.org/root/path/a/\\b/c/d'); |
| 371 }); | 590 }); |
| 372 }); | 591 }); |
| 373 | 592 |
| 374 test('withoutExtension', () { | 593 test('withoutExtension', () { |
| 375 expect(builder.withoutExtension(''), ''); | 594 expect(builder.withoutExtension(''), ''); |
| 376 expect(builder.withoutExtension('a'), 'a'); | 595 expect(builder.withoutExtension('a'), 'a'); |
| 377 expect(builder.withoutExtension('.a'), '.a'); | 596 expect(builder.withoutExtension('.a'), '.a'); |
| 378 expect(builder.withoutExtension('a.b'), 'a'); | 597 expect(builder.withoutExtension('a.b'), 'a'); |
| 379 expect(builder.withoutExtension('a/b.c'), 'a/b'); | 598 expect(builder.withoutExtension('a/b.c'), 'a/b'); |
| 380 expect(builder.withoutExtension('a/b.c.d'), 'a/b.c'); | 599 expect(builder.withoutExtension('a/b.c.d'), 'a/b.c'); |
| 381 expect(builder.withoutExtension('a/'), 'a/'); | 600 expect(builder.withoutExtension('a/'), 'a/'); |
| 382 expect(builder.withoutExtension('a/b/'), 'a/b/'); | 601 expect(builder.withoutExtension('a/b/'), 'a/b/'); |
| 383 expect(builder.withoutExtension('a/.'), 'a/.'); | 602 expect(builder.withoutExtension('a/.'), 'a/.'); |
| 384 expect(builder.withoutExtension('a/.b'), 'a/.b'); | 603 expect(builder.withoutExtension('a/.b'), 'a/.b'); |
| 385 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); | 604 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); |
| 386 expect(builder.withoutExtension(r'a.b\c'), r'a'); | 605 expect(builder.withoutExtension(r'a.b\c'), r'a'); |
| 387 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); | 606 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); |
| 388 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); | 607 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); |
| 389 expect(builder.withoutExtension('a/b.c/'), 'a/b/'); | 608 expect(builder.withoutExtension('a/b.c/'), 'a/b/'); |
| 390 expect(builder.withoutExtension('a/b.c//'), 'a/b//'); | 609 expect(builder.withoutExtension('a/b.c//'), 'a/b//'); |
| 391 }); | 610 }); |
| 392 } | 611 } |
| OLD | NEW |