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

Unified Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 2008363002: Add label support to ExitDetector (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Re-short circuit, plus test Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/all_the_rest_test.dart
diff --git a/pkg/analyzer/test/generated/all_the_rest_test.dart b/pkg/analyzer/test/generated/all_the_rest_test.dart
index c01ed0b03b5f083b124ead1acd302bc892ba0ed1..9445d72b08eedd4c524fc3f9efee7015eca2f02f 100644
--- a/pkg/analyzer/test/generated/all_the_rest_test.dart
+++ b/pkg/analyzer/test/generated/all_the_rest_test.dart
@@ -3856,6 +3856,20 @@ class ExitDetectorTest extends ParserTestCase {
*/
@reflectiveTest
class ExitDetectorTest2 extends ResolverTestCase {
+ void test_forStatement_implicitTrue_breakWithLabel() {
+ Source source = addSource(r'''
+void f() {
+ x: for (;;) {
+ if (1 < 2) {
+ break x;
+ }
+ return;
+ }
+}
+''');
+ _assertNthStatementDoesNotExit(source, 0);
+ }
+
void test_switch_withEnum_false_noDefault() {
Source source = addSource(r'''
enum E { A, B }
@@ -3870,12 +3884,7 @@ String f(E e) {
return x;
}
''');
- LibraryElement element = resolve2(source);
- CompilationUnit unit = resolveCompilationUnit(source, element);
- FunctionDeclaration function = unit.declarations.last;
- BlockFunctionBody body = function.functionExpression.body;
- Statement statement = body.block.statements[1];
- expect(ExitDetector.exits(statement), false);
+ _assertNthStatementDoesNotExit(source, 1);
}
void test_switch_withEnum_false_withDefault() {
@@ -3892,12 +3901,7 @@ String f(E e) {
return x;
}
''');
- LibraryElement element = resolve2(source);
- CompilationUnit unit = resolveCompilationUnit(source, element);
- FunctionDeclaration function = unit.declarations.last;
- BlockFunctionBody body = function.functionExpression.body;
- Statement statement = body.block.statements[1];
- expect(ExitDetector.exits(statement), false);
+ _assertNthStatementDoesNotExit(source, 1);
}
void test_switch_withEnum_true_noDefault() {
@@ -3912,12 +3916,7 @@ String f(E e) {
}
}
''');
- LibraryElement element = resolve2(source);
- CompilationUnit unit = resolveCompilationUnit(source, element);
- FunctionDeclaration function = unit.declarations.last;
- BlockFunctionBody body = function.functionExpression.body;
- Statement statement = body.block.statements[0];
- expect(ExitDetector.exits(statement), true);
+ _assertNthStatementExits(source, 0);
}
void test_switch_withEnum_true_withDefault() {
@@ -3932,12 +3931,56 @@ String f(E e) {
}
}
''');
+ _assertNthStatementExits(source, 0);
+ }
+
+ void test_whileStatement_breakWithLabel() {
+ Source source = addSource(r'''
+void f() {
+ x: while (true) {
+ if (1 < 2) {
+ break x;
+ }
+ return;
+ }
+}
+''');
+ _assertNthStatementDoesNotExit(source, 0);
+ }
+
+ void test_whileStatement_breakWithLabel_afterExting() {
+ Source source = addSource(r'''
+void f() {
+ x: while (true) {
+ return;
+ if (1 < 2) {
+ break x;
+ }
+ }
+}
+''');
+ _assertNthStatementExits(source, 0);
+ }
+
+ void _assertHasReturn(bool expectedResult, String source, int n) {
LibraryElement element = resolve2(source);
CompilationUnit unit = resolveCompilationUnit(source, element);
FunctionDeclaration function = unit.declarations.last;
BlockFunctionBody body = function.functionExpression.body;
- Statement statement = body.block.statements[0];
- expect(ExitDetector.exits(statement), true);
+ Statement statement = body.block.statements[n];
+ expect(ExitDetector.exits(statement), expectedResult);
+ }
+
+ // Assert that the [n]th statement in the last function declaration of
+ // [source] exits.
+ void _assertNthStatementExits(String source, int n) {
+ _assertHasReturn(true, source, n);
+ }
+
+ // Assert that the [n]th statement in the last function declaration of
+ // [source] does not exit.
+ void _assertNthStatementDoesNotExit(String source, int n) {
+ _assertHasReturn(false, source, n);
}
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698