| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 var dir = new Directory('').createTempSync(); | 137 var dir = new Directory('').createTempSync(); |
| 138 var file = new File(dir.path + '/file'); | 138 var file = new File(dir.path + '/file'); |
| 139 var file2 = new File(dir.path + '/file2'); | 139 var file2 = new File(dir.path + '/file2'); |
| 140 | 140 |
| 141 var watcher = dir.watch(); | 141 var watcher = dir.watch(); |
| 142 | 142 |
| 143 asyncStart(); | 143 asyncStart(); |
| 144 int state = 0; | 144 int state = 0; |
| 145 var sub; | 145 var sub; |
| 146 sub = watcher.listen((event) { | 146 sub = watcher.listen((event) { |
| 147 switch (state) { | 147 int newState = 0; |
| 148 case 0: | 148 switch (event.type) { |
| 149 Expect.isTrue(event is FileSystemCreateEvent); | 149 case FileSystemEvent.CREATE: |
| 150 state = 1; | 150 newState = 1; |
| 151 break; | 151 break; |
| 152 | 152 |
| 153 case 1: | 153 case FileSystemEvent.MODIFY: |
| 154 if (event is FileSystemCreateEvent) break; | 154 newState = 2; |
| 155 Expect.isTrue(event is FileSystemModifyEvent); | |
| 156 state = 2; | |
| 157 break; | 155 break; |
| 158 | 156 |
| 159 case 2: | 157 case FileSystemEvent.MOVE: |
| 160 if (event is FileSystemModifyEvent) break; | 158 newState = 3; |
| 161 Expect.isTrue(event is FileSystemMoveEvent); | |
| 162 state = 3; | |
| 163 break; | 159 break; |
| 164 | 160 |
| 165 case 3: | 161 case FileSystemEvent.DELETE: |
| 166 if (event is FileSystemMoveEvent) break; | 162 newState = 4; |
| 167 Expect.isTrue(event is FileSystemDeleteEvent); | |
| 168 sub.cancel(); | 163 sub.cancel(); |
| 169 asyncEnd(); | 164 asyncEnd(); |
| 170 dir.deleteSync(); | 165 dir.deleteSync(); |
| 171 break; | 166 break; |
| 172 } | 167 } |
| 168 if (newState < state) throw "Bad state"; |
| 169 state = newState; |
| 173 }); | 170 }); |
| 174 | 171 |
| 175 file.createSync(); | 172 runAsync(() { |
| 176 file.writeAsStringSync('a'); | 173 file.createSync(); |
| 177 file.renameSync(file2.path); | 174 file.writeAsStringSync('a'); |
| 178 file2.deleteSync(); | 175 file.renameSync(file2.path); |
| 176 file2.deleteSync(); |
| 177 }); |
| 179 } | 178 } |
| 180 | 179 |
| 181 | 180 |
| 182 void testWatchRecursive() { | 181 void testWatchRecursive() { |
| 183 var dir = new Directory('').createTempSync(); | 182 var dir = new Directory('').createTempSync(); |
| 184 if (Platform.isLinux) { | 183 if (Platform.isLinux) { |
| 185 Expect.throws(() => dir.watch(recursive: true)); | 184 Expect.throws(() => dir.watch(recursive: true)); |
| 186 return; | 185 return; |
| 187 } | 186 } |
| 188 var dir2 = new Directory(dir.path + '/dir'); | 187 var dir2 = new Directory(dir.path + '/dir'); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 238 |
| 240 void main() { | 239 void main() { |
| 241 testWatchCreateFile(); | 240 testWatchCreateFile(); |
| 242 testWatchModifyFile(); | 241 testWatchModifyFile(); |
| 243 testWatchMoveFile(); | 242 testWatchMoveFile(); |
| 244 testWatchDeleteFile(); | 243 testWatchDeleteFile(); |
| 245 testWatchOnlyModifyFile(); | 244 testWatchOnlyModifyFile(); |
| 246 testMultipleEvents(); | 245 testMultipleEvents(); |
| 247 testWatchNonRecursive(); | 246 testWatchNonRecursive(); |
| 248 } | 247 } |
| OLD | NEW |