Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: pkg/analyzer/test/src/dart/sdk/sdk_test.dart

Issue 2344933002: Fix recently introduced strong-mode errors (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.sdk_test; 5 library analyzer.test.generated.sdk_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/context/builder.dart' show EmbedderYamlLocator; 9 import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator;
10 import 'package:analyzer/src/dart/sdk/sdk.dart'; 10 import 'package:analyzer/src/dart/sdk/sdk.dart';
(...skipping 15 matching lines...) Expand all
26 defineReflectiveTests(EmbedderSdkTest); 26 defineReflectiveTests(EmbedderSdkTest);
27 defineReflectiveTests(FolderBasedDartSdkTest); 27 defineReflectiveTests(FolderBasedDartSdkTest);
28 defineReflectiveTests(SdkExtensionFinderTest); 28 defineReflectiveTests(SdkExtensionFinderTest);
29 defineReflectiveTests(SDKLibrariesReaderTest); 29 defineReflectiveTests(SDKLibrariesReaderTest);
30 } 30 }
31 31
32 @reflectiveTest 32 @reflectiveTest
33 class EmbedderSdkTest extends EmbedderRelatedTest { 33 class EmbedderSdkTest extends EmbedderRelatedTest {
34 void test_creation() { 34 void test_creation() {
35 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 35 EmbedderYamlLocator locator = new EmbedderYamlLocator({
36 'fox': [pathTranslator.getResource(foxLib)] 36 'fox': <Folder>[pathTranslator.getResource(foxLib)]
37 }); 37 });
38 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); 38 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
39 39
40 expect(sdk.urlMappings, hasLength(5)); 40 expect(sdk.urlMappings, hasLength(5));
41 } 41 }
42 42
43 void test_fromFileUri() { 43 void test_fromFileUri() {
44 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 44 EmbedderYamlLocator locator = new EmbedderYamlLocator({
45 'fox': [pathTranslator.getResource(foxLib)] 45 'fox': <Folder>[pathTranslator.getResource(foxLib)]
46 }); 46 });
47 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); 47 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
48 48
49 expectSource(String posixPath, String dartUri) { 49 expectSource(String posixPath, String dartUri) {
50 Uri uri = Uri.parse(posixToOSFileUri(posixPath)); 50 Uri uri = Uri.parse(posixToOSFileUri(posixPath));
51 Source source = sdk.fromFileUri(uri); 51 Source source = sdk.fromFileUri(uri);
52 expect(source, isNotNull, reason: posixPath); 52 expect(source, isNotNull, reason: posixPath);
53 expect(source.uri.toString(), dartUri); 53 expect(source.uri.toString(), dartUri);
54 expect(source.fullName, posixToOSPath(posixPath)); 54 expect(source.fullName, posixToOSPath(posixPath));
55 } 55 }
56 56
57 expectSource('$foxLib/slippy.dart', 'dart:fox'); 57 expectSource('$foxLib/slippy.dart', 'dart:fox');
58 expectSource('$foxLib/deep/directory/file.dart', 'dart:deep'); 58 expectSource('$foxLib/deep/directory/file.dart', 'dart:deep');
59 expectSource('$foxLib/deep/directory/part.dart', 'dart:deep/part.dart'); 59 expectSource('$foxLib/deep/directory/part.dart', 'dart:deep/part.dart');
60 } 60 }
61 61
62 void test_getLinkedBundle_hasBundle() { 62 void test_getLinkedBundle_hasBundle() {
63 pathTranslator.newFileWithBytes( 63 pathTranslator.newFileWithBytes(
64 '$foxPath/sdk.ds', new PackageBundleAssembler().assemble().toBuffer()); 64 '$foxPath/sdk.ds', new PackageBundleAssembler().assemble().toBuffer());
65 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 65 EmbedderYamlLocator locator = new EmbedderYamlLocator({
66 'fox': [pathTranslator.getResource(foxLib)] 66 'fox': <Folder>[pathTranslator.getResource(foxLib)]
67 }); 67 });
68 // No bundle for spec mode. 68 // No bundle for spec mode.
69 { 69 {
70 EmbedderSdk sdk = 70 EmbedderSdk sdk =
71 new EmbedderSdk(resourceProvider, locator.embedderYamls); 71 new EmbedderSdk(resourceProvider, locator.embedderYamls);
72 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = false; 72 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = false;
73 expect(sdk.getLinkedBundle(), isNull); 73 expect(sdk.getLinkedBundle(), isNull);
74 } 74 }
75 // Has bundle for strong mode. 75 // Has bundle for strong mode.
76 { 76 {
77 EmbedderSdk sdk = 77 EmbedderSdk sdk =
78 new EmbedderSdk(resourceProvider, locator.embedderYamls); 78 new EmbedderSdk(resourceProvider, locator.embedderYamls);
79 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; 79 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true;
80 expect(sdk.getLinkedBundle(), isNotNull); 80 expect(sdk.getLinkedBundle(), isNotNull);
81 } 81 }
82 } 82 }
83 83
84 void test_getLinkedBundle_noBundle() { 84 void test_getLinkedBundle_noBundle() {
85 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 85 EmbedderYamlLocator locator = new EmbedderYamlLocator({
86 'fox': [pathTranslator.getResource(foxLib)] 86 'fox': <Folder>[pathTranslator.getResource(foxLib)]
87 }); 87 });
88 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); 88 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
89 expect(sdk.getLinkedBundle(), isNull); 89 expect(sdk.getLinkedBundle(), isNull);
90 } 90 }
91 91
92 void test_getSdkLibrary() { 92 void test_getSdkLibrary() {
93 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 93 EmbedderYamlLocator locator = new EmbedderYamlLocator({
94 'fox': [pathTranslator.getResource(foxLib)] 94 'fox': <Folder>[pathTranslator.getResource(foxLib)]
95 }); 95 });
96 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); 96 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
97 97
98 SdkLibrary lib = sdk.getSdkLibrary('dart:fox'); 98 SdkLibrary lib = sdk.getSdkLibrary('dart:fox');
99 expect(lib, isNotNull); 99 expect(lib, isNotNull);
100 expect(lib.path, posixToOSPath('$foxLib/slippy.dart')); 100 expect(lib.path, posixToOSPath('$foxLib/slippy.dart'));
101 expect(lib.shortName, 'dart:fox'); 101 expect(lib.shortName, 'dart:fox');
102 } 102 }
103 103
104 void test_mapDartUri() { 104 void test_mapDartUri() {
105 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 105 EmbedderYamlLocator locator = new EmbedderYamlLocator({
106 'fox': [pathTranslator.getResource(foxLib)] 106 'fox': <Folder>[pathTranslator.getResource(foxLib)]
107 }); 107 });
108 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); 108 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
109 109
110 void expectSource(String dartUri, String posixPath) { 110 void expectSource(String dartUri, String posixPath) {
111 Source source = sdk.mapDartUri(dartUri); 111 Source source = sdk.mapDartUri(dartUri);
112 expect(source, isNotNull, reason: posixPath); 112 expect(source, isNotNull, reason: posixPath);
113 expect(source.uri.toString(), dartUri); 113 expect(source.uri.toString(), dartUri);
114 expect(source.fullName, posixToOSPath(posixPath)); 114 expect(source.fullName, posixToOSPath(posixPath));
115 } 115 }
116 116
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 "dart:fox": "slippy.dart", 339 "dart:fox": "slippy.dart",
340 "dart:bear": "grizzly.dart", 340 "dart:bear": "grizzly.dart",
341 "dart:relative": "../relative.dart", 341 "dart:relative": "../relative.dart",
342 "dart:deep": "deep/directory/file.dart", 342 "dart:deep": "deep/directory/file.dart",
343 "fart:loudly": "nomatter.dart" 343 "fart:loudly": "nomatter.dart"
344 }'''); 344 }''');
345 } 345 }
346 346
347 test_create_noSdkExtPackageMap() { 347 test_create_noSdkExtPackageMap() {
348 var resolver = new SdkExtensionFinder({ 348 var resolver = new SdkExtensionFinder({
349 'fox': [resourceProvider.getResource('/empty')] 349 'fox': <Folder>[resourceProvider.getResource('/empty')]
350 }); 350 });
351 expect(resolver.urlMappings.length, equals(0)); 351 expect(resolver.urlMappings.length, equals(0));
352 } 352 }
353 353
354 test_create_nullPackageMap() { 354 test_create_nullPackageMap() {
355 var resolver = new SdkExtensionFinder(null); 355 var resolver = new SdkExtensionFinder(null);
356 expect(resolver.urlMappings.length, equals(0)); 356 expect(resolver.urlMappings.length, equals(0));
357 } 357 }
358 358
359 test_create_sdkExtPackageMap() { 359 test_create_sdkExtPackageMap() {
360 var resolver = new SdkExtensionFinder({ 360 var resolver = new SdkExtensionFinder({
361 'fox': [resourceProvider.getResource('/tmp')] 361 'fox': <Folder>[resourceProvider.getResource('/tmp')]
362 }); 362 });
363 // We have four mappings. 363 // We have four mappings.
364 Map<String, String> urlMappings = resolver.urlMappings; 364 Map<String, String> urlMappings = resolver.urlMappings;
365 expect(urlMappings.length, equals(4)); 365 expect(urlMappings.length, equals(4));
366 // Check that they map to the correct paths. 366 // Check that they map to the correct paths.
367 expect(urlMappings['dart:fox'], equals("/tmp/slippy.dart")); 367 expect(urlMappings['dart:fox'], equals("/tmp/slippy.dart"));
368 expect(urlMappings['dart:bear'], equals("/tmp/grizzly.dart")); 368 expect(urlMappings['dart:bear'], equals("/tmp/grizzly.dart"));
369 expect(urlMappings['dart:relative'], equals("/relative.dart")); 369 expect(urlMappings['dart:relative'], equals("/relative.dart"));
370 expect(urlMappings['dart:deep'], equals("/tmp/deep/directory/file.dart")); 370 expect(urlMappings['dart:deep'], equals("/tmp/deep/directory/file.dart"));
371 } 371 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 expect(second, isNotNull); 448 expect(second, isNotNull);
449 expect(second.category, "Server"); 449 expect(second.category, "Server");
450 expect(second.path, "second/second.dart"); 450 expect(second.path, "second/second.dart");
451 expect(second.shortName, "dart:second"); 451 expect(second.shortName, "dart:second");
452 expect(second.isDart2JsLibrary, false); 452 expect(second.isDart2JsLibrary, false);
453 expect(second.isDocumented, false); 453 expect(second.isDocumented, false);
454 expect(second.isImplementation, true); 454 expect(second.isImplementation, true);
455 expect(second.isVmLibrary, false); 455 expect(second.isVmLibrary, false);
456 } 456 }
457 } 457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698