| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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.simple_resolver_test; | 5 library analyzer.test.generated.simple_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 557 } |
| 558 | 558 |
| 559 test_empty() async { | 559 test_empty() async { |
| 560 Source source = addSource(""); | 560 Source source = addSource(""); |
| 561 await computeAnalysisResult(source); | 561 await computeAnalysisResult(source); |
| 562 assertNoErrors(source); | 562 assertNoErrors(source); |
| 563 verify([source]); | 563 verify([source]); |
| 564 } | 564 } |
| 565 | 565 |
| 566 test_entryPoint_exported() async { | 566 test_entryPoint_exported() async { |
| 567 addNamedSource( | 567 addNamedSource("/two.dart", r''' |
| 568 "/two.dart", | |
| 569 r''' | |
| 570 library two; | 568 library two; |
| 571 main() {}'''); | 569 main() {}'''); |
| 572 Source source = addNamedSource( | 570 Source source = addNamedSource("/one.dart", r''' |
| 573 "/one.dart", | |
| 574 r''' | |
| 575 library one; | 571 library one; |
| 576 export 'two.dart';'''); | 572 export 'two.dart';'''); |
| 577 LibraryElement library = resolve2(source); | 573 LibraryElement library = resolve2(source); |
| 578 expect(library, isNotNull); | 574 expect(library, isNotNull); |
| 579 FunctionElement main = library.entryPoint; | 575 FunctionElement main = library.entryPoint; |
| 580 expect(main, isNotNull); | 576 expect(main, isNotNull); |
| 581 expect(main.library, isNot(same(library))); | 577 expect(main.library, isNot(same(library))); |
| 582 await computeAnalysisResult(source); | 578 await computeAnalysisResult(source); |
| 583 assertNoErrors(source); | 579 assertNoErrors(source); |
| 584 verify([source]); | 580 verify([source]); |
| 585 } | 581 } |
| 586 | 582 |
| 587 test_entryPoint_local() async { | 583 test_entryPoint_local() async { |
| 588 Source source = addNamedSource( | 584 Source source = addNamedSource("/one.dart", r''' |
| 589 "/one.dart", | |
| 590 r''' | |
| 591 library one; | 585 library one; |
| 592 main() {}'''); | 586 main() {}'''); |
| 593 LibraryElement library = resolve2(source); | 587 LibraryElement library = resolve2(source); |
| 594 expect(library, isNotNull); | 588 expect(library, isNotNull); |
| 595 FunctionElement main = library.entryPoint; | 589 FunctionElement main = library.entryPoint; |
| 596 expect(main, isNotNull); | 590 expect(main, isNotNull); |
| 597 expect(main.library, same(library)); | 591 expect(main.library, same(library)); |
| 598 await computeAnalysisResult(source); | 592 await computeAnalysisResult(source); |
| 599 assertNoErrors(source); | 593 assertNoErrors(source); |
| 600 verify([source]); | 594 verify([source]); |
| 601 } | 595 } |
| 602 | 596 |
| 603 test_entryPoint_none() async { | 597 test_entryPoint_none() async { |
| 604 Source source = addNamedSource("/one.dart", "library one;"); | 598 Source source = addNamedSource("/one.dart", "library one;"); |
| 605 LibraryElement library = resolve2(source); | 599 LibraryElement library = resolve2(source); |
| 606 expect(library, isNotNull); | 600 expect(library, isNotNull); |
| 607 expect(library.entryPoint, isNull); | 601 expect(library.entryPoint, isNull); |
| 608 await computeAnalysisResult(source); | 602 await computeAnalysisResult(source); |
| 609 assertNoErrors(source); | 603 assertNoErrors(source); |
| 610 verify([source]); | 604 verify([source]); |
| 611 } | 605 } |
| 612 | 606 |
| 613 test_enum_externalLibrary() async { | 607 test_enum_externalLibrary() async { |
| 614 addNamedSource( | 608 addNamedSource("/my_lib.dart", r''' |
| 615 "/my_lib.dart", | |
| 616 r''' | |
| 617 library my_lib; | 609 library my_lib; |
| 618 enum EEE {A, B, C}'''); | 610 enum EEE {A, B, C}'''); |
| 619 Source source = addSource(r''' | 611 Source source = addSource(r''' |
| 620 import 'my_lib.dart'; | 612 import 'my_lib.dart'; |
| 621 main() { | 613 main() { |
| 622 EEE e = null; | 614 EEE e = null; |
| 623 }'''); | 615 }'''); |
| 624 await computeAnalysisResult(source); | 616 await computeAnalysisResult(source); |
| 625 assertNoErrors(source); | 617 assertNoErrors(source); |
| 626 verify([source]); | 618 verify([source]); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 List<ClassElement> classes = unit.types; | 862 List<ClassElement> classes = unit.types; |
| 871 expect(classes, hasLength(2)); | 863 expect(classes, hasLength(2)); |
| 872 expect(classes[0].hasReferenceToSuper, isFalse); | 864 expect(classes[0].hasReferenceToSuper, isFalse); |
| 873 expect(classes[1].hasReferenceToSuper, isTrue); | 865 expect(classes[1].hasReferenceToSuper, isTrue); |
| 874 await computeAnalysisResult(source); | 866 await computeAnalysisResult(source); |
| 875 assertNoErrors(source); | 867 assertNoErrors(source); |
| 876 verify([source]); | 868 verify([source]); |
| 877 } | 869 } |
| 878 | 870 |
| 879 test_import_hide() async { | 871 test_import_hide() async { |
| 880 addNamedSource( | 872 addNamedSource("/lib1.dart", r''' |
| 881 "/lib1.dart", | |
| 882 r''' | |
| 883 library lib1; | 873 library lib1; |
| 884 set foo(value) {} | 874 set foo(value) {} |
| 885 class A {}'''); | 875 class A {}'''); |
| 886 addNamedSource( | 876 addNamedSource("/lib2.dart", r''' |
| 887 "/lib2.dart", | |
| 888 r''' | |
| 889 library lib2; | 877 library lib2; |
| 890 set foo(value) {}'''); | 878 set foo(value) {}'''); |
| 891 Source source = addNamedSource( | 879 Source source = addNamedSource("/lib3.dart", r''' |
| 892 "/lib3.dart", | |
| 893 r''' | |
| 894 import 'lib1.dart' hide foo; | 880 import 'lib1.dart' hide foo; |
| 895 import 'lib2.dart'; | 881 import 'lib2.dart'; |
| 896 | 882 |
| 897 main() { | 883 main() { |
| 898 foo = 0; | 884 foo = 0; |
| 899 } | 885 } |
| 900 A a;'''); | 886 A a;'''); |
| 901 await computeAnalysisResult(source); | 887 await computeAnalysisResult(source); |
| 902 assertNoErrors(source); | 888 assertNoErrors(source); |
| 903 verify([source]); | 889 verify([source]); |
| 904 } | 890 } |
| 905 | 891 |
| 906 test_import_prefix() async { | 892 test_import_prefix() async { |
| 907 addNamedSource( | 893 addNamedSource("/two.dart", r''' |
| 908 "/two.dart", | |
| 909 r''' | |
| 910 library two; | 894 library two; |
| 911 f(int x) { | 895 f(int x) { |
| 912 return x * x; | 896 return x * x; |
| 913 }'''); | 897 }'''); |
| 914 Source source = addNamedSource( | 898 Source source = addNamedSource("/one.dart", r''' |
| 915 "/one.dart", | |
| 916 r''' | |
| 917 library one; | 899 library one; |
| 918 import 'two.dart' as _two; | 900 import 'two.dart' as _two; |
| 919 main() { | 901 main() { |
| 920 _two.f(0); | 902 _two.f(0); |
| 921 }'''); | 903 }'''); |
| 922 await computeAnalysisResult(source); | 904 await computeAnalysisResult(source); |
| 923 assertNoErrors(source); | 905 assertNoErrors(source); |
| 924 verify([source]); | 906 verify([source]); |
| 925 } | 907 } |
| 926 | 908 |
| 927 test_import_prefix_doesNotExist() async { | 909 test_import_prefix_doesNotExist() async { |
| 928 // | 910 // |
| 929 // The primary purpose of this test is to ensure that we are only getting a | 911 // The primary purpose of this test is to ensure that we are only getting a |
| 930 // single error generated when the only problem is that an imported file | 912 // single error generated when the only problem is that an imported file |
| 931 // does not exist. | 913 // does not exist. |
| 932 // | 914 // |
| 933 Source source = addNamedSource( | 915 Source source = addNamedSource("/a.dart", r''' |
| 934 "/a.dart", | |
| 935 r''' | |
| 936 import 'missing.dart' as p; | 916 import 'missing.dart' as p; |
| 937 int a = p.q + p.r.s; | 917 int a = p.q + p.r.s; |
| 938 String b = p.t(a) + p.u(v: 0); | 918 String b = p.t(a) + p.u(v: 0); |
| 939 p.T c = new p.T(); | 919 p.T c = new p.T(); |
| 940 class D<E> extends p.T { | 920 class D<E> extends p.T { |
| 941 D(int i) : super(i); | 921 D(int i) : super(i); |
| 942 p.U f = new p.V(); | 922 p.U f = new p.V(); |
| 943 } | 923 } |
| 944 class F implements p.T { | 924 class F implements p.T { |
| 945 p.T m(p.U u) => null; | 925 p.T m(p.U u) => null; |
| 946 } | 926 } |
| 947 class G extends Object with p.V {} | 927 class G extends Object with p.V {} |
| 948 class H extends D<p.W> { | 928 class H extends D<p.W> { |
| 949 H(int i) : super(i); | 929 H(int i) : super(i); |
| 950 } | 930 } |
| 951 '''); | 931 '''); |
| 952 await computeAnalysisResult(source); | 932 await computeAnalysisResult(source); |
| 953 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 933 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 954 verify([source]); | 934 verify([source]); |
| 955 } | 935 } |
| 956 | 936 |
| 957 test_import_show_doesNotExist() async { | 937 test_import_show_doesNotExist() async { |
| 958 // | 938 // |
| 959 // The primary purpose of this test is to ensure that we are only getting a | 939 // The primary purpose of this test is to ensure that we are only getting a |
| 960 // single error generated when the only problem is that an imported file | 940 // single error generated when the only problem is that an imported file |
| 961 // does not exist. | 941 // does not exist. |
| 962 // | 942 // |
| 963 Source source = addNamedSource( | 943 Source source = addNamedSource("/a.dart", r''' |
| 964 "/a.dart", | |
| 965 r''' | |
| 966 import 'missing.dart' show q, r, t, u, T, U, V, W; | 944 import 'missing.dart' show q, r, t, u, T, U, V, W; |
| 967 int a = q + r.s; | 945 int a = q + r.s; |
| 968 String b = t(a) + u(v: 0); | 946 String b = t(a) + u(v: 0); |
| 969 T c = new T(); | 947 T c = new T(); |
| 970 class D<E> extends T { | 948 class D<E> extends T { |
| 971 D(int i) : super(i); | 949 D(int i) : super(i); |
| 972 U f = new V(); | 950 U f = new V(); |
| 973 } | 951 } |
| 974 class F implements T { | 952 class F implements T { |
| 975 T m(U u) => null; | 953 T m(U u) => null; |
| 976 } | 954 } |
| 977 class G extends Object with V {} | 955 class G extends Object with V {} |
| 978 class H extends D<W> { | 956 class H extends D<W> { |
| 979 H(int i) : super(i); | 957 H(int i) : super(i); |
| 980 } | 958 } |
| 981 '''); | 959 '''); |
| 982 await computeAnalysisResult(source); | 960 await computeAnalysisResult(source); |
| 983 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 961 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 984 verify([source]); | 962 verify([source]); |
| 985 } | 963 } |
| 986 | 964 |
| 987 test_import_spaceInUri() async { | 965 test_import_spaceInUri() async { |
| 988 addNamedSource( | 966 addNamedSource("/sub folder/lib.dart", r''' |
| 989 "/sub folder/lib.dart", | |
| 990 r''' | |
| 991 library lib; | 967 library lib; |
| 992 foo() {}'''); | 968 foo() {}'''); |
| 993 Source source = addNamedSource( | 969 Source source = addNamedSource("/app.dart", r''' |
| 994 "/app.dart", | |
| 995 r''' | |
| 996 import 'sub folder/lib.dart'; | 970 import 'sub folder/lib.dart'; |
| 997 | 971 |
| 998 main() { | 972 main() { |
| 999 foo(); | 973 foo(); |
| 1000 }'''); | 974 }'''); |
| 1001 await computeAnalysisResult(source); | 975 await computeAnalysisResult(source); |
| 1002 assertNoErrors(source); | 976 assertNoErrors(source); |
| 1003 verify([source]); | 977 verify([source]); |
| 1004 } | 978 } |
| 1005 | 979 |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1868 // check propagated type | 1842 // check propagated type |
| 1869 FunctionType propagatedType = node.propagatedType as FunctionType; | 1843 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 1870 expect(propagatedType.returnType, test.typeProvider.stringType); | 1844 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 1871 } on AnalysisException catch (e, stackTrace) { | 1845 } on AnalysisException catch (e, stackTrace) { |
| 1872 thrownException[0] = new CaughtException(e, stackTrace); | 1846 thrownException[0] = new CaughtException(e, stackTrace); |
| 1873 } | 1847 } |
| 1874 } | 1848 } |
| 1875 return null; | 1849 return null; |
| 1876 } | 1850 } |
| 1877 } | 1851 } |
| OLD | NEW |