Search in sources :

Example 6 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldPrioritizePowerOverUnaryMinus.

@Test
void shouldPrioritizePowerOverUnaryMinus() {
    Statement stmt = parseStatement("-(2)**2");
    assertEquals(new RedsInteger(-4), stmt.execute(env));
}
Also used : TestUtils.parseStatement(net.taken.redsnake.tree.TestUtils.parseStatement) Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 7 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldPrioritizeMultiplyDivideAndModuloOverPlusAndMinus.

@Test
void shouldPrioritizeMultiplyDivideAndModuloOverPlusAndMinus() {
    Statement stmt = parseStatement("2+2*3-4/2+5%3");
    assertEquals(new RedsInteger(8), stmt.execute(env));
}
Also used : TestUtils.parseStatement(net.taken.redsnake.tree.TestUtils.parseStatement) Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 8 with Statement

use of net.taken.redsnake.tree.statements.Statement in project redsnake by Taken0711.

the class AssignmentTest method shouldPrioritizePlusAndMinusOverEquals.

@Test
void shouldPrioritizePlusAndMinusOverEquals() {
    Statement stmt = parseStatement("a = 5+2-1");
    stmt.execute(env);
    assertEquals(new RedsInteger(6), env.getVariable("a"));
}
Also used : Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Aggregations

Statement (net.taken.redsnake.tree.statements.Statement)8 RedsInteger (net.taken.redsnake.lang.RedsInteger)7 Test (org.junit.jupiter.api.Test)7 TestUtils.parseStatement (net.taken.redsnake.tree.TestUtils.parseStatement)5 RedsnakeLexer (net.taken.redsnake.parser.RedsnakeLexer)1 RedsnakeParser (net.taken.redsnake.parser.RedsnakeParser)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 TokenStream (org.antlr.v4.runtime.TokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1