Update tests for targets
This commit is contained in:
3 files changed
+10
-11
No files matched your search
@@ -44,17 +44,16 @@ public final class ASTContinueStatement extends AbstractStatement {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the statement that is the target of this break. This must
|
||||
* be a loop.
|
||||
* Returns the statement that is the target of this break. This can
|
||||
* be a loop, or an {@link ASTLabeledStatement}.
|
||||
*/
|
||||
public ASTLoopStatement getTarget() {
|
||||
public ASTStatement getTarget() {
|
||||
String myLabel = this.getLabel();
|
||||
if (myLabel == null) {
|
||||
return ancestors().map(CONTINUE_TARGET_MAPPER).first();
|
||||
}
|
||||
return (ASTLoopStatement) ancestors(ASTLabeledStatement.class)
|
||||
return ancestors(ASTLabeledStatement.class)
|
||||
.filter(it -> it.getLabel().equals(myLabel))
|
||||
.map(ASTLabeledStatement::getStatement)
|
||||
.first();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ public class AbruptCompletionTests extends BaseNonParserTest {
|
||||
private Executable canCompleteNormally(String stmt) {
|
||||
return canCompleteNormally(stmt, actual -> {
|
||||
if (!actual) {
|
||||
throw new AssertionFailedError("Code can complete normally: `" + stmt + "`");
|
||||
throw new AssertionFailedError("Code CAN complete normally: `" + stmt + "`");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class AbruptCompletionTests extends BaseNonParserTest {
|
||||
private Executable mustCompleteAbruptly(String stmt) {
|
||||
return canCompleteNormally(stmt, actual -> {
|
||||
if (actual) {
|
||||
throw new AssertionFailedError("Code MUST complete abruptly, got " + actual + ": `" + stmt + "`");
|
||||
throw new AssertionFailedError("Code MUST complete abruptly: `" + stmt + "`");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,19 +179,19 @@ class ASTStatementsTest : ParserTestSpec({
|
||||
""" should parseAs {
|
||||
block {
|
||||
labeledStatement("l") {
|
||||
val labeledL = it
|
||||
forLoop {
|
||||
val loopL = it
|
||||
block {
|
||||
labeledStatement("i") {
|
||||
val labeledI = it
|
||||
forLoop {
|
||||
val loopI = it;
|
||||
ifStatement {
|
||||
it::getCondition shouldBe unspecifiedChild()
|
||||
it::getThenBranch shouldBe breakStatement("l") {
|
||||
it::getTarget shouldBe loopL
|
||||
it::getTarget shouldBe labeledL
|
||||
}
|
||||
it::getElseBranch shouldBe continueStatement("i") {
|
||||
it::getTarget shouldBe loopI
|
||||
it::getTarget shouldBe labeledI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user