| 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.resource; | 5 library test.memory_file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/resource.dart'; | |
| 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; | 9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 12 import 'package:path/path.dart'; | 11 import 'package:path/path.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 14 import 'package:watcher/watcher.dart'; | 13 import 'package:watcher/watcher.dart'; |
| 15 | 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 16 import 'mocks.dart'; | 15 import 'package:analyzer/file_system/file_system.dart'; |
| 17 | 16 |
| 18 | 17 |
| 19 var _isFile = new isInstanceOf<File>(); | 18 var _isFile = new isInstanceOf<File>(); |
| 20 var _isFolder = new isInstanceOf<Folder>(); | 19 var _isFolder = new isInstanceOf<Folder>(); |
| 21 var _isMemoryResourceException = new isInstanceOf<MemoryResourceException>(); | 20 var _isMemoryResourceException = new isInstanceOf<MemoryResourceException>(); |
| 22 | 21 |
| 23 | 22 |
| 24 main() { | 23 main() { |
| 25 groupSep = ' | '; | 24 groupSep = ' | '; |
| 26 | 25 |
| 27 group('MemoryResourceProvider', () { | 26 group('MemoryResourceProvider', () { |
| 28 MemoryResourceProvider provider; | 27 MemoryResourceProvider provider; |
| 29 | 28 |
| 30 setUp(() { | 29 setUp(() { |
| 31 provider = new MemoryResourceProvider(); | 30 provider = new MemoryResourceProvider(); |
| 32 }); | 31 }); |
| 33 | 32 |
| 34 test('MemoryResourceException', () { | 33 test('MemoryResourceException', () { |
| 35 var exception = new MemoryResourceException('/my/path', 'my message'); | 34 var exception = new MemoryResourceException('/my/path', 'my message'); |
| 36 expect(exception.path, '/my/path'); | 35 expect(exception.path, '/my/path'); |
| 37 expect(exception.message, 'my message'); | 36 expect(exception.message, 'my message'); |
| 38 expect(exception.toString(), | 37 expect(exception.toString(), |
| 39 'MemoryResourceException(path=/my/path; message=my message)'); | 38 'MemoryResourceException(path=/my/path; message=my message)'); |
| 40 }); | 39 }); |
| 41 | 40 |
| 42 group('Watch', () { | 41 group('Watch', () { |
| 43 | 42 |
| 44 Future delayed(computation()) { | 43 Future delayed(computation()) { |
| 45 return pumpEventQueue().then((_) => computation()); | 44 return new Future.delayed(Duration.ZERO, computation); |
| 46 } | 45 } |
| 47 | 46 |
| 48 watchingFolder(String path, test(List<WatchEvent> changesReceived)) { | 47 watchingFolder(String path, test(List<WatchEvent> changesReceived)) { |
| 49 Folder folder = provider.getResource(path); | 48 Folder folder = provider.getResource(path); |
| 50 var changesReceived = <WatchEvent>[]; | 49 var changesReceived = <WatchEvent>[]; |
| 51 folder.changes.listen(changesReceived.add); | 50 folder.changes.listen(changesReceived.add); |
| 52 return test(changesReceived); | 51 return test(changesReceived); |
| 53 } | 52 } |
| 54 | 53 |
| 55 test('create file', () { | 54 test('create file', () { |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 expect(source.shortName, 'test.dart'); | 468 expect(source.shortName, 'test.dart'); |
| 470 }); | 469 }); |
| 471 | 470 |
| 472 test('resolveRelative', () { | 471 test('resolveRelative', () { |
| 473 var relative = source.resolveRelative(new Uri.file('bar/baz.dart')); | 472 var relative = source.resolveRelative(new Uri.file('bar/baz.dart')); |
| 474 expect(relative.fullName, '/foo/bar/baz.dart'); | 473 expect(relative.fullName, '/foo/bar/baz.dart'); |
| 475 }); | 474 }); |
| 476 }); | 475 }); |
| 477 }); | 476 }); |
| 478 }); | 477 }); |
| 479 | |
| 480 group('ResourceUriResolver', testResourceResourceUriResolver); | |
| 481 } | 478 } |
| 482 | |
| 483 | |
| 484 void testResourceResourceUriResolver() { | |
| 485 MemoryResourceProvider provider; | |
| 486 ResourceUriResolver resolver; | |
| 487 | |
| 488 setUp(() { | |
| 489 provider = new MemoryResourceProvider(); | |
| 490 resolver = new ResourceUriResolver(provider); | |
| 491 provider.newFile('/test.dart', ''); | |
| 492 provider.newFolder('/folder'); | |
| 493 }); | |
| 494 | |
| 495 group('fromEncoding', () { | |
| 496 test('file', () { | |
| 497 var uri = new Uri(path: '/test.dart'); | |
| 498 Source source = resolver.fromEncoding(UriKind.FILE_URI, uri); | |
| 499 expect(source, isNotNull); | |
| 500 expect(source.exists(), isTrue); | |
| 501 expect(source.fullName, '/test.dart'); | |
| 502 }); | |
| 503 | |
| 504 test('not a UriKind.FILE_URI', () { | |
| 505 var uri = new Uri(path: '/test.dart'); | |
| 506 Source source = resolver.fromEncoding(UriKind.DART_URI, uri); | |
| 507 expect(source, isNull); | |
| 508 }); | |
| 509 }); | |
| 510 | |
| 511 group('resolveAbsolute', () { | |
| 512 test('file', () { | |
| 513 var uri = new Uri(scheme: 'file', path: '/test.dart'); | |
| 514 Source source = resolver.resolveAbsolute(uri); | |
| 515 expect(source, isNotNull); | |
| 516 expect(source.exists(), isTrue); | |
| 517 expect(source.fullName, '/test.dart'); | |
| 518 }); | |
| 519 | |
| 520 test('folder', () { | |
| 521 var uri = new Uri(scheme: 'file', path: '/folder'); | |
| 522 Source source = resolver.resolveAbsolute(uri); | |
| 523 expect(source, isNull); | |
| 524 }); | |
| 525 | |
| 526 test('not a file URI', () { | |
| 527 var uri = new Uri(scheme: 'https', path: '127.0.0.1/test.dart'); | |
| 528 Source source = resolver.resolveAbsolute(uri); | |
| 529 expect(source, isNull); | |
| 530 }); | |
| 531 }); | |
| 532 } | |
| OLD | NEW |