154 lines
No EOL
5.4 KiB
Java
154 lines
No EOL
5.4 KiB
Java
package dev.peerat.parser.java.element.value;
|
|
|
|
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.element.BaseElementTests;
|
|
import dev.peerat.parser.java.operation.IfOperation;
|
|
import dev.peerat.parser.java.operation.Operation;
|
|
import dev.peerat.parser.java.value.BiValue;
|
|
import dev.peerat.parser.java.value.StaticValue;
|
|
|
|
public class ValueInCondition extends BaseElementTests{
|
|
|
|
{
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(a){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
System.out.println(condition.getCondition());
|
|
assertEquals("a", ((StaticValue)condition.getCondition()).getToken().getValue());
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(a && b){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
BiValue value = (BiValue)condition.getCondition();
|
|
assertEquals("a", ((StaticValue)value.left()).getToken().getValue());
|
|
assertEquals("b", ((StaticValue)value.right()).getToken().getValue());
|
|
assertEquals("&&", value.getAction());
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(a || b){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
BiValue value = (BiValue)condition.getCondition();
|
|
assertEquals("a", ((StaticValue)value.left()).getToken().getValue());
|
|
assertEquals("b", ((StaticValue)value.right()).getToken().getValue());
|
|
assertEquals("||", value.getAction());
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(a || (b)){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
BiValue value = (BiValue)condition.getCondition();
|
|
assertEquals("a", ((StaticValue)value.left()).getToken().getValue());
|
|
assertEquals("b", ((StaticValue)value.right()).getToken().getValue());
|
|
assertEquals("||", value.getAction());
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(((a || ((b))))){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
BiValue value = (BiValue)condition.getCondition();
|
|
assertEquals("a", ((StaticValue)value.left()).getToken().getValue());
|
|
assertEquals("b", ((StaticValue)value.right()).getToken().getValue());
|
|
assertEquals("||", value.getAction());
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(a > 2){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
BiValue value = (BiValue)condition.getCondition();
|
|
assertEquals("a", ((StaticValue)value.left()).getToken().getValue());
|
|
assertEquals("2", ((StaticValue)value.right()).getToken().getValue());
|
|
assertEquals(">", value.getAction());
|
|
});
|
|
|
|
register(
|
|
"package be.jeffcheasey88;"
|
|
+ ""
|
|
+ "public static class Test{ "
|
|
+ " void test(){ "
|
|
+ " if(a <= 2){}"
|
|
+ "}"
|
|
+ "}",
|
|
(javafile) -> {
|
|
Function function = checkFunction(checkClass(javafile).getElements().get(0));
|
|
assertEquals(1, function.getElements().size());
|
|
Operation op = checkOperation(function.getElements().get(0));
|
|
assertTrue(op instanceof IfOperation);
|
|
IfOperation condition = (IfOperation)op;
|
|
BiValue value = (BiValue)condition.getCondition();
|
|
assertEquals("a", ((StaticValue)value.left()).getToken().getValue());
|
|
assertEquals("2", ((StaticValue)value.right()).getToken().getValue());
|
|
assertEquals(">", value.getAction());
|
|
});
|
|
}
|
|
} |