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