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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 829133007: Enable enum and deferred import support (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 * Instances of the class `AnalysisContextForTests` implement an analysis contex t that has a 371 * Instances of the class `AnalysisContextForTests` implement an analysis contex t that has a
372 * fake SDK that is much smaller and faster for testing purposes. 372 * fake SDK that is much smaller and faster for testing purposes.
373 */ 373 */
374 class AnalysisContextForTests extends AnalysisContextImpl { 374 class AnalysisContextForTests extends AnalysisContextImpl {
375 @override 375 @override
376 void set analysisOptions(AnalysisOptions options) { 376 void set analysisOptions(AnalysisOptions options) {
377 AnalysisOptions currentOptions = analysisOptions; 377 AnalysisOptions currentOptions = analysisOptions;
378 bool needsRecompute = 378 bool needsRecompute =
379 currentOptions.analyzeFunctionBodies != options.analyzeFunctionBodies || 379 currentOptions.analyzeFunctionBodies != options.analyzeFunctionBodies ||
380 currentOptions.generateSdkErrors != options.generateSdkErrors || 380 currentOptions.generateSdkErrors != options.generateSdkErrors ||
381 currentOptions.enableDeferredLoading != options.enableDeferredLoading ||
382 currentOptions.enableEnum != options.enableEnum ||
383 currentOptions.dart2jsHint != options.dart2jsHint || 381 currentOptions.dart2jsHint != options.dart2jsHint ||
384 (currentOptions.hint && !options.hint) || 382 (currentOptions.hint && !options.hint) ||
385 currentOptions.preserveComments != options.preserveComments; 383 currentOptions.preserveComments != options.preserveComments;
386 if (needsRecompute) { 384 if (needsRecompute) {
387 fail( 385 fail(
388 "Cannot set options that cause the sources to be reanalyzed in a test context"); 386 "Cannot set options that cause the sources to be reanalyzed in a test context");
389 } 387 }
390 super.analysisOptions = options; 388 super.analysisOptions = options;
391 } 389 }
392 390
(...skipping 2578 matching lines...) Expand 10 before | Expand all | Expand 10 after
2971 addNamedSource("/lib1.dart", r''' 2969 addNamedSource("/lib1.dart", r'''
2972 library lib1; 2970 library lib1;
2973 class A {} 2971 class A {}
2974 class B {}'''); 2972 class B {}''');
2975 resolve(source); 2973 resolve(source);
2976 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); 2974 assertErrors(source, [HintCode.DUPLICATE_IMPORT]);
2977 verify([source]); 2975 verify([source]);
2978 } 2976 }
2979 2977
2980 void test_importDeferredLibraryWithLoadFunction() { 2978 void test_importDeferredLibraryWithLoadFunction() {
2981 resolveWithAndWithoutExperimental(<String>[r''' 2979 resolveWithErrors(<String>[r'''
2982 library lib1; 2980 library lib1;
2983 loadLibrary() {} 2981 loadLibrary() {}
2984 f() {}''', r''' 2982 f() {}''', r'''
2985 library root; 2983 library root;
2986 import 'lib1.dart' deferred as lib1; 2984 import 'lib1.dart' deferred as lib1;
2987 main() { lib1.f(); }'''], 2985 main() { lib1.f(); }'''],
2988 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED],
2989 <ErrorCode>[HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]); 2986 <ErrorCode>[HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]);
2990 } 2987 }
2991 2988
2992 void test_invalidAssignment_instanceVariable() { 2989 void test_invalidAssignment_instanceVariable() {
2993 Source source = addSource(r''' 2990 Source source = addSource(r'''
2994 class A { 2991 class A {
2995 int x; 2992 int x;
2996 } 2993 }
2997 f(var y) { 2994 f(var y) {
2998 A a; 2995 A a;
(...skipping 3542 matching lines...) Expand 10 before | Expand all | Expand 10 after
6541 addNamedSource("/lib1.dart", r''' 6538 addNamedSource("/lib1.dart", r'''
6542 library lib1; 6539 library lib1;
6543 class A {} 6540 class A {}
6544 class B {}'''); 6541 class B {}''');
6545 resolve(source); 6542 resolve(source);
6546 assertNoErrors(source); 6543 assertNoErrors(source);
6547 verify([source]); 6544 verify([source]);
6548 } 6545 }
6549 6546
6550 void test_importDeferredLibraryWithLoadFunction() { 6547 void test_importDeferredLibraryWithLoadFunction() {
6551 resolveWithAndWithoutExperimental(<String>[r''' 6548 resolveWithErrors(<String>[r'''
6552 library lib1; 6549 library lib1;
6553 f() {}''', r''' 6550 f() {}''', r'''
6554 library root; 6551 library root;
6555 import 'lib1.dart' deferred as lib1; 6552 import 'lib1.dart' deferred as lib1;
6556 main() { lib1.f(); }'''], 6553 main() { lib1.f(); }'''],
6557 <ErrorCode>[ParserErrorCode.DEFERRED_IMPORTS_NOT_SUPPORTED],
6558 ErrorCode.EMPTY_LIST); 6554 ErrorCode.EMPTY_LIST);
6559 } 6555 }
6560 6556
6561 void test_issue20904BuggyTypePromotionAtIfJoin_1() { 6557 void test_issue20904BuggyTypePromotionAtIfJoin_1() {
6562 // https://code.google.com/p/dart/issues/detail?id=20904 6558 // https://code.google.com/p/dart/issues/detail?id=20904
6563 Source source = addSource(r''' 6559 Source source = addSource(r'''
6564 f(var message, var dynamic_) { 6560 f(var message, var dynamic_) {
6565 if (message is Function) { 6561 if (message is Function) {
6566 message = dynamic_; 6562 message = dynamic_;
6567 } 6563 }
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
7822 */ 7818 */
7823 void reset() { 7819 void reset() {
7824 analysisContext2 = AnalysisContextFactory.contextWithCore(); 7820 analysisContext2 = AnalysisContextFactory.contextWithCore();
7825 // These defaults are duplicated for the editor in 7821 // These defaults are duplicated for the editor in
7826 // editor/tools/plugins/com.google.dart.tools.core/.options . 7822 // editor/tools/plugins/com.google.dart.tools.core/.options .
7827 AnalysisEngine.instance.enableUnionTypes = false; 7823 AnalysisEngine.instance.enableUnionTypes = false;
7828 AnalysisEngine.instance.strictUnionTypes = false; 7824 AnalysisEngine.instance.strictUnionTypes = false;
7829 } 7825 }
7830 7826
7831 /** 7827 /**
7832 * Reset the analysis context to have the 'enableEnum' option set to true.
7833 */
7834 void resetWithEnum() {
7835 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl();
7836 analysisOptions.enableEnum = true;
7837 resetWithOptions(analysisOptions);
7838 }
7839
7840 /**
7841 * Reset the analysis context to have the given options applied. 7828 * Reset the analysis context to have the given options applied.
7842 * 7829 *
7843 * @param options the analysis options to be applied to the context 7830 * @param options the analysis options to be applied to the context
7844 */ 7831 */
7845 void resetWithOptions(AnalysisOptions options) { 7832 void resetWithOptions(AnalysisOptions options) {
7846 analysisContext2 = 7833 analysisContext2 =
7847 AnalysisContextFactory.contextWithCoreAndOptions(options); 7834 AnalysisContextFactory.contextWithCoreAndOptions(options);
7848 } 7835 }
7849 7836
7850 /** 7837 /**
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
7885 CompilationUnit unit = 7872 CompilationUnit unit =
7886 resolveSource2("/lib${i + 1}.dart", sourceTexts[i]); 7873 resolveSource2("/lib${i + 1}.dart", sourceTexts[i]);
7887 // reference the source if this is the last source 7874 // reference the source if this is the last source
7888 if (i + 1 == sourceTexts.length) { 7875 if (i + 1 == sourceTexts.length) {
7889 return unit.element.source; 7876 return unit.element.source;
7890 } 7877 }
7891 } 7878 }
7892 return null; 7879 return null;
7893 } 7880 }
7894 7881
7882 void resolveWithErrors(List<String> strSources, List<ErrorCode> codes) {
7883 // Analysis and assertions
7884 Source source = resolveSources(strSources);
7885 assertErrors(source, codes);
7886 verify([source]);
7887 }
7888
7895 void resolveWithAndWithoutExperimental(List<String> strSources, 7889 void resolveWithAndWithoutExperimental(List<String> strSources,
7896 List<ErrorCode> codesWithoutExperimental, 7890 List<ErrorCode> codesWithoutExperimental,
7897 List<ErrorCode> codesWithExperimental) { 7891 List<ErrorCode> codesWithExperimental) {
7898 // Setup analysis context as non-experimental 7892 // Setup analysis context as non-experimental
7899 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 7893 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
7900 options.enableDeferredLoading = false; 7894 // options.enableDeferredLoading = false;
7901 resetWithOptions(options); 7895 resetWithOptions(options);
7902 // Analysis and assertions 7896 // Analysis and assertions
7903 Source source = resolveSources(strSources); 7897 Source source = resolveSources(strSources);
7904 assertErrors(source, codesWithoutExperimental); 7898 assertErrors(source, codesWithoutExperimental);
7905 verify([source]); 7899 verify([source]);
7906 // Setup analysis context as experimental 7900 // Setup analysis context as experimental
7907 reset(); 7901 reset();
7908 // Analysis and assertions 7902 // Analysis and assertions
7909 source = resolveSources(strSources); 7903 source = resolveSources(strSources);
7910 assertErrors(source, codesWithExperimental); 7904 assertErrors(source, codesWithExperimental);
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
8655 void test_entryPoint_none() { 8649 void test_entryPoint_none() {
8656 Source source = addNamedSource("/one.dart", "library one;"); 8650 Source source = addNamedSource("/one.dart", "library one;");
8657 LibraryElement library = resolve(source); 8651 LibraryElement library = resolve(source);
8658 expect(library, isNotNull); 8652 expect(library, isNotNull);
8659 expect(library.entryPoint, isNull); 8653 expect(library.entryPoint, isNull);
8660 assertNoErrors(source); 8654 assertNoErrors(source);
8661 verify([source]); 8655 verify([source]);
8662 } 8656 }
8663 8657
8664 void test_enum_externalLibrary() { 8658 void test_enum_externalLibrary() {
8665 resetWithEnum();
8666 addNamedSource("/my_lib.dart", r''' 8659 addNamedSource("/my_lib.dart", r'''
8667 library my_lib; 8660 library my_lib;
8668 enum EEE {A, B, C}'''); 8661 enum EEE {A, B, C}''');
8669 Source source = addSource(r''' 8662 Source source = addSource(r'''
8670 import 'my_lib.dart'; 8663 import 'my_lib.dart';
8671 main() { 8664 main() {
8672 EEE e = null; 8665 EEE e = null;
8673 }'''); 8666 }''');
8674 resolve(source); 8667 resolve(source);
8675 assertNoErrors(source); 8668 assertNoErrors(source);
(...skipping 5142 matching lines...) Expand 10 before | Expand all | Expand 10 after
13818 // check propagated type 13811 // check propagated type
13819 FunctionType propagatedType = node.propagatedType as FunctionType; 13812 FunctionType propagatedType = node.propagatedType as FunctionType;
13820 expect(propagatedType.returnType, test.typeProvider.stringType); 13813 expect(propagatedType.returnType, test.typeProvider.stringType);
13821 } on AnalysisException catch (e, stackTrace) { 13814 } on AnalysisException catch (e, stackTrace) {
13822 thrownException[0] = new CaughtException(e, stackTrace); 13815 thrownException[0] = new CaughtException(e, stackTrace);
13823 } 13816 }
13824 } 13817 }
13825 return null; 13818 return null;
13826 } 13819 }
13827 } 13820 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | pkg/analyzer/test/generated/static_warning_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698