108 lines
No EOL
3.6 KiB
Java
108 lines
No EOL
3.6 KiB
Java
package dev.peerat.parser.java.element.operation;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import dev.peerat.parser.java.Function;
|
|
import dev.peerat.parser.java.Operation;
|
|
import dev.peerat.parser.java.element.BaseElementTests;
|
|
import dev.peerat.parser.java.operation.BreakOperation;
|
|
import dev.peerat.parser.java.operation.ContinueOperation;
|
|
import dev.peerat.parser.java.operation.ForOperation;
|
|
import dev.peerat.parser.java.operation.ReturnOperation;
|
|
import dev.peerat.parser.java.operation.WhileOperation;
|
|
|
|
public class LoopOperationTests extends BaseElementTests{
|
|
|
|
{
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " for(;;) break;"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof ForOperation);
|
|
ForOperation forOp = (ForOperation)op;
|
|
Operation o = checkOperation(forOp.getElements().get(0));
|
|
assertTrue(o instanceof BreakOperation);
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " for(;;){ break;}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof ForOperation);
|
|
ForOperation forOp = (ForOperation)op;
|
|
Operation o = checkOperation(forOp.getElements().get(0));
|
|
assertTrue(o instanceof BreakOperation);
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " for(;;) continue;"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof ForOperation);
|
|
ForOperation forOp = (ForOperation)op;
|
|
Operation o = checkOperation(forOp.getElements().get(0));
|
|
assertTrue(o instanceof ContinueOperation);
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " while(true) continue;"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof WhileOperation);
|
|
WhileOperation whileOp = (WhileOperation)op;
|
|
Operation o = checkOperation(whileOp.getElements().get(0));
|
|
assertTrue(o instanceof ContinueOperation);
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " while(true) return;"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof WhileOperation);
|
|
WhileOperation whileOp = (WhileOperation)op;
|
|
Operation o = checkOperation(whileOp.getElements().get(0));
|
|
assertTrue(o instanceof ReturnOperation);
|
|
});
|
|
}
|
|
} |