| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.memory_file_system; | 5 library analyzer.test.file_system.memory_file_system_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core'; |
| 9 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; | 12 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:path/path.dart'; | 14 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 15 import 'package:path/path.dart' hide equals; |
| 16 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 16 import 'package:watcher/watcher.dart'; | 18 import 'package:watcher/watcher.dart'; |
| 17 | 19 |
| 18 import '../reflective_tests.dart'; | |
| 19 import '../utils.dart'; | 20 import '../utils.dart'; |
| 20 | 21 |
| 21 main() { | 22 main() { |
| 22 initializeTestEnvironment(); | 23 initializeTestEnvironment(); |
| 23 runReflectiveTests(FileSystemExceptionTest); | 24 defineReflectiveTests(FileSystemExceptionTest); |
| 24 runReflectiveTests(FileTest); | 25 defineReflectiveTests(FileTest); |
| 25 runReflectiveTests(FolderTest); | 26 defineReflectiveTests(FolderTest); |
| 26 runReflectiveTests(MemoryFileSourceExistingTest); | 27 defineReflectiveTests(MemoryFileSourceExistingTest); |
| 27 runReflectiveTests(MemoryFileSourceNotExistingTest); | 28 defineReflectiveTests(MemoryFileSourceNotExistingTest); |
| 28 runReflectiveTests(MemoryResourceProviderTest); | 29 defineReflectiveTests(MemoryResourceProviderTest); |
| 29 } | 30 } |
| 30 | 31 |
| 31 var _isFile = new isInstanceOf<File>(); | 32 var _isFile = new isInstanceOf<File>(); |
| 32 var _isFileSystemException = new isInstanceOf<FileSystemException>(); | 33 var _isFileSystemException = new isInstanceOf<FileSystemException>(); |
| 33 var _isFolder = new isInstanceOf<Folder>(); | 34 var _isFolder = new isInstanceOf<Folder>(); |
| 34 | 35 |
| 35 @reflectiveTest | 36 @reflectiveTest |
| 36 class FileSystemExceptionTest { | 37 class FileSystemExceptionTest { |
| 37 void test_constructor() { | 38 void test_constructor() { |
| 38 var exception = new FileSystemException('/my/path', 'my message'); | 39 var exception = new FileSystemException('/my/path', 'my message'); |
| 39 expect(exception.path, '/my/path'); | 40 expect(exception.path, '/my/path'); |
| 40 expect(exception.message, 'my message'); | 41 expect(exception.message, 'my message'); |
| 41 expect(exception.toString(), | 42 expect(exception.toString(), |
| 42 'FileSystemException(path=/my/path; message=my message)'); | 43 'FileSystemException(path=/my/path; message=my message)'); |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 | 46 |
| 46 @reflectiveTest | 47 @reflectiveTest |
| 47 class FileTest { | 48 class FileTest { |
| 48 MemoryResourceProvider provider = new MemoryResourceProvider(); | 49 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 49 | 50 |
| 51 void test_delete() { |
| 52 File file = |
| 53 provider.newFile(provider.convertPath('/foo/file.txt'), 'content'); |
| 54 expect(file.exists, isTrue); |
| 55 // delete |
| 56 file.delete(); |
| 57 expect(file.exists, isFalse); |
| 58 } |
| 59 |
| 50 void test_equals_beforeAndAfterCreate() { | 60 void test_equals_beforeAndAfterCreate() { |
| 51 String path = '/file.txt'; | 61 String path = provider.convertPath('/file.txt'); |
| 52 File file1 = provider.getResource(path); | 62 File file1 = provider.getResource(path); |
| 53 provider.newFile(path, 'contents'); | 63 provider.newFile(path, 'contents'); |
| 54 File file2 = provider.getResource(path); | 64 File file2 = provider.getResource(path); |
| 55 expect(file1 == file2, isTrue); | 65 expect(file1 == file2, isTrue); |
| 56 } | 66 } |
| 57 | 67 |
| 58 void test_equals_false() { | 68 void test_equals_false() { |
| 59 File fileA = provider.getResource('/fileA.txt'); | 69 File fileA = provider.getResource(provider.convertPath('/fileA.txt')); |
| 60 File fileB = provider.getResource('/fileB.txt'); | 70 File fileB = provider.getResource(provider.convertPath('/fileB.txt')); |
| 61 expect(fileA == new Object(), isFalse); | 71 expect(fileA == new Object(), isFalse); |
| 62 expect(fileA == fileB, isFalse); | 72 expect(fileA == fileB, isFalse); |
| 63 } | 73 } |
| 64 | 74 |
| 65 void test_equals_true() { | 75 void test_equals_true() { |
| 66 File file = provider.getResource('/file.txt'); | 76 File file = provider.getResource(provider.convertPath('/file.txt')); |
| 67 expect(file == file, isTrue); | 77 expect(file == file, isTrue); |
| 68 } | 78 } |
| 69 | 79 |
| 70 void test_exists_false() { | 80 void test_exists_false() { |
| 71 File file = provider.getResource('/file.txt'); | 81 File file = provider.getResource(provider.convertPath('/file.txt')); |
| 72 expect(file, isNotNull); | 82 expect(file, isNotNull); |
| 73 expect(file.exists, isFalse); | 83 expect(file.exists, isFalse); |
| 74 } | 84 } |
| 75 | 85 |
| 76 void test_exists_true() { | 86 void test_exists_true() { |
| 77 provider.newFile('/foo/file.txt', 'qwerty'); | 87 String path = provider.convertPath('/foo/file.txt'); |
| 78 File file = provider.getResource('/foo/file.txt'); | 88 provider.newFile(path, 'qwerty'); |
| 89 File file = provider.getResource(path); |
| 79 expect(file, isNotNull); | 90 expect(file, isNotNull); |
| 80 expect(file.exists, isTrue); | 91 expect(file.exists, isTrue); |
| 81 } | 92 } |
| 82 | 93 |
| 83 void test_fullName() { | 94 void test_fullName() { |
| 84 File file = provider.getResource('/foo/bar/file.txt'); | 95 String path = provider.convertPath('/foo/bar/file.txt'); |
| 85 expect(file.path, '/foo/bar/file.txt'); | 96 File file = provider.getResource(path); |
| 97 expect(file.path, path); |
| 86 } | 98 } |
| 87 | 99 |
| 88 void test_hashCode() { | 100 void test_hashCode() { |
| 89 String path = '/foo/bar/file.txt'; | 101 String path = provider.convertPath('/foo/bar/file.txt'); |
| 90 File file1 = provider.getResource(path); | 102 File file1 = provider.getResource(path); |
| 91 provider.newFile(path, 'contents'); | 103 provider.newFile(path, 'contents'); |
| 92 File file2 = provider.getResource(path); | 104 File file2 = provider.getResource(path); |
| 93 expect(file1.hashCode, equals(file2.hashCode)); | 105 expect(file1.hashCode, equals(file2.hashCode)); |
| 94 } | 106 } |
| 95 | 107 |
| 96 void test_isOrContains() { | 108 void test_isOrContains() { |
| 97 String path = '/foo/bar/file.txt'; | 109 String path = provider.convertPath('/foo/bar/file.txt'); |
| 98 File file = provider.getResource(path); | 110 File file = provider.getResource(path); |
| 99 expect(file.isOrContains(path), isTrue); | 111 expect(file.isOrContains(path), isTrue); |
| 100 expect(file.isOrContains('/foo/bar'), isFalse); | 112 expect(file.isOrContains(provider.convertPath('/foo/bar')), isFalse); |
| 101 } | 113 } |
| 102 | 114 |
| 103 void test_modificationStamp_doesNotExist() { | 115 void test_modificationStamp_doesNotExist() { |
| 104 String path = '/foo/bar/file.txt'; | 116 String path = provider.convertPath('/foo/bar/file.txt'); |
| 105 File file = provider.newFile(path, 'qwerty'); | 117 File file = provider.newFile(path, 'qwerty'); |
| 106 provider.deleteFile(path); | 118 provider.deleteFile(path); |
| 107 expect(() { | 119 expect(() { |
| 108 file.modificationStamp; | 120 file.modificationStamp; |
| 109 }, throwsA(_isFileSystemException)); | 121 }, throwsA(_isFileSystemException)); |
| 110 } | 122 } |
| 111 | 123 |
| 112 void test_modificationStamp_exists() { | 124 void test_modificationStamp_exists() { |
| 113 String path = '/foo/bar/file.txt'; | 125 String path = provider.convertPath('/foo/bar/file.txt'); |
| 114 File file = provider.newFile(path, 'qwerty'); | 126 File file = provider.newFile(path, 'qwerty'); |
| 115 expect(file.modificationStamp, isNonNegative); | 127 expect(file.modificationStamp, isNonNegative); |
| 116 } | 128 } |
| 117 | 129 |
| 118 void test_parent() { | 130 void test_parent() { |
| 119 provider.newFile('/foo/bar/file.txt', 'content'); | 131 String path = provider.convertPath('/foo/bar/file.txt'); |
| 120 File file = provider.getResource('/foo/bar/file.txt'); | 132 provider.newFile(path, 'content'); |
| 133 File file = provider.getResource(path); |
| 121 Resource parent = file.parent; | 134 Resource parent = file.parent; |
| 122 expect(parent, new isInstanceOf<Folder>()); | 135 expect(parent, new isInstanceOf<Folder>()); |
| 123 expect(parent.path, equals('/foo/bar')); | 136 expect(parent.path, equals(provider.convertPath('/foo/bar'))); |
| 137 } |
| 138 |
| 139 void test_readAsBytesSync_doesNotExist() { |
| 140 File file = provider.getResource(provider.convertPath('/test.bin')); |
| 141 expect(() { |
| 142 file.readAsBytesSync(); |
| 143 }, throwsA(_isFileSystemException)); |
| 144 } |
| 145 |
| 146 void test_readAsBytesSync_exists() { |
| 147 List<int> bytes = <int>[1, 2, 3, 4, 5]; |
| 148 File file = |
| 149 provider.newFileWithBytes(provider.convertPath('/file.bin'), bytes); |
| 150 expect(file.readAsBytesSync(), bytes); |
| 124 } | 151 } |
| 125 | 152 |
| 126 void test_readAsStringSync_doesNotExist() { | 153 void test_readAsStringSync_doesNotExist() { |
| 127 File file = provider.getResource('/test.txt'); | 154 File file = provider.getResource(provider.convertPath('/test.txt')); |
| 128 expect(() { | 155 expect(() { |
| 129 file.readAsStringSync(); | 156 file.readAsStringSync(); |
| 130 }, throwsA(_isFileSystemException)); | 157 }, throwsA(_isFileSystemException)); |
| 131 } | 158 } |
| 132 | 159 |
| 133 void test_readAsStringSync_exists() { | 160 void test_readAsStringSync_exists() { |
| 134 File file = provider.newFile('/file.txt', 'abc'); | 161 File file = provider.newFile(provider.convertPath('/file.txt'), 'abc'); |
| 135 expect(file.readAsStringSync(), 'abc'); | 162 expect(file.readAsStringSync(), 'abc'); |
| 136 } | 163 } |
| 137 | 164 |
| 165 void test_renameSync_newDoesNotExist() { |
| 166 String oldPath = provider.convertPath('/foo/bar/file.txt'); |
| 167 String newPath = provider.convertPath('/foo/bar/new-file.txt'); |
| 168 File file = provider.newFile(oldPath, 'text'); |
| 169 File newFile = file.renameSync(newPath); |
| 170 expect(file.path, oldPath); |
| 171 expect(file.exists, isFalse); |
| 172 expect(newFile.path, newPath); |
| 173 expect(newFile.exists, isTrue); |
| 174 expect(newFile.readAsStringSync(), 'text'); |
| 175 } |
| 176 |
| 177 void test_renameSync_newExists_file() { |
| 178 String oldPath = provider.convertPath('/foo/bar/file.txt'); |
| 179 String newPath = provider.convertPath('/foo/bar/new-file.txt'); |
| 180 File file = provider.newFile(oldPath, 'text'); |
| 181 provider.newFile(newPath, 'new text'); |
| 182 File newFile = file.renameSync(newPath); |
| 183 expect(file.path, oldPath); |
| 184 expect(file.exists, isFalse); |
| 185 expect(newFile.path, newPath); |
| 186 expect(newFile.exists, isTrue); |
| 187 expect(newFile.readAsStringSync(), 'text'); |
| 188 } |
| 189 |
| 190 void test_renameSync_newExists_folder() { |
| 191 String oldPath = provider.convertPath('/foo/bar/file.txt'); |
| 192 String newPath = provider.convertPath('/foo/bar/baz'); |
| 193 File file = provider.newFile(oldPath, 'text'); |
| 194 provider.newFolder(newPath); |
| 195 expect(() { |
| 196 file.renameSync(newPath); |
| 197 }, throwsA(_isFileSystemException)); |
| 198 expect(file.path, oldPath); |
| 199 expect(file.exists, isTrue); |
| 200 } |
| 201 |
| 202 void test_resolveSymbolicLinksSync() { |
| 203 File file = provider.newFile(provider.convertPath('/test.txt'), 'text'); |
| 204 expect(file.resolveSymbolicLinksSync(), file); |
| 205 } |
| 206 |
| 138 void test_shortName() { | 207 void test_shortName() { |
| 139 File file = provider.getResource('/foo/bar/file.txt'); | 208 File file = provider.getResource(provider.convertPath('/foo/bar/file.txt')); |
| 140 expect(file.shortName, 'file.txt'); | 209 expect(file.shortName, 'file.txt'); |
| 141 } | 210 } |
| 142 | 211 |
| 143 void test_toString() { | 212 void test_toString() { |
| 144 File file = provider.getResource('/foo/bar/file.txt'); | 213 String path = provider.convertPath('/foo/bar/file.txt'); |
| 145 expect(file.toString(), '/foo/bar/file.txt'); | 214 File file = provider.getResource(path); |
| 215 expect(file.toString(), path); |
| 216 } |
| 217 |
| 218 void test_toUri() { |
| 219 String path = provider.convertPath('/foo/file.txt'); |
| 220 File file = provider.newFile(path, ''); |
| 221 expect(file.toUri(), provider.pathContext.toUri(path)); |
| 222 } |
| 223 |
| 224 void test_writeAsBytesSync_existing() { |
| 225 List<int> content = <int>[1, 2]; |
| 226 File file = provider.newFileWithBytes( |
| 227 provider.convertPath('/foo/file.bin'), content); |
| 228 expect(file.readAsBytesSync(), content); |
| 229 // write new bytes |
| 230 content = <int>[10, 20]; |
| 231 file.writeAsBytesSync(content); |
| 232 expect(file.readAsBytesSync(), content); |
| 233 } |
| 234 |
| 235 void test_writeAsBytesSync_new() { |
| 236 File file = provider.getFile(provider.convertPath('/foo/file.bin')); |
| 237 expect(file.exists, false); |
| 238 // write new bytes |
| 239 List<int> content = <int>[10, 20]; |
| 240 file.writeAsBytesSync(content); |
| 241 expect(file.exists, true); |
| 242 expect(file.readAsBytesSync(), content); |
| 243 } |
| 244 |
| 245 void test_writeAsStringSync_existing() { |
| 246 String content = 'ab'; |
| 247 File file = |
| 248 provider.newFile(provider.convertPath('/foo/file.txt'), content); |
| 249 expect(file.readAsStringSync(), content); |
| 250 // write new bytes |
| 251 content = 'CD'; |
| 252 file.writeAsStringSync(content); |
| 253 expect(file.readAsStringSync(), content); |
| 254 } |
| 255 |
| 256 void test_writeAsStringSync_new() { |
| 257 File file = provider.getFile(provider.convertPath('/foo/file.txt')); |
| 258 expect(file.exists, false); |
| 259 // write new bytes |
| 260 String content = 'ef'; |
| 261 file.writeAsStringSync(content); |
| 262 expect(file.exists, true); |
| 263 expect(file.readAsStringSync(), content); |
| 146 } | 264 } |
| 147 } | 265 } |
| 148 | 266 |
| 149 @reflectiveTest | 267 @reflectiveTest |
| 150 class FolderTest { | 268 class FolderTest { |
| 151 static const String path = '/foo/bar'; | |
| 152 | |
| 153 MemoryResourceProvider provider = new MemoryResourceProvider(); | 269 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 270 String path; |
| 154 Folder folder; | 271 Folder folder; |
| 155 | 272 |
| 156 void setUp() { | 273 void setUp() { |
| 274 path = provider.convertPath('/foo/bar'); |
| 157 folder = provider.newFolder(path); | 275 folder = provider.newFolder(path); |
| 158 } | 276 } |
| 159 | 277 |
| 160 void test_canonicalizePath() { | 278 void test_canonicalizePath() { |
| 161 expect(folder.canonicalizePath('baz'), equals('/foo/bar/baz')); | 279 expect(folder.canonicalizePath(provider.convertPath('baz')), |
| 162 expect(folder.canonicalizePath('/baz'), equals('/baz')); | 280 equals(provider.convertPath('/foo/bar/baz'))); |
| 163 expect(folder.canonicalizePath('../baz'), equals('/foo/baz')); | 281 expect(folder.canonicalizePath(provider.convertPath('/baz')), |
| 164 expect(folder.canonicalizePath('/a/b/../c'), equals('/a/c')); | 282 equals(provider.convertPath('/baz'))); |
| 165 expect(folder.canonicalizePath('./baz'), equals('/foo/bar/baz')); | 283 expect(folder.canonicalizePath(provider.convertPath('../baz')), |
| 166 expect(folder.canonicalizePath('/a/b/./c'), equals('/a/b/c')); | 284 equals(provider.convertPath('/foo/baz'))); |
| 285 expect(folder.canonicalizePath(provider.convertPath('/a/b/../c')), |
| 286 equals(provider.convertPath('/a/c'))); |
| 287 expect(folder.canonicalizePath(provider.convertPath('./baz')), |
| 288 equals(provider.convertPath('/foo/bar/baz'))); |
| 289 expect(folder.canonicalizePath(provider.convertPath('/a/b/./c')), |
| 290 equals(provider.convertPath('/a/b/c'))); |
| 167 } | 291 } |
| 168 | 292 |
| 169 void test_contains() { | 293 void test_contains() { |
| 170 expect(folder.contains('/foo/bar/aaa.txt'), isTrue); | 294 expect(folder.contains(provider.convertPath('/foo/bar/aaa.txt')), isTrue); |
| 171 expect(folder.contains('/foo/bar/aaa/bbb.txt'), isTrue); | 295 expect( |
| 172 expect(folder.contains('/baz.txt'), isFalse); | 296 folder.contains(provider.convertPath('/foo/bar/aaa/bbb.txt')), isTrue); |
| 173 expect(folder.contains('/foo/bar'), isFalse); | 297 expect(folder.contains(provider.convertPath('/baz.txt')), isFalse); |
| 298 expect(folder.contains(provider.convertPath('/foo/bar')), isFalse); |
| 299 } |
| 300 |
| 301 void test_delete() { |
| 302 Folder folder = provider.newFolder(provider.convertPath('/foo')); |
| 303 Folder barFolder = provider.newFolder(provider.convertPath('/foo/bar')); |
| 304 File aFile = provider.newFile(provider.convertPath('/foo/bar/a.txt'), ''); |
| 305 File bFile = provider.newFile(provider.convertPath('/foo/b.txt'), ''); |
| 306 expect(folder.exists, isTrue); |
| 307 expect(barFolder.exists, isTrue); |
| 308 expect(aFile.exists, isTrue); |
| 309 expect(bFile.exists, isTrue); |
| 310 // delete 'folder' |
| 311 folder.delete(); |
| 312 expect(folder.exists, isFalse); |
| 313 expect(barFolder.exists, isFalse); |
| 314 expect(aFile.exists, isFalse); |
| 315 expect(bFile.exists, isFalse); |
| 174 } | 316 } |
| 175 | 317 |
| 176 void test_equal_false() { | 318 void test_equal_false() { |
| 177 String path2 = '/foo/baz'; | 319 String path2 = provider.convertPath('/foo/baz'); |
| 178 Folder folder2 = provider.newFolder(path2); | 320 Folder folder2 = provider.newFolder(path2); |
| 179 expect(folder == folder2, isFalse); | 321 expect(folder == folder2, isFalse); |
| 180 } | 322 } |
| 181 | 323 |
| 182 void test_equal_true() { | 324 void test_equal_true() { |
| 183 Folder folder2 = provider.getResource(path); | 325 Folder folder2 = provider.getResource(path); |
| 184 expect(folder == folder2, isTrue); | 326 expect(folder == folder2, isTrue); |
| 185 } | 327 } |
| 186 | 328 |
| 187 void test_getChild_doesNotExist() { | 329 void test_getChild_doesNotExist() { |
| 188 File file = folder.getChild('file.txt'); | 330 File file = folder.getChild('file.txt'); |
| 189 expect(file, isNotNull); | 331 expect(file, isNotNull); |
| 190 expect(file.exists, isFalse); | 332 expect(file.exists, isFalse); |
| 191 } | 333 } |
| 192 | 334 |
| 193 void test_getChild_file() { | 335 void test_getChild_file() { |
| 194 provider.newFile('/foo/bar/file.txt', 'content'); | 336 provider.newFile(provider.convertPath('/foo/bar/file.txt'), 'content'); |
| 195 File child = folder.getChild('file.txt'); | 337 File child = folder.getChild('file.txt'); |
| 196 expect(child, isNotNull); | 338 expect(child, isNotNull); |
| 197 expect(child.exists, isTrue); | 339 expect(child.exists, isTrue); |
| 198 } | 340 } |
| 199 | 341 |
| 200 void test_getChild_folder() { | 342 void test_getChild_folder() { |
| 201 provider.newFolder('/foo/bar/baz'); | 343 provider.newFolder(provider.convertPath('/foo/bar/baz')); |
| 202 Folder child = folder.getChild('baz'); | 344 Folder child = folder.getChild('baz'); |
| 203 expect(child, isNotNull); | 345 expect(child, isNotNull); |
| 204 expect(child.exists, isTrue); | 346 expect(child.exists, isTrue); |
| 205 } | 347 } |
| 206 | 348 |
| 349 void test_getChildAssumingFile_doesNotExist() { |
| 350 File child = folder.getChildAssumingFile('name'); |
| 351 expect(child, isNotNull); |
| 352 expect(child.exists, isFalse); |
| 353 } |
| 354 |
| 355 void test_getChildAssumingFile_file() { |
| 356 provider.newFile(provider.convertPath('/foo/bar/name'), 'content'); |
| 357 File child = folder.getChildAssumingFile('name'); |
| 358 expect(child, isNotNull); |
| 359 expect(child.exists, isTrue); |
| 360 } |
| 361 |
| 362 void test_getChildAssumingFile_folder() { |
| 363 provider.newFolder(provider.convertPath('/foo/bar/name')); |
| 364 File child = folder.getChildAssumingFile('name'); |
| 365 expect(child, isNotNull); |
| 366 expect(child.exists, isFalse); |
| 367 } |
| 368 |
| 207 void test_getChildAssumingFolder_doesNotExist() { | 369 void test_getChildAssumingFolder_doesNotExist() { |
| 208 Folder child = folder.getChildAssumingFolder('foldername'); | 370 Folder child = folder.getChildAssumingFolder('foldername'); |
| 209 expect(child, isNotNull); | 371 expect(child, isNotNull); |
| 210 expect(child.exists, isFalse); | 372 expect(child.exists, isFalse); |
| 211 } | 373 } |
| 212 | 374 |
| 213 void test_getChildAssumingFolder_file() { | 375 void test_getChildAssumingFolder_file() { |
| 214 provider.newFile('/foo/bar/foldername', 'content'); | 376 provider.newFile(provider.convertPath('/foo/bar/foldername'), 'content'); |
| 215 Folder child = folder.getChildAssumingFolder('foldername'); | 377 Folder child = folder.getChildAssumingFolder('foldername'); |
| 216 expect(child, isNotNull); | 378 expect(child, isNotNull); |
| 217 expect(child.exists, isFalse); | 379 expect(child.exists, isFalse); |
| 218 } | 380 } |
| 219 | 381 |
| 220 void test_getChildAssumingFolder_folder() { | 382 void test_getChildAssumingFolder_folder() { |
| 221 provider.newFolder('/foo/bar/foldername'); | 383 provider.newFolder(provider.convertPath('/foo/bar/foldername')); |
| 222 Folder child = folder.getChildAssumingFolder('foldername'); | 384 Folder child = folder.getChildAssumingFolder('foldername'); |
| 223 expect(child, isNotNull); | 385 expect(child, isNotNull); |
| 224 expect(child.exists, isTrue); | 386 expect(child.exists, isTrue); |
| 225 } | 387 } |
| 226 | 388 |
| 227 void test_getChildren_doesNotExist() { | 389 void test_getChildren_doesNotExist() { |
| 228 folder = folder.getChildAssumingFolder('no-such-folder'); | 390 folder = folder.getChildAssumingFolder('no-such-folder'); |
| 229 expect(() { | 391 expect(() { |
| 230 folder.getChildren(); | 392 folder.getChildren(); |
| 231 }, throwsA(_isFileSystemException)); | 393 }, throwsA(_isFileSystemException)); |
| 232 } | 394 } |
| 233 | 395 |
| 234 void test_getChildren_exists() { | 396 void test_getChildren_exists() { |
| 235 provider.newFile('/foo/bar/a.txt', 'aaa'); | 397 provider.newFile(provider.convertPath('/foo/bar/a.txt'), 'aaa'); |
| 236 provider.newFolder('/foo/bar/bFolder'); | 398 provider.newFolder(provider.convertPath('/foo/bar/bFolder')); |
| 237 provider.newFile('/foo/bar/c.txt', 'ccc'); | 399 provider.newFile(provider.convertPath('/foo/bar/c.txt'), 'ccc'); |
| 238 // prepare 3 children | 400 // prepare 3 children |
| 239 List<Resource> children = folder.getChildren(); | 401 List<Resource> children = folder.getChildren(); |
| 240 expect(children, hasLength(3)); | 402 expect(children, hasLength(3)); |
| 241 children.sort((a, b) => a.shortName.compareTo(b.shortName)); | 403 children.sort((a, b) => a.shortName.compareTo(b.shortName)); |
| 242 // check that each child exists | 404 // check that each child exists |
| 243 children.forEach((child) { | 405 children.forEach((child) { |
| 244 expect(child.exists, true); | 406 expect(child.exists, true); |
| 245 }); | 407 }); |
| 246 // check names | 408 // check names |
| 247 expect(children[0].shortName, 'a.txt'); | 409 expect(children[0].shortName, 'a.txt'); |
| 248 expect(children[1].shortName, 'bFolder'); | 410 expect(children[1].shortName, 'bFolder'); |
| 249 expect(children[2].shortName, 'c.txt'); | 411 expect(children[2].shortName, 'c.txt'); |
| 250 // check types | 412 // check types |
| 251 expect(children[0], _isFile); | 413 expect(children[0], _isFile); |
| 252 expect(children[1], _isFolder); | 414 expect(children[1], _isFolder); |
| 253 expect(children[2], _isFile); | 415 expect(children[2], _isFile); |
| 254 } | 416 } |
| 255 | 417 |
| 256 void test_hashCode() { | 418 void test_hashCode() { |
| 257 Folder folder2 = provider.getResource(path); | 419 Folder folder2 = provider.getResource(path); |
| 258 expect(folder.hashCode, folder2.hashCode); | 420 expect(folder.hashCode, folder2.hashCode); |
| 259 } | 421 } |
| 260 | 422 |
| 261 void test_isOrContains() { | 423 void test_isOrContains() { |
| 262 expect(folder.isOrContains('/foo/bar'), isTrue); | 424 expect(folder.isOrContains(provider.convertPath('/foo/bar')), isTrue); |
| 263 expect(folder.isOrContains('/foo/bar/aaa.txt'), isTrue); | 425 expect( |
| 264 expect(folder.isOrContains('/foo/bar/aaa/bbb.txt'), isTrue); | 426 folder.isOrContains(provider.convertPath('/foo/bar/aaa.txt')), isTrue); |
| 265 expect(folder.isOrContains('/baz.txt'), isFalse); | 427 expect(folder.isOrContains(provider.convertPath('/foo/bar/aaa/bbb.txt')), |
| 428 isTrue); |
| 429 expect(folder.isOrContains(provider.convertPath('/baz.txt')), isFalse); |
| 266 } | 430 } |
| 267 | 431 |
| 268 void test_parent() { | 432 void test_parent() { |
| 269 Resource parent1 = folder.parent; | 433 Resource parent1 = folder.parent; |
| 270 expect(parent1, new isInstanceOf<Folder>()); | 434 expect(parent1, new isInstanceOf<Folder>()); |
| 271 expect(parent1.path, equals('/foo')); | 435 expect(parent1.path, equals(provider.convertPath('/foo'))); |
| 272 Resource parent2 = parent1.parent; | 436 Resource parent2 = parent1.parent; |
| 273 expect(parent2, new isInstanceOf<Folder>()); | 437 expect(parent2, new isInstanceOf<Folder>()); |
| 274 expect(parent2.path, equals('/')); | 438 expect(parent2.path, equals(provider.convertPath('/'))); |
| 275 expect(parent2.parent, isNull); | 439 expect(parent2.parent, isNull); |
| 276 } | 440 } |
| 441 |
| 442 void test_toUri() { |
| 443 String path = provider.convertPath('/foo/directory'); |
| 444 Folder folder = provider.newFolder(path); |
| 445 expect(folder.toUri(), provider.pathContext.toUri(path)); |
| 446 } |
| 277 } | 447 } |
| 278 | 448 |
| 279 @reflectiveTest | 449 @reflectiveTest |
| 280 class MemoryFileSourceExistingTest { | 450 class MemoryFileSourceExistingTest { |
| 281 MemoryResourceProvider provider = new MemoryResourceProvider(); | 451 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 452 String path; |
| 282 Source source; | 453 Source source; |
| 283 | 454 |
| 284 setUp() { | 455 setUp() { |
| 285 File file = provider.newFile('/foo/test.dart', 'library test;'); | 456 path = provider.convertPath('/foo/test.dart'); |
| 457 File file = provider.newFile(path, 'library test;'); |
| 286 source = file.createSource(); | 458 source = file.createSource(); |
| 287 } | 459 } |
| 288 | 460 |
| 289 void test_contents() { | 461 void test_contents() { |
| 290 TimestampedData<String> contents = source.contents; | 462 TimestampedData<String> contents = source.contents; |
| 291 expect(contents.data, 'library test;'); | 463 expect(contents.data, 'library test;'); |
| 292 } | 464 } |
| 293 | 465 |
| 294 void test_encoding() { | 466 void test_encoding() { |
| 295 expect(source.encoding, 'file:///foo/test.dart'); | 467 String expected = 'file:///foo/test.dart'; |
| 468 if (provider.pathContext.style == windows.style) { |
| 469 expected = 'file:///C:/foo/test.dart'; |
| 470 } |
| 471 expect(source.encoding, expected); |
| 296 } | 472 } |
| 297 | 473 |
| 298 void test_equals_false_differentFile() { | 474 void test_equals_false_differentFile() { |
| 299 File fileA = provider.newFile('/foo/a.dart', ''); | 475 File fileA = provider.newFile(provider.convertPath('/foo/a.dart'), ''); |
| 300 File fileB = provider.newFile('/foo/b.dart', ''); | 476 File fileB = provider.newFile(provider.convertPath('/foo/b.dart'), ''); |
| 301 Source sourceA = fileA.createSource(); | 477 Source sourceA = fileA.createSource(); |
| 302 Source sourceB = fileB.createSource(); | 478 Source sourceB = fileB.createSource(); |
| 303 expect(sourceA == sourceB, isFalse); | 479 expect(sourceA == sourceB, isFalse); |
| 304 } | 480 } |
| 305 | 481 |
| 306 void test_equals_false_notMemorySource() { | 482 void test_equals_false_notMemorySource() { |
| 307 File file = provider.newFile('/foo/test.dart', ''); | 483 File file = provider.newFile(path, ''); |
| 308 Source source = file.createSource(); | 484 Source source = file.createSource(); |
| 309 expect(source == new Object(), isFalse); | 485 expect(source == new Object(), isFalse); |
| 310 } | 486 } |
| 311 | 487 |
| 312 void test_equals_true_sameFile() { | 488 void test_equals_true_sameFile() { |
| 313 File file = provider.newFile('/foo/test.dart', ''); | 489 File file = provider.newFile(path, ''); |
| 314 Source sourceA = file.createSource(); | 490 Source sourceA = file.createSource(); |
| 315 Source sourceB = file.createSource(); | 491 Source sourceB = file.createSource(); |
| 316 expect(sourceA == sourceB, isTrue); | 492 expect(sourceA == sourceB, isTrue); |
| 317 } | 493 } |
| 318 | 494 |
| 319 void test_equals_true_self() { | 495 void test_equals_true_self() { |
| 320 File file = provider.newFile('/foo/test.dart', ''); | 496 File file = provider.newFile(path, ''); |
| 321 Source source = file.createSource(); | 497 Source source = file.createSource(); |
| 322 expect(source == source, isTrue); | 498 expect(source == source, isTrue); |
| 323 } | 499 } |
| 324 | 500 |
| 325 void test_exists() { | 501 void test_exists() { |
| 326 expect(source.exists(), isTrue); | 502 expect(source.exists(), isTrue); |
| 327 } | 503 } |
| 328 | 504 |
| 329 void test_fullName() { | 505 void test_fullName() { |
| 330 expect(source.fullName, '/foo/test.dart'); | 506 expect(source.fullName, path); |
| 331 } | 507 } |
| 332 | 508 |
| 333 void test_hashCode() { | 509 void test_hashCode() { |
| 334 source.hashCode; | 510 source.hashCode; |
| 335 } | 511 } |
| 336 | 512 |
| 337 void test_resolveRelative() { | 513 void test_resolveRelative() { |
| 338 Uri relative = source.resolveRelativeUri(new Uri.file('bar/baz.dart')); | 514 Uri relative = resolveRelativeUri( |
| 339 expect(relative.path, '/foo/bar/baz.dart'); | 515 source.uri, |
| 516 provider.pathContext |
| 517 .toUri(provider.pathContext.join('bar', 'baz.dart'))); |
| 518 expect(relative, |
| 519 provider.pathContext.toUri(provider.convertPath('/foo/bar/baz.dart'))); |
| 340 } | 520 } |
| 341 | 521 |
| 342 void test_resolveRelative_dart() { | 522 void test_resolveRelative_dart() { |
| 343 File file = provider.newFile('/sdk/lib/core/core.dart', ''); | 523 File file = |
| 524 provider.newFile(provider.convertPath('/sdk/lib/core/core.dart'), ''); |
| 344 Source source = file.createSource(Uri.parse('dart:core')); | 525 Source source = file.createSource(Uri.parse('dart:core')); |
| 345 Uri resolved = source.resolveRelativeUri(Uri.parse('int.dart')); | 526 Uri resolved = resolveRelativeUri(source.uri, Uri.parse('int.dart')); |
| 346 expect(resolved.toString(), 'dart:core/int.dart'); | 527 expect(resolved.toString(), 'dart:core/int.dart'); |
| 347 } | 528 } |
| 348 | 529 |
| 349 void test_shortName() { | 530 void test_shortName() { |
| 350 expect(source.shortName, 'test.dart'); | 531 expect(source.shortName, 'test.dart'); |
| 351 } | 532 } |
| 352 } | 533 } |
| 353 | 534 |
| 354 @reflectiveTest | 535 @reflectiveTest |
| 355 class MemoryFileSourceNotExistingTest { | 536 class MemoryFileSourceNotExistingTest { |
| 356 MemoryResourceProvider provider = new MemoryResourceProvider(); | 537 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 538 String path; |
| 357 Source source; | 539 Source source; |
| 358 | 540 |
| 359 setUp() { | 541 setUp() { |
| 360 File file = provider.getResource('/foo/test.dart'); | 542 path = provider.convertPath('/foo/test.dart'); |
| 543 File file = provider.getResource(path); |
| 361 source = file.createSource(); | 544 source = file.createSource(); |
| 362 } | 545 } |
| 363 | 546 |
| 364 void test_contents() { | 547 void test_contents() { |
| 365 expect(() { | 548 expect(() { |
| 366 source.contents; | 549 source.contents; |
| 367 }, throwsA(_isFileSystemException)); | 550 }, throwsA(_isFileSystemException)); |
| 368 } | 551 } |
| 369 | 552 |
| 370 void test_encoding() { | 553 void test_encoding() { |
| 371 expect(source.encoding, 'file:///foo/test.dart'); | 554 String expected = 'file:///foo/test.dart'; |
| 555 if (provider.pathContext.style == windows.style) { |
| 556 expected = 'file:///C:/foo/test.dart'; |
| 557 } |
| 558 expect(source.encoding, expected); |
| 372 } | 559 } |
| 373 | 560 |
| 374 void test_exists() { | 561 void test_exists() { |
| 375 expect(source.exists(), isFalse); | 562 expect(source.exists(), isFalse); |
| 376 } | 563 } |
| 377 | 564 |
| 378 void test_fullName() { | 565 void test_fullName() { |
| 379 expect(source.fullName, '/foo/test.dart'); | 566 expect(source.fullName, path); |
| 380 } | 567 } |
| 381 | 568 |
| 382 void test_modificationStamp() { | 569 void test_modificationStamp() { |
| 383 expect(source.modificationStamp, -1); | 570 expect(source.modificationStamp, -1); |
| 384 } | 571 } |
| 385 | 572 |
| 386 void test_resolveRelative() { | 573 void test_resolveRelative() { |
| 387 Uri relative = source.resolveRelativeUri(new Uri.file('bar/baz.dart')); | 574 Uri relative = resolveRelativeUri( |
| 388 expect(relative.path, '/foo/bar/baz.dart'); | 575 source.uri, |
| 576 provider.pathContext |
| 577 .toUri(provider.pathContext.join('bar', 'baz.dart'))); |
| 578 expect(relative, |
| 579 provider.pathContext.toUri(provider.convertPath('/foo/bar/baz.dart'))); |
| 389 } | 580 } |
| 390 | 581 |
| 391 void test_shortName() { | 582 void test_shortName() { |
| 392 expect(source.shortName, 'test.dart'); | 583 expect(source.shortName, 'test.dart'); |
| 393 } | 584 } |
| 394 } | 585 } |
| 395 | 586 |
| 396 @reflectiveTest | 587 @reflectiveTest |
| 397 class MemoryResourceProviderTest { | 588 class MemoryResourceProviderTest { |
| 398 MemoryResourceProvider provider = new MemoryResourceProvider(); | 589 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 399 | 590 |
| 400 void test_deleteFile_folder() { | 591 void test_deleteFile_folder() { |
| 401 String path = '/my/file'; | 592 String path = provider.convertPath('/my/file'); |
| 402 provider.newFolder(path); | 593 provider.newFolder(path); |
| 403 expect(() { | 594 expect(() { |
| 404 provider.deleteFile(path); | 595 provider.deleteFile(path); |
| 405 }, throwsA(new isInstanceOf<ArgumentError>())); | 596 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 406 expect(provider.getResource(path), new isInstanceOf<Folder>()); | 597 expect(provider.getResource(path), new isInstanceOf<Folder>()); |
| 407 } | 598 } |
| 408 | 599 |
| 409 void test_deleteFile_notExistent() { | 600 void test_deleteFile_notExistent() { |
| 410 String path = '/my/file'; | 601 String path = provider.convertPath('/my/file'); |
| 411 expect(() { | 602 expect(() { |
| 412 provider.deleteFile(path); | 603 provider.deleteFile(path); |
| 413 }, throwsA(new isInstanceOf<ArgumentError>())); | 604 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 414 Resource file = provider.getResource(path); | 605 Resource file = provider.getResource(path); |
| 415 expect(file, isNotNull); | 606 expect(file, isNotNull); |
| 416 expect(file.exists, isFalse); | 607 expect(file.exists, isFalse); |
| 417 } | 608 } |
| 418 | 609 |
| 419 void test_deleteFile_success() { | 610 void test_deleteFile_success() { |
| 420 String path = '/my/file'; | 611 String path = provider.convertPath('/my/file'); |
| 421 provider.newFile(path, 'contents'); | 612 provider.newFile(path, 'contents'); |
| 422 Resource file = provider.getResource(path); | 613 Resource file = provider.getResource(path); |
| 423 expect(file, new isInstanceOf<File>()); | 614 expect(file, new isInstanceOf<File>()); |
| 424 expect(file.exists, isTrue); | 615 expect(file.exists, isTrue); |
| 425 provider.deleteFile(path); | 616 provider.deleteFile(path); |
| 426 expect(file.exists, isFalse); | 617 expect(file.exists, isFalse); |
| 427 } | 618 } |
| 428 | 619 |
| 620 test_getModificationTimes() async { |
| 621 File file = provider.newFile(provider.convertPath('/test.dart'), ''); |
| 622 Source source = file.createSource(); |
| 623 List<int> times = await provider.getModificationTimes([source]); |
| 624 expect(times, [source.modificationStamp]); |
| 625 } |
| 626 |
| 429 void test_getStateLocation_uniqueness() { | 627 void test_getStateLocation_uniqueness() { |
| 430 String idOne = 'one'; | 628 String idOne = 'one'; |
| 431 Folder folderOne = provider.getStateLocation(idOne); | 629 Folder folderOne = provider.getStateLocation(idOne); |
| 432 expect(folderOne, isNotNull); | 630 expect(folderOne, isNotNull); |
| 433 String idTwo = 'two'; | 631 String idTwo = 'two'; |
| 434 Folder folderTwo = provider.getStateLocation(idTwo); | 632 Folder folderTwo = provider.getStateLocation(idTwo); |
| 435 expect(folderTwo, isNotNull); | 633 expect(folderTwo, isNotNull); |
| 436 expect(folderTwo, isNot(equals(folderOne))); | 634 expect(folderTwo, isNot(equals(folderOne))); |
| 437 expect(provider.getStateLocation(idOne), equals(folderOne)); | 635 expect(provider.getStateLocation(idOne), equals(folderOne)); |
| 438 } | 636 } |
| 439 | 637 |
| 440 void test_modifyFile_isFolder() { | 638 void test_modifyFile_isFolder() { |
| 441 String path = '/my/file'; | 639 String path = provider.convertPath('/my/file'); |
| 442 provider.newFolder(path); | 640 provider.newFolder(path); |
| 443 expect(() { | 641 expect(() { |
| 444 provider.modifyFile(path, 'contents'); | 642 provider.modifyFile(path, 'contents'); |
| 445 }, throwsA(new isInstanceOf<ArgumentError>())); | 643 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 446 expect(provider.getResource(path), new isInstanceOf<Folder>()); | 644 expect(provider.getResource(path), new isInstanceOf<Folder>()); |
| 447 } | 645 } |
| 448 | 646 |
| 449 void test_modifyFile_notExistent() { | 647 void test_modifyFile_notExistent() { |
| 450 String path = '/my/file'; | 648 String path = provider.convertPath('/my/file'); |
| 451 expect(() { | 649 expect(() { |
| 452 provider.modifyFile(path, 'contents'); | 650 provider.modifyFile(path, 'contents'); |
| 453 }, throwsA(new isInstanceOf<ArgumentError>())); | 651 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 454 Resource file = provider.getResource(path); | 652 Resource file = provider.getResource(path); |
| 455 expect(file, isNotNull); | 653 expect(file, isNotNull); |
| 456 expect(file.exists, isFalse); | 654 expect(file.exists, isFalse); |
| 457 } | 655 } |
| 458 | 656 |
| 459 void test_modifyFile_success() { | 657 void test_modifyFile_success() { |
| 460 String path = '/my/file'; | 658 String path = provider.convertPath('/my/file'); |
| 461 provider.newFile(path, 'contents 1'); | 659 provider.newFile(path, 'contents 1'); |
| 462 Resource file = provider.getResource(path); | 660 Resource file = provider.getResource(path); |
| 463 expect(file, new isInstanceOf<File>()); | 661 expect(file, new isInstanceOf<File>()); |
| 464 Source source = (file as File).createSource(); | 662 Source source = (file as File).createSource(); |
| 465 expect(source.contents.data, equals('contents 1')); | 663 expect(source.contents.data, equals('contents 1')); |
| 466 provider.modifyFile(path, 'contents 2'); | 664 provider.modifyFile(path, 'contents 2'); |
| 467 expect(source.contents.data, equals('contents 2')); | 665 expect(source.contents.data, equals('contents 2')); |
| 468 } | 666 } |
| 469 | 667 |
| 470 void test_newFolder_aleadyExists_asFile() { | 668 void test_newFileWithBytes() { |
| 471 provider.newFile('/my/file', 'qwerty'); | 669 String path = provider.convertPath('/my/file'); |
| 670 List<int> bytes = <int>[1, 2, 3, 4, 5]; |
| 671 provider.newFileWithBytes(path, bytes); |
| 672 File file = provider.getResource(path); |
| 673 expect(file, isNotNull); |
| 674 expect(file.exists, isTrue); |
| 675 expect(file.readAsBytesSync(), bytes); |
| 676 } |
| 677 |
| 678 void test_newFolder_alreadyExists_asFile() { |
| 679 provider.newFile(provider.convertPath('/my/file'), 'qwerty'); |
| 472 expect(() { | 680 expect(() { |
| 473 provider.newFolder('/my/file'); | 681 provider.newFolder(provider.convertPath('/my/file')); |
| 474 }, throwsA(new isInstanceOf<ArgumentError>())); | 682 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 475 } | 683 } |
| 476 | 684 |
| 477 void test_newFolder_aleadyExists_asFolder() { | 685 void test_newFolder_alreadyExists_asFolder() { |
| 478 Folder folder = provider.newFolder('/my/folder'); | 686 String path = provider.convertPath('/my/folder'); |
| 479 Folder newFolder = provider.newFolder('/my/folder'); | 687 Folder folder = provider.newFolder(path); |
| 688 Folder newFolder = provider.newFolder(path); |
| 480 expect(newFolder, folder); | 689 expect(newFolder, folder); |
| 481 } | 690 } |
| 482 | 691 |
| 483 void test_newFolder_emptyPath() { | 692 void test_newFolder_emptyPath() { |
| 484 expect(() { | 693 expect(() { |
| 485 provider.newFolder(''); | 694 provider.newFolder(''); |
| 486 }, throwsA(new isInstanceOf<ArgumentError>())); | 695 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 487 } | 696 } |
| 488 | 697 |
| 489 void test_newFolder_notAbsolute() { | 698 void test_newFolder_notAbsolute() { |
| 490 expect(() { | 699 expect(() { |
| 491 provider.newFolder('not/absolute'); | 700 provider.newFolder('not/absolute'); |
| 492 }, throwsA(new isInstanceOf<ArgumentError>())); | 701 }, throwsA(new isInstanceOf<ArgumentError>())); |
| 493 } | 702 } |
| 494 | 703 |
| 495 test_watch_createFile() { | 704 test_watch_createFile() { |
| 496 String rootPath = '/my/path'; | 705 String rootPath = provider.convertPath('/my/path'); |
| 497 provider.newFolder(rootPath); | 706 provider.newFolder(rootPath); |
| 498 return _watchingFolder(rootPath, (changesReceived) { | 707 return _watchingFolder(rootPath, (changesReceived) { |
| 499 expect(changesReceived, hasLength(0)); | 708 expect(changesReceived, hasLength(0)); |
| 500 String path = posix.join(rootPath, 'foo'); | 709 String path = provider.pathContext.join(rootPath, 'foo'); |
| 501 provider.newFile(path, 'contents'); | 710 provider.newFile(path, 'contents'); |
| 502 return _delayed(() { | 711 return _delayed(() { |
| 503 expect(changesReceived, hasLength(1)); | 712 expect(changesReceived, hasLength(1)); |
| 504 expect(changesReceived[0].type, equals(ChangeType.ADD)); | 713 expect(changesReceived[0].type, equals(ChangeType.ADD)); |
| 505 expect(changesReceived[0].path, equals(path)); | 714 expect(changesReceived[0].path, equals(path)); |
| 506 }); | 715 }); |
| 507 }); | 716 }); |
| 508 } | 717 } |
| 509 | 718 |
| 510 test_watch_deleteFile() { | 719 test_watch_deleteFile() { |
| 511 String rootPath = '/my/path'; | 720 String rootPath = provider.convertPath('/my/path'); |
| 512 provider.newFolder(rootPath); | 721 provider.newFolder(rootPath); |
| 513 String path = posix.join(rootPath, 'foo'); | 722 String path = provider.pathContext.join(rootPath, 'foo'); |
| 514 provider.newFile(path, 'contents 1'); | 723 provider.newFile(path, 'contents 1'); |
| 515 return _watchingFolder(rootPath, (changesReceived) { | 724 return _watchingFolder(rootPath, (changesReceived) { |
| 516 expect(changesReceived, hasLength(0)); | 725 expect(changesReceived, hasLength(0)); |
| 517 provider.deleteFile(path); | 726 provider.deleteFile(path); |
| 518 return _delayed(() { | 727 return _delayed(() { |
| 519 expect(changesReceived, hasLength(1)); | 728 expect(changesReceived, hasLength(1)); |
| 520 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); | 729 expect(changesReceived[0].type, equals(ChangeType.REMOVE)); |
| 521 expect(changesReceived[0].path, equals(path)); | 730 expect(changesReceived[0].path, equals(path)); |
| 522 }); | 731 }); |
| 523 }); | 732 }); |
| 524 } | 733 } |
| 525 | 734 |
| 526 test_watch_modifyFile() { | 735 test_watch_modifyFile() { |
| 527 String rootPath = '/my/path'; | 736 String rootPath = provider.convertPath('/my/path'); |
| 528 provider.newFolder(rootPath); | 737 provider.newFolder(rootPath); |
| 529 String path = posix.join(rootPath, 'foo'); | 738 String path = provider.pathContext.join(rootPath, 'foo'); |
| 530 provider.newFile(path, 'contents 1'); | 739 provider.newFile(path, 'contents 1'); |
| 531 return _watchingFolder(rootPath, (changesReceived) { | 740 return _watchingFolder(rootPath, (changesReceived) { |
| 532 expect(changesReceived, hasLength(0)); | 741 expect(changesReceived, hasLength(0)); |
| 533 provider.modifyFile(path, 'contents 2'); | 742 provider.modifyFile(path, 'contents 2'); |
| 534 return _delayed(() { | 743 return _delayed(() { |
| 535 expect(changesReceived, hasLength(1)); | 744 expect(changesReceived, hasLength(1)); |
| 536 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); | 745 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); |
| 537 expect(changesReceived[0].path, equals(path)); | 746 expect(changesReceived[0].path, equals(path)); |
| 538 }); | 747 }); |
| 539 }); | 748 }); |
| 540 } | 749 } |
| 541 | 750 |
| 542 test_watch_modifyFile_inSubDir() { | 751 test_watch_modifyFile_inSubDir() { |
| 543 String rootPath = '/my/path'; | 752 String rootPath = provider.convertPath('/my/path'); |
| 544 provider.newFolder(rootPath); | 753 provider.newFolder(rootPath); |
| 545 String subdirPath = posix.join(rootPath, 'foo'); | 754 String subdirPath = provider.pathContext.join(rootPath, 'foo'); |
| 546 provider.newFolder(subdirPath); | 755 provider.newFolder(subdirPath); |
| 547 String path = posix.join(rootPath, 'bar'); | 756 String path = provider.pathContext.join(rootPath, 'bar'); |
| 548 provider.newFile(path, 'contents 1'); | 757 provider.newFile(path, 'contents 1'); |
| 549 return _watchingFolder(rootPath, (changesReceived) { | 758 return _watchingFolder(rootPath, (changesReceived) { |
| 550 expect(changesReceived, hasLength(0)); | 759 expect(changesReceived, hasLength(0)); |
| 551 provider.modifyFile(path, 'contents 2'); | 760 provider.modifyFile(path, 'contents 2'); |
| 552 return _delayed(() { | 761 return _delayed(() { |
| 553 expect(changesReceived, hasLength(1)); | 762 expect(changesReceived, hasLength(1)); |
| 554 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); | 763 expect(changesReceived[0].type, equals(ChangeType.MODIFY)); |
| 555 expect(changesReceived[0].path, equals(path)); | 764 expect(changesReceived[0].path, equals(path)); |
| 556 }); | 765 }); |
| 557 }); | 766 }); |
| 558 } | 767 } |
| 559 | 768 |
| 560 Future _delayed(computation()) { | 769 Future _delayed(computation()) { |
| 561 return new Future.delayed(Duration.ZERO, computation); | 770 return new Future.delayed(Duration.ZERO, computation); |
| 562 } | 771 } |
| 563 | 772 |
| 564 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { | 773 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { |
| 565 Folder folder = provider.getResource(path); | 774 Folder folder = provider.getResource(path); |
| 566 var changesReceived = <WatchEvent>[]; | 775 var changesReceived = <WatchEvent>[]; |
| 567 folder.changes.listen(changesReceived.add); | 776 folder.changes.listen(changesReceived.add); |
| 568 return test(changesReceived); | 777 return test(changesReceived); |
| 569 } | 778 } |
| 570 } | 779 } |
| OLD | NEW |