OLD | NEW |
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.all_the_rest_test; | 5 library analyzer.test.generated.all_the_rest_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/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
(...skipping 3838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3849 } | 3849 } |
3850 } | 3850 } |
3851 | 3851 |
3852 /** | 3852 /** |
3853 * Tests for the [ExitDetector] that require that the AST be resolved. | 3853 * Tests for the [ExitDetector] that require that the AST be resolved. |
3854 * | 3854 * |
3855 * See [ExitDetectorTest] for tests that do not require the AST to be resolved. | 3855 * See [ExitDetectorTest] for tests that do not require the AST to be resolved. |
3856 */ | 3856 */ |
3857 @reflectiveTest | 3857 @reflectiveTest |
3858 class ExitDetectorTest2 extends ResolverTestCase { | 3858 class ExitDetectorTest2 extends ResolverTestCase { |
| 3859 void test_forStatement_implicitTrue_breakWithLabel() { |
| 3860 Source source = addSource(r''' |
| 3861 void f() { |
| 3862 x: for (;;) { |
| 3863 if (1 < 2) { |
| 3864 break x; |
| 3865 } |
| 3866 return; |
| 3867 } |
| 3868 } |
| 3869 '''); |
| 3870 _assertNthStatementDoesNotExit(source, 0); |
| 3871 } |
| 3872 |
3859 void test_switch_withEnum_false_noDefault() { | 3873 void test_switch_withEnum_false_noDefault() { |
3860 Source source = addSource(r''' | 3874 Source source = addSource(r''' |
3861 enum E { A, B } | 3875 enum E { A, B } |
3862 String f(E e) { | 3876 String f(E e) { |
3863 var x; | 3877 var x; |
3864 switch (e) { | 3878 switch (e) { |
3865 case A: | 3879 case A: |
3866 x = 'A'; | 3880 x = 'A'; |
3867 case B: | 3881 case B: |
3868 x = 'B'; | 3882 x = 'B'; |
3869 } | 3883 } |
3870 return x; | 3884 return x; |
3871 } | 3885 } |
3872 '''); | 3886 '''); |
3873 LibraryElement element = resolve2(source); | 3887 _assertNthStatementDoesNotExit(source, 1); |
3874 CompilationUnit unit = resolveCompilationUnit(source, element); | |
3875 FunctionDeclaration function = unit.declarations.last; | |
3876 BlockFunctionBody body = function.functionExpression.body; | |
3877 Statement statement = body.block.statements[1]; | |
3878 expect(ExitDetector.exits(statement), false); | |
3879 } | 3888 } |
3880 | 3889 |
3881 void test_switch_withEnum_false_withDefault() { | 3890 void test_switch_withEnum_false_withDefault() { |
3882 Source source = addSource(r''' | 3891 Source source = addSource(r''' |
3883 enum E { A, B } | 3892 enum E { A, B } |
3884 String f(E e) { | 3893 String f(E e) { |
3885 var x; | 3894 var x; |
3886 switch (e) { | 3895 switch (e) { |
3887 case A: | 3896 case A: |
3888 x = 'A'; | 3897 x = 'A'; |
3889 default: | 3898 default: |
3890 x = '?'; | 3899 x = '?'; |
3891 } | 3900 } |
3892 return x; | 3901 return x; |
3893 } | 3902 } |
3894 '''); | 3903 '''); |
3895 LibraryElement element = resolve2(source); | 3904 _assertNthStatementDoesNotExit(source, 1); |
3896 CompilationUnit unit = resolveCompilationUnit(source, element); | |
3897 FunctionDeclaration function = unit.declarations.last; | |
3898 BlockFunctionBody body = function.functionExpression.body; | |
3899 Statement statement = body.block.statements[1]; | |
3900 expect(ExitDetector.exits(statement), false); | |
3901 } | 3905 } |
3902 | 3906 |
3903 void test_switch_withEnum_true_noDefault() { | 3907 void test_switch_withEnum_true_noDefault() { |
3904 Source source = addSource(r''' | 3908 Source source = addSource(r''' |
3905 enum E { A, B } | 3909 enum E { A, B } |
3906 String f(E e) { | 3910 String f(E e) { |
3907 switch (e) { | 3911 switch (e) { |
3908 case A: | 3912 case A: |
3909 return 'A'; | 3913 return 'A'; |
3910 case B: | 3914 case B: |
3911 return 'B'; | 3915 return 'B'; |
3912 } | 3916 } |
3913 } | 3917 } |
3914 '''); | 3918 '''); |
3915 LibraryElement element = resolve2(source); | 3919 _assertNthStatementExits(source, 0); |
3916 CompilationUnit unit = resolveCompilationUnit(source, element); | |
3917 FunctionDeclaration function = unit.declarations.last; | |
3918 BlockFunctionBody body = function.functionExpression.body; | |
3919 Statement statement = body.block.statements[0]; | |
3920 expect(ExitDetector.exits(statement), true); | |
3921 } | 3920 } |
3922 | 3921 |
3923 void test_switch_withEnum_true_withDefault() { | 3922 void test_switch_withEnum_true_withDefault() { |
3924 Source source = addSource(r''' | 3923 Source source = addSource(r''' |
3925 enum E { A, B } | 3924 enum E { A, B } |
3926 String f(E e) { | 3925 String f(E e) { |
3927 switch (e) { | 3926 switch (e) { |
3928 case A: | 3927 case A: |
3929 return 'A'; | 3928 return 'A'; |
3930 default: | 3929 default: |
3931 return '?'; | 3930 return '?'; |
3932 } | 3931 } |
3933 } | 3932 } |
3934 '''); | 3933 '''); |
| 3934 _assertNthStatementExits(source, 0); |
| 3935 } |
| 3936 |
| 3937 void test_whileStatement_breakWithLabel() { |
| 3938 Source source = addSource(r''' |
| 3939 void f() { |
| 3940 x: while (true) { |
| 3941 if (1 < 2) { |
| 3942 break x; |
| 3943 } |
| 3944 return; |
| 3945 } |
| 3946 } |
| 3947 '''); |
| 3948 _assertNthStatementDoesNotExit(source, 0); |
| 3949 } |
| 3950 |
| 3951 void test_whileStatement_breakWithLabel_afterExting() { |
| 3952 Source source = addSource(r''' |
| 3953 void f() { |
| 3954 x: while (true) { |
| 3955 return; |
| 3956 if (1 < 2) { |
| 3957 break x; |
| 3958 } |
| 3959 } |
| 3960 } |
| 3961 '''); |
| 3962 _assertNthStatementExits(source, 0); |
| 3963 } |
| 3964 |
| 3965 void _assertHasReturn(bool expectedResult, String source, int n) { |
3935 LibraryElement element = resolve2(source); | 3966 LibraryElement element = resolve2(source); |
3936 CompilationUnit unit = resolveCompilationUnit(source, element); | 3967 CompilationUnit unit = resolveCompilationUnit(source, element); |
3937 FunctionDeclaration function = unit.declarations.last; | 3968 FunctionDeclaration function = unit.declarations.last; |
3938 BlockFunctionBody body = function.functionExpression.body; | 3969 BlockFunctionBody body = function.functionExpression.body; |
3939 Statement statement = body.block.statements[0]; | 3970 Statement statement = body.block.statements[n]; |
3940 expect(ExitDetector.exits(statement), true); | 3971 expect(ExitDetector.exits(statement), expectedResult); |
| 3972 } |
| 3973 |
| 3974 // Assert that the [n]th statement in the last function declaration of |
| 3975 // [source] exits. |
| 3976 void _assertNthStatementExits(String source, int n) { |
| 3977 _assertHasReturn(true, source, n); |
| 3978 } |
| 3979 |
| 3980 // Assert that the [n]th statement in the last function declaration of |
| 3981 // [source] does not exit. |
| 3982 void _assertNthStatementDoesNotExit(String source, int n) { |
| 3983 _assertHasReturn(false, source, n); |
3941 } | 3984 } |
3942 } | 3985 } |
3943 | 3986 |
3944 @reflectiveTest | 3987 @reflectiveTest |
3945 class FileBasedSourceTest { | 3988 class FileBasedSourceTest { |
3946 void test_equals_false_differentFiles() { | 3989 void test_equals_false_differentFiles() { |
3947 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); | 3990 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); |
3948 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); | 3991 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); |
3949 FileBasedSource source1 = new FileBasedSource(file1); | 3992 FileBasedSource source1 = new FileBasedSource(file1); |
3950 FileBasedSource source2 = new FileBasedSource(file2); | 3993 FileBasedSource source2 = new FileBasedSource(file2); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4312 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 4355 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
4313 expect(UriKind.fromEncoding(0x58), same(null)); | 4356 expect(UriKind.fromEncoding(0x58), same(null)); |
4314 } | 4357 } |
4315 | 4358 |
4316 void test_getEncoding() { | 4359 void test_getEncoding() { |
4317 expect(UriKind.DART_URI.encoding, 0x64); | 4360 expect(UriKind.DART_URI.encoding, 0x64); |
4318 expect(UriKind.FILE_URI.encoding, 0x66); | 4361 expect(UriKind.FILE_URI.encoding, 0x66); |
4319 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 4362 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
4320 } | 4363 } |
4321 } | 4364 } |
OLD | NEW |