OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.test.driver; | 5 library analyzer.test.driver; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 driver.addFile(a); | 259 driver.addFile(a); |
260 expect(driver.addedFiles, contains(a)); | 260 expect(driver.addedFiles, contains(a)); |
261 expect(driver.addedFiles, isNot(contains(b))); | 261 expect(driver.addedFiles, isNot(contains(b))); |
262 | 262 |
263 driver.removeFile(a); | 263 driver.removeFile(a); |
264 expect(driver.addedFiles, isNot(contains(a))); | 264 expect(driver.addedFiles, isNot(contains(a))); |
265 expect(driver.addedFiles, isNot(contains(b))); | 265 expect(driver.addedFiles, isNot(contains(b))); |
266 } | 266 } |
267 | 267 |
| 268 test_addFile_shouldRefresh() async { |
| 269 var a = _p('/test/lib/a.dart'); |
| 270 var b = _p('/test/lib/b.dart'); |
| 271 |
| 272 provider.newFile(a, 'class A {}'); |
| 273 provider.newFile( |
| 274 b, |
| 275 r''' |
| 276 import 'a.dart'; |
| 277 '''); |
| 278 |
| 279 driver.addFile(a); |
| 280 driver.addFile(b); |
| 281 |
| 282 void assertNumberOfErrorsInB(int n) { |
| 283 var bResult = allResults.singleWhere((r) => r.path == b); |
| 284 expect(bResult.errors, hasLength(n)); |
| 285 allResults.clear(); |
| 286 } |
| 287 |
| 288 // Initial analysis, 'b' does not use 'a', so there is a hint. |
| 289 await _waitForIdle(); |
| 290 assertNumberOfErrorsInB(1); |
| 291 |
| 292 // Update 'b' to use 'a', no more hints. |
| 293 provider.newFile( |
| 294 b, |
| 295 r''' |
| 296 import 'a.dart'; |
| 297 main() { |
| 298 print(A); |
| 299 } |
| 300 '''); |
| 301 driver.changeFile(b); |
| 302 await _waitForIdle(); |
| 303 assertNumberOfErrorsInB(0); |
| 304 |
| 305 // Change 'b' t have a hint again. |
| 306 // Add and remove 'b'. |
| 307 // The file must be refreshed, and the hint must be reported. |
| 308 provider.newFile( |
| 309 b, |
| 310 r''' |
| 311 import 'a.dart'; |
| 312 '''); |
| 313 driver.removeFile(b); |
| 314 driver.addFile(b); |
| 315 await _waitForIdle(); |
| 316 assertNumberOfErrorsInB(1); |
| 317 } |
| 318 |
268 test_addFile_thenRemove() async { | 319 test_addFile_thenRemove() async { |
269 var a = _p('/test/lib/a.dart'); | 320 var a = _p('/test/lib/a.dart'); |
270 var b = _p('/test/lib/b.dart'); | 321 var b = _p('/test/lib/b.dart'); |
271 provider.newFile(a, 'class A {}'); | 322 provider.newFile(a, 'class A {}'); |
272 provider.newFile(b, 'class B {}'); | 323 provider.newFile(b, 'class B {}'); |
273 driver.addFile(a); | 324 driver.addFile(a); |
274 driver.addFile(b); | 325 driver.addFile(b); |
275 | 326 |
276 // Now remove 'a'. | 327 // Now remove 'a'. |
277 driver.removeFile(a); | 328 driver.removeFile(a); |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 String _p(String path) => provider.convertPath(path); | 1482 String _p(String path) => provider.convertPath(path); |
1432 | 1483 |
1433 Future<Null> _waitForIdle() async { | 1484 Future<Null> _waitForIdle() async { |
1434 await idleStatusMonitor.signal; | 1485 await idleStatusMonitor.signal; |
1435 } | 1486 } |
1436 | 1487 |
1437 static String _md5(String content) { | 1488 static String _md5(String content) { |
1438 return hex.encode(md5.convert(UTF8.encode(content)).bytes); | 1489 return hex.encode(md5.convert(UTF8.encode(content)).bytes); |
1439 } | 1490 } |
1440 } | 1491 } |
OLD | NEW |