| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.test.generated.bazel_test; |
| 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/generated/bazel.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 import 'package:unittest/unittest.dart'; |
| 13 |
| 14 import '../utils.dart'; |
| 15 |
| 16 main() { |
| 17 initializeTestEnvironment(); |
| 18 defineReflectiveTests(BazelFileUriResolverTest); |
| 19 } |
| 20 |
| 21 @reflectiveTest |
| 22 class BazelFileUriResolverTest { |
| 23 MemoryResourceProvider provider; |
| 24 Folder workspace; |
| 25 List<Folder> buildDirs; |
| 26 ResourceUriResolver resolver; |
| 27 |
| 28 void setUp() { |
| 29 provider = new MemoryResourceProvider(); |
| 30 workspace = provider.newFolder(provider.convertPath('/workspace')); |
| 31 buildDirs = [ |
| 32 provider.newFolder(provider.convertPath('/workspace/one')), |
| 33 provider.newFolder(provider.convertPath('/workspace/two')) |
| 34 ]; |
| 35 resolver = new BazelFileUriResolver(provider, workspace, buildDirs); |
| 36 provider.newFile(provider.convertPath('/workspace/test.dart'), ''); |
| 37 provider.newFile(provider.convertPath('/workspace/one/gen1.dart'), ''); |
| 38 provider.newFile(provider.convertPath('/workspace/two/gen2.dart'), ''); |
| 39 } |
| 40 |
| 41 void test_creation() { |
| 42 expect(provider, isNotNull); |
| 43 expect(workspace, isNotNull); |
| 44 expect(buildDirs, isNotNull); |
| 45 expect(buildDirs.length, 2); |
| 46 expect(resolver, isNotNull); |
| 47 } |
| 48 |
| 49 void test_resolveAbsolute_file() { |
| 50 var uri = provider.pathContext |
| 51 .toUri(provider.convertPath('/workspace/test.dart')); |
| 52 Source source = resolver.resolveAbsolute(uri); |
| 53 expect(source, isNotNull); |
| 54 expect(source.exists(), isTrue); |
| 55 expect(source.fullName, provider.convertPath('/workspace/test.dart')); |
| 56 } |
| 57 |
| 58 void test_resolveAbsolute_folder() { |
| 59 var uri = provider.pathContext.toUri(provider.convertPath('/workspace')); |
| 60 Source source = resolver.resolveAbsolute(uri); |
| 61 expect(source, isNull); |
| 62 } |
| 63 |
| 64 void test_resolveAbsolute_generated_file_does_not_exist_three() { |
| 65 var uri = provider.pathContext |
| 66 .toUri(provider.convertPath('/workspace/gen3.dart')); |
| 67 Source source = resolver.resolveAbsolute(uri); |
| 68 expect(source, isNull); |
| 69 } |
| 70 |
| 71 void test_resolveAbsolute_generated_file_exists_one() { |
| 72 var uri = provider.pathContext |
| 73 .toUri(provider.convertPath('/workspace/gen1.dart')); |
| 74 Source source = resolver.resolveAbsolute(uri); |
| 75 expect(source, isNotNull); |
| 76 expect(source.exists(), isTrue); |
| 77 expect(source.fullName, provider.convertPath('/workspace/one/gen1.dart')); |
| 78 } |
| 79 |
| 80 void test_resolveAbsolute_generated_file_exists_two() { |
| 81 var uri = provider.pathContext |
| 82 .toUri(provider.convertPath('/workspace/gen2.dart')); |
| 83 Source source = resolver.resolveAbsolute(uri); |
| 84 expect(source, isNotNull); |
| 85 expect(source.exists(), isTrue); |
| 86 expect(source.fullName, provider.convertPath('/workspace/two/gen2.dart')); |
| 87 } |
| 88 |
| 89 void test_resolveAbsolute_notFile_dartUri() { |
| 90 var uri = new Uri(scheme: 'dart', path: 'core'); |
| 91 Source source = resolver.resolveAbsolute(uri); |
| 92 expect(source, isNull); |
| 93 } |
| 94 |
| 95 void test_resolveAbsolute_notFile_httpsUri() { |
| 96 var uri = new Uri(scheme: 'https', path: '127.0.0.1/test.dart'); |
| 97 Source source = resolver.resolveAbsolute(uri); |
| 98 expect(source, isNull); |
| 99 } |
| 100 |
| 101 void test_restoreAbsolute() { |
| 102 var uri = provider.pathContext |
| 103 .toUri(provider.convertPath('/workspace/test.dart')); |
| 104 Source source = resolver.resolveAbsolute(uri); |
| 105 expect(source, isNotNull); |
| 106 expect(resolver.restoreAbsolute(source), uri); |
| 107 expect( |
| 108 resolver.restoreAbsolute( |
| 109 new NonExistingSource(source.fullName, null, null)), |
| 110 uri); |
| 111 } |
| 112 } |
| OLD | NEW |