| 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:unittest/unittest.dart'; |
| 12 |
| 13 import '../reflective_tests.dart'; |
| 14 import '../utils.dart'; |
| 15 |
| 16 main() { |
| 17 initializeTestEnvironment(); |
| 18 runReflectiveTests(ResourceUriResolverTest); |
| 19 } |
| 20 |
| 21 @reflectiveTest |
| 22 class ResourceUriResolverTest { |
| 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('/workspace'); |
| 31 buildDirs = [provider.newFolder('/workspace/one'), provider.newFolder('/work
space/two')]; |
| 32 resolver = new BazelFileUriResolver(provider, workspace, buildDirs); |
| 33 provider.newFile('/workspace/test.dart', ''); |
| 34 provider.newFile('/workspace/one/gen1.dart', ''); |
| 35 provider.newFile('/workspace/two/gen2.dart', ''); |
| 36 } |
| 37 |
| 38 void test_creation() { |
| 39 expect(provider, isNotNull); |
| 40 expect(workspace, isNotNull); |
| 41 expect(buildDirs, isNotNull); |
| 42 expect(buildDirs.length, 2); |
| 43 expect(resolver, isNotNull); |
| 44 } |
| 45 |
| 46 void test_resolveAbsolute_file() { |
| 47 var uri = new Uri(scheme: 'file', path: '/workspace/test.dart'); |
| 48 Source source = resolver.resolveAbsolute(uri); |
| 49 expect(source, isNotNull); |
| 50 expect(source.exists(), isTrue); |
| 51 expect(source.fullName, '/workspace/test.dart'); |
| 52 } |
| 53 |
| 54 void test_resolveAbsolute_folder() { |
| 55 var uri = new Uri(scheme: 'file', path: '/workspace'); |
| 56 Source source = resolver.resolveAbsolute(uri); |
| 57 expect(source, isNull); |
| 58 } |
| 59 |
| 60 void test_resolveAbsolute_notFile_httpsUri() { |
| 61 var uri = new Uri(scheme: 'https', path: '127.0.0.1/test.dart'); |
| 62 Source source = resolver.resolveAbsolute(uri); |
| 63 expect(source, isNull); |
| 64 } |
| 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 |
| 72 void test_resolveAbsolute_generated_file_exists_one() { |
| 73 var uri = new Uri(scheme: 'file', path: '/workspace/gen1.dart'); |
| 74 Source source = resolver.resolveAbsolute(uri); |
| 75 expect(source, isNotNull); |
| 76 expect(source.exists(), isTrue); |
| 77 expect(source.fullName, '/workspace/one/gen1.dart'); |
| 78 } |
| 79 |
| 80 void test_resolveAbsolute_generated_file_exists_two() { |
| 81 var uri = new Uri(scheme: 'file', path: '/workspace/gen2.dart'); |
| 82 Source source = resolver.resolveAbsolute(uri); |
| 83 expect(source, isNotNull); |
| 84 expect(source.exists(), isTrue); |
| 85 expect(source.fullName, '/workspace/two/gen2.dart'); |
| 86 } |
| 87 |
| 88 void test_resolveAbsolute_generated_file_does_not_exist_three() { |
| 89 var uri = new Uri(scheme: 'file', path: '/workspace/gen3.dart'); |
| 90 Source source = resolver.resolveAbsolute(uri); |
| 91 expect(source, isNull); |
| 92 } |
| 93 |
| 94 void test_restoreAbsolute() { |
| 95 var uri = new Uri(scheme: 'file', path: '/workspace/test.dart'); |
| 96 Source source = resolver.resolveAbsolute(uri); |
| 97 expect(source, isNotNull); |
| 98 expect(resolver.restoreAbsolute(source), uri); |
| 99 expect( |
| 100 resolver.restoreAbsolute( |
| 101 new NonExistingSource(source.fullName, null, null)), |
| 102 uri); |
| 103 } |
| 104 } |
| OLD | NEW |