| 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.src.summary.prelinker_test; |
| 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:analyzer/src/summary/format.dart'; |
| 11 import 'package:analyzer/src/summary/prelink.dart'; |
| 12 import 'package:unittest/unittest.dart'; |
| 13 |
| 14 import '../../reflective_tests.dart'; |
| 15 import 'summarize_elements_test.dart'; |
| 16 import 'summary_common.dart'; |
| 17 |
| 18 main() { |
| 19 groupSep = ' | '; |
| 20 runReflectiveTests(PrelinkerTest); |
| 21 } |
| 22 |
| 23 /** |
| 24 * Override of [SummaryTest] which verifies the correctness of the prelinker by |
| 25 * creating summaries from the element model, discarding their prelinked |
| 26 * information, and then recreating it using the prelinker. |
| 27 */ |
| 28 @reflectiveTest |
| 29 class PrelinkerTest extends SummarizeElementsTest { |
| 30 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = |
| 31 <String, UnlinkedPublicNamespace>{}; |
| 32 |
| 33 @override |
| 34 bool get expectAbsoluteUrisInDependencies => false; |
| 35 |
| 36 @override |
| 37 bool get skipFullyLinkedData => true; |
| 38 |
| 39 @override |
| 40 Source addNamedSource(String filePath, String contents) { |
| 41 Source source = super.addNamedSource(filePath, contents); |
| 42 uriToPublicNamespace[absUri(filePath)] = |
| 43 computePublicNamespaceFromText(contents, source); |
| 44 return source; |
| 45 } |
| 46 |
| 47 String resolveToAbsoluteUri(LibraryElement library, String relativeUri) { |
| 48 Source resolvedSource = |
| 49 analysisContext.sourceFactory.resolveUri(library.source, relativeUri); |
| 50 if (resolvedSource == null) { |
| 51 fail('Failed to resolve relative uri "$relativeUri"'); |
| 52 } |
| 53 return resolvedSource.uri.toString(); |
| 54 } |
| 55 |
| 56 @override |
| 57 void serializeLibraryElement(LibraryElement library) { |
| 58 super.serializeLibraryElement(library); |
| 59 Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{}; |
| 60 expect(unlinkedUnits.length, unitUris.length); |
| 61 for (int i = 1; i < unlinkedUnits.length; i++) { |
| 62 uriToUnit[unitUris[i]] = unlinkedUnits[i]; |
| 63 } |
| 64 UnlinkedUnit getPart(String relativeUri) { |
| 65 String absoluteUri = resolveToAbsoluteUri(library, relativeUri); |
| 66 UnlinkedUnit unit = uriToUnit[absoluteUri]; |
| 67 if (unit == null) { |
| 68 fail('Prelinker unexpectedly requested unit for "$relativeUri"' |
| 69 ' (resolves to "$absoluteUri").'); |
| 70 } |
| 71 return unit; |
| 72 } |
| 73 UnlinkedPublicNamespace getImport(String relativeUri) { |
| 74 String absoluteUri = resolveToAbsoluteUri(library, relativeUri); |
| 75 UnlinkedPublicNamespace namespace = sdkPublicNamespace[absoluteUri]; |
| 76 if (namespace == null) { |
| 77 namespace = uriToPublicNamespace[absoluteUri]; |
| 78 } |
| 79 if (namespace == null && !allowMissingFiles) { |
| 80 fail('Prelinker unexpectedly requested namespace for "$relativeUri"' |
| 81 ' (resolves to "$absoluteUri").' |
| 82 ' Namespaces available: ${uriToPublicNamespace.keys}'); |
| 83 } |
| 84 return namespace; |
| 85 } |
| 86 linked = new LinkedLibrary.fromBuffer( |
| 87 prelink(unlinkedUnits[0], getPart, getImport).toBuffer()); |
| 88 } |
| 89 } |
| OLD | NEW |