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 3461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3472 } | 3472 } |
3473 | 3473 |
3474 void test_conditionalCall_rhs2() { | 3474 void test_conditionalCall_rhs2() { |
3475 _assertFalse("null?.b(throw '');"); | 3475 _assertFalse("null?.b(throw '');"); |
3476 } | 3476 } |
3477 | 3477 |
3478 void test_creation() { | 3478 void test_creation() { |
3479 expect(new ExitDetector(), isNotNull); | 3479 expect(new ExitDetector(), isNotNull); |
3480 } | 3480 } |
3481 | 3481 |
3482 void test_doStatement_return() { | |
3483 _assertTrue("{ do { return null; } while (1 == 2); }"); | |
3484 } | |
3485 | |
3482 void test_doStatement_throwCondition() { | 3486 void test_doStatement_throwCondition() { |
3483 _assertTrue("{ do {} while (throw ''); }"); | 3487 _assertTrue("{ do {} while (throw ''); }"); |
3484 } | 3488 } |
3485 | 3489 |
3486 void test_doStatement_return() { | |
3487 _assertTrue("{ do { return null; } while (1 == 2); }"); | |
3488 } | |
3489 | |
3490 void test_doStatement_true_break() { | 3490 void test_doStatement_true_break() { |
3491 _assertFalse("{ do { break; } while (true); }"); | 3491 _assertFalse("{ do { break; } while (true); }"); |
3492 } | 3492 } |
3493 | 3493 |
3494 void test_doStatement_true_continue() { | 3494 void test_doStatement_true_continue() { |
3495 _assertTrue("{ do { continue; } while (true); }"); | 3495 _assertTrue("{ do { continue; } while (true); }"); |
3496 } | 3496 } |
3497 | 3497 |
3498 void test_doStatement_true_if_return() { | 3498 void test_doStatement_true_if_return() { |
3499 _assertTrue("{ do { if (true) {return null;} } while (true); }"); | 3499 _assertTrue("{ do { if (true) {return null;} } while (true); }"); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3780 } | 3780 } |
3781 | 3781 |
3782 void test_tryStatement_return_catch() { | 3782 void test_tryStatement_return_catch() { |
3783 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); | 3783 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); |
3784 } | 3784 } |
3785 | 3785 |
3786 void test_tryStatement_return_finally() { | 3786 void test_tryStatement_return_finally() { |
3787 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); | 3787 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); |
3788 } | 3788 } |
3789 | 3789 |
3790 void test_tryStatement_return_try() { | 3790 void test_tryStatement_return_try_noCatch() { |
Brian Wilkerson
2016/06/11 00:13:39
Strangely enough, all of the tests use a try state
Paul Berry
2016/06/11 13:02:15
Done.
| |
3791 _assertTrue("try { return 1; } catch (e, s) {} finally {}"); | 3791 _assertTrue("try { return 1; } finally {}"); |
3792 } | |
3793 | |
3794 void test_tryStatement_return_try_oneCatchDoesNotExit() { | |
3795 _assertFalse("try { return 1; } catch (e, s) {} finally {}"); | |
3796 } | |
3797 | |
3798 void test_tryStatement_return_try_oneCatchExits() { | |
3799 _assertTrue("try { return 1; } catch (e, s) { return 1; } finally {}"); | |
3800 } | |
3801 | |
3802 void test_tryStatement_return_try_twoCatchesDoExit() { | |
3803 _assertTrue(''' | |
3804 try { return 1; } | |
3805 on int catch (e, s) { return 1; } | |
3806 on String catch (e, s) { return 1; } | |
3807 finally {}'''); | |
3808 } | |
3809 | |
3810 void test_tryStatement_return_try_twoCatchesDoNotExit() { | |
3811 _assertFalse(''' | |
3812 try { return 1; } | |
3813 on int catch (e, s) {} | |
3814 on String catch (e, s) {} | |
3815 finally {}'''); | |
3816 } | |
3817 | |
3818 void test_tryStatement_return_try_twoCatchesMixed() { | |
3819 _assertFalse(''' | |
3820 try { return 1; } | |
3821 on int catch (e, s) {} | |
3822 on String catch (e, s) { return 1; } | |
3823 finally {}'''); | |
3792 } | 3824 } |
3793 | 3825 |
3794 void test_variableDeclarationStatement_noInitializer() { | 3826 void test_variableDeclarationStatement_noInitializer() { |
3795 _assertFalse("int i;"); | 3827 _assertFalse("int i;"); |
3796 } | 3828 } |
3797 | 3829 |
3798 void test_variableDeclarationStatement_noThrow() { | 3830 void test_variableDeclarationStatement_noThrow() { |
3799 _assertFalse("int i = 0;"); | 3831 _assertFalse("int i = 0;"); |
3800 } | 3832 } |
3801 | 3833 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3980 | 4012 |
3981 void test_yieldStatement_plain() { | 4013 void test_yieldStatement_plain() { |
3982 Source source = addSource(r''' | 4014 Source source = addSource(r''' |
3983 void f() sync* { | 4015 void f() sync* { |
3984 yield 1; | 4016 yield 1; |
3985 } | 4017 } |
3986 '''); | 4018 '''); |
3987 _assertNthStatementDoesNotExit(source, 0); | 4019 _assertNthStatementDoesNotExit(source, 0); |
3988 } | 4020 } |
3989 | 4021 |
3990 void test_yieldStatement_throw() { | |
3991 Source source = addSource(r''' | |
3992 void f() sync* { | |
3993 yield throw ''; | |
3994 } | |
3995 '''); | |
3996 _assertNthStatementExits(source, 0); | |
3997 } | |
3998 | |
3999 void test_yieldStatement_star_plain() { | 4022 void test_yieldStatement_star_plain() { |
4000 Source source = addSource(r''' | 4023 Source source = addSource(r''' |
4001 void f() sync* { | 4024 void f() sync* { |
4002 yield* 1; | 4025 yield* 1; |
4003 } | 4026 } |
4004 '''); | 4027 '''); |
4005 _assertNthStatementDoesNotExit(source, 0); | 4028 _assertNthStatementDoesNotExit(source, 0); |
4006 } | 4029 } |
4007 | 4030 |
4008 void test_yieldStatement_star_throw() { | 4031 void test_yieldStatement_star_throw() { |
4009 Source source = addSource(r''' | 4032 Source source = addSource(r''' |
4010 void f() sync* { | 4033 void f() sync* { |
4011 yield* throw ''; | 4034 yield* throw ''; |
4012 } | 4035 } |
4013 '''); | 4036 '''); |
4014 _assertNthStatementExits(source, 0); | 4037 _assertNthStatementExits(source, 0); |
4038 } | |
4039 | |
4040 void test_yieldStatement_throw() { | |
4041 Source source = addSource(r''' | |
4042 void f() sync* { | |
4043 yield throw ''; | |
4044 } | |
4045 '''); | |
4046 _assertNthStatementExits(source, 0); | |
4015 } | 4047 } |
4016 | 4048 |
4017 void _assertHasReturn(bool expectedResult, Source source, int n) { | 4049 void _assertHasReturn(bool expectedResult, Source source, int n) { |
4018 LibraryElement element = resolve2(source); | 4050 LibraryElement element = resolve2(source); |
4019 CompilationUnit unit = resolveCompilationUnit(source, element); | 4051 CompilationUnit unit = resolveCompilationUnit(source, element); |
4020 FunctionDeclaration function = unit.declarations.last; | 4052 FunctionDeclaration function = unit.declarations.last; |
4021 BlockFunctionBody body = function.functionExpression.body; | 4053 BlockFunctionBody body = function.functionExpression.body; |
4022 Statement statement = body.block.statements[n]; | 4054 Statement statement = body.block.statements[n]; |
4023 expect(ExitDetector.exits(statement), expectedResult); | 4055 expect(ExitDetector.exits(statement), expectedResult); |
4024 } | 4056 } |
4025 | 4057 |
4026 // Assert that the [n]th statement in the last function declaration of | 4058 // Assert that the [n]th statement in the last function declaration of |
4027 // [source] exits. | 4059 // [source] exits. |
4028 void _assertNthStatementExits(Source source, int n) { | 4060 void _assertNthStatementDoesNotExit(Source source, int n) { |
4029 _assertHasReturn(true, source, n); | 4061 _assertHasReturn(false, source, n); |
4030 } | 4062 } |
4031 | 4063 |
4032 // Assert that the [n]th statement in the last function declaration of | 4064 // Assert that the [n]th statement in the last function declaration of |
4033 // [source] does not exit. | 4065 // [source] does not exit. |
4034 void _assertNthStatementDoesNotExit(Source source, int n) { | 4066 void _assertNthStatementExits(Source source, int n) { |
4035 _assertHasReturn(false, source, n); | 4067 _assertHasReturn(true, source, n); |
4036 } | 4068 } |
4037 } | 4069 } |
4038 | 4070 |
4039 @reflectiveTest | 4071 @reflectiveTest |
4040 class FileBasedSourceTest { | 4072 class FileBasedSourceTest { |
4041 void test_equals_false_differentFiles() { | 4073 void test_equals_false_differentFiles() { |
4042 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); | 4074 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); |
4043 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); | 4075 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); |
4044 FileBasedSource source1 = new FileBasedSource(file1); | 4076 FileBasedSource source1 = new FileBasedSource(file1); |
4045 FileBasedSource source2 = new FileBasedSource(file2); | 4077 FileBasedSource source2 = new FileBasedSource(file2); |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4407 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 4439 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
4408 expect(UriKind.fromEncoding(0x58), same(null)); | 4440 expect(UriKind.fromEncoding(0x58), same(null)); |
4409 } | 4441 } |
4410 | 4442 |
4411 void test_getEncoding() { | 4443 void test_getEncoding() { |
4412 expect(UriKind.DART_URI.encoding, 0x64); | 4444 expect(UriKind.DART_URI.encoding, 0x64); |
4413 expect(UriKind.FILE_URI.encoding, 0x66); | 4445 expect(UriKind.FILE_URI.encoding, 0x66); |
4414 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 4446 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
4415 } | 4447 } |
4416 } | 4448 } |
OLD | NEW |