| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, 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 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. |
| 7 |
| 8 library analyzer.test.generated.source_factory; |
| 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 12 import 'package:analyzer/source/package_map_resolver.dart'; |
| 13 import 'package:analyzer/src/generated/java_core.dart'; |
| 14 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 15 import 'package:analyzer/src/generated/java_io.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/generated/source_io.dart'; |
| 18 import 'package:path/path.dart'; |
| 19 import 'package:unittest/unittest.dart'; |
| 20 |
| 21 import '../reflective_tests.dart'; |
| 22 import 'test_support.dart'; |
| 23 |
| 24 main() { |
| 25 groupSep = ' | '; |
| 26 runReflectiveTests(SourceFactoryTest); |
| 27 } |
| 28 |
| 29 @reflectiveTest |
| 30 class SourceFactoryTest { |
| 31 void test_creation() { |
| 32 expect(new SourceFactory([]), isNotNull); |
| 33 } |
| 34 void test_fromEncoding_invalidUri() { |
| 35 SourceFactory factory = new SourceFactory([]); |
| 36 try { |
| 37 factory.fromEncoding("<:&%>"); |
| 38 fail("Expected IllegalArgumentException"); |
| 39 } on IllegalArgumentException {} |
| 40 } |
| 41 void test_fromEncoding_noResolver() { |
| 42 SourceFactory factory = new SourceFactory([]); |
| 43 try { |
| 44 factory.fromEncoding("foo:/does/not/exist.dart"); |
| 45 fail("Expected IllegalArgumentException"); |
| 46 } on IllegalArgumentException {} |
| 47 } |
| 48 void test_fromEncoding_valid() { |
| 49 String encoding = "file:///does/not/exist.dart"; |
| 50 SourceFactory factory = new SourceFactory( |
| 51 [new UriResolver_SourceFactoryTest_test_fromEncoding_valid(encoding)]); |
| 52 expect(factory.fromEncoding(encoding), isNotNull); |
| 53 } |
| 54 void test_resolveUri_absolute() { |
| 55 UriResolver_absolute resolver = new UriResolver_absolute(); |
| 56 SourceFactory factory = new SourceFactory([resolver]); |
| 57 factory.resolveUri(null, "dart:core"); |
| 58 expect(resolver.invoked, isTrue); |
| 59 } |
| 60 void test_resolveUri_nonAbsolute_absolute() { |
| 61 SourceFactory factory = |
| 62 new SourceFactory([new UriResolver_nonAbsolute_absolute()]); |
| 63 String absolutePath = "/does/not/matter.dart"; |
| 64 Source containingSource = |
| 65 new FileBasedSource(FileUtilities2.createFile("/does/not/exist.dart")); |
| 66 Source result = factory.resolveUri(containingSource, absolutePath); |
| 67 expect(result.fullName, |
| 68 FileUtilities2.createFile(absolutePath).getAbsolutePath()); |
| 69 } |
| 70 void test_resolveUri_nonAbsolute_relative() { |
| 71 SourceFactory factory = |
| 72 new SourceFactory([new UriResolver_nonAbsolute_relative()]); |
| 73 Source containingSource = |
| 74 new FileBasedSource(FileUtilities2.createFile("/does/not/have.dart")); |
| 75 Source result = factory.resolveUri(containingSource, "exist.dart"); |
| 76 expect(result.fullName, |
| 77 FileUtilities2.createFile("/does/not/exist.dart").getAbsolutePath()); |
| 78 } |
| 79 |
| 80 void test_resolveUri_nonAbsolute_relative_package() { |
| 81 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 82 Context context = provider.pathContext; |
| 83 String packagePath = |
| 84 context.joinAll([context.separator, 'path', 'to', 'package']); |
| 85 String libPath = context.joinAll([packagePath, 'lib']); |
| 86 String dirPath = context.joinAll([libPath, 'dir']); |
| 87 String firstPath = context.joinAll([dirPath, 'first.dart']); |
| 88 String secondPath = context.joinAll([dirPath, 'second.dart']); |
| 89 |
| 90 provider.newFolder(packagePath); |
| 91 Folder libFolder = provider.newFolder(libPath); |
| 92 provider.newFolder(dirPath); |
| 93 File firstFile = provider.newFile(firstPath, ''); |
| 94 provider.newFile(secondPath, ''); |
| 95 |
| 96 PackageMapUriResolver resolver = |
| 97 new PackageMapUriResolver(provider, {'package': [libFolder]}); |
| 98 SourceFactory factory = new SourceFactory([resolver]); |
| 99 Source librarySource = |
| 100 firstFile.createSource(Uri.parse('package:package/dir/first.dart')); |
| 101 |
| 102 Source result = factory.resolveUri(librarySource, 'second.dart'); |
| 103 expect(result, isNotNull); |
| 104 expect(result.fullName, secondPath); |
| 105 expect(result.uri.toString(), 'package:package/dir/second.dart'); |
| 106 } |
| 107 |
| 108 void test_restoreUri() { |
| 109 JavaFile file1 = FileUtilities2.createFile("/some/file1.dart"); |
| 110 JavaFile file2 = FileUtilities2.createFile("/some/file2.dart"); |
| 111 Source source1 = new FileBasedSource(file1); |
| 112 Source source2 = new FileBasedSource(file2); |
| 113 Uri expected1 = parseUriWithException("file:///my_file.dart"); |
| 114 SourceFactory factory = |
| 115 new SourceFactory([new UriResolver_restoreUri(source1, expected1)]); |
| 116 expect(factory.restoreUri(source1), same(expected1)); |
| 117 expect(factory.restoreUri(source2), same(null)); |
| 118 } |
| 119 } |
| 120 |
| 121 class UriResolver_absolute extends UriResolver { |
| 122 bool invoked = false; |
| 123 |
| 124 UriResolver_absolute(); |
| 125 |
| 126 @override |
| 127 Source resolveAbsolute(Uri uri) { |
| 128 invoked = true; |
| 129 return null; |
| 130 } |
| 131 } |
| 132 |
| 133 class UriResolver_nonAbsolute_absolute extends UriResolver { |
| 134 @override |
| 135 Source resolveAbsolute(Uri uri) { |
| 136 return new FileBasedSource(new JavaFile.fromUri(uri), uri); |
| 137 } |
| 138 } |
| 139 |
| 140 class UriResolver_nonAbsolute_relative extends UriResolver { |
| 141 @override |
| 142 Source resolveAbsolute(Uri uri) { |
| 143 return new FileBasedSource(new JavaFile.fromUri(uri), uri); |
| 144 } |
| 145 } |
| 146 |
| 147 class UriResolver_restoreUri extends UriResolver { |
| 148 Source source1; |
| 149 |
| 150 Uri expected1; |
| 151 |
| 152 UriResolver_restoreUri(this.source1, this.expected1); |
| 153 |
| 154 @override |
| 155 Source resolveAbsolute(Uri uri) => null; |
| 156 |
| 157 @override |
| 158 Uri restoreAbsolute(Source source) { |
| 159 if (identical(source, source1)) { |
| 160 return expected1; |
| 161 } |
| 162 return null; |
| 163 } |
| 164 } |
| 165 |
| 166 class UriResolver_SourceFactoryTest_test_fromEncoding_valid |
| 167 extends UriResolver { |
| 168 String encoding; |
| 169 |
| 170 UriResolver_SourceFactoryTest_test_fromEncoding_valid(this.encoding); |
| 171 |
| 172 @override |
| 173 Source resolveAbsolute(Uri uri) { |
| 174 if (uri.toString() == encoding) { |
| 175 return new TestSource(); |
| 176 } |
| 177 return null; |
| 178 } |
| 179 } |
| OLD | NEW |