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