Search in sources :

Example 1 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class CallTest method shouldReturnCallValueWhenExecuteCallWithoutParams.

@Test
void shouldReturnCallValueWhenExecuteCallWithoutParams() {
    Call call = createCall("carded");
    env.putFunction("carded", (x) -> new RedsInteger(500));
    assertEquals(new RedsInteger(500), call.execute(env));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 2 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class CallTest method shouldReturnCallValueWhenExecuteCallWithParams.

@Test
void shouldReturnCallValueWhenExecuteCallWithParams() {
    Call call = createCall("zymogene", 383);
    env.putFunction("zymogene", (x) -> new RedsInteger(576).plus(x.get(0)));
    assertEquals(new RedsInteger(576 + 383), call.execute(env));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 3 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class ProgramTest method shouldReturnSomethingWhenParsingStmt.

@Test
void shouldReturnSomethingWhenParsingStmt() {
    Statement stmt = parseStatement("598");
    assertEquals(new RedsInteger(598), 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 4 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class ProgramTest method shouldUpdateValueWhenAssignConditionallyAVariable.

@Test
void shouldUpdateValueWhenAssignConditionallyAVariable() {
    parseProgram("a = 0\n" + "if true {\n" + "  a = 1\n" + "} else {\n" + "  a = 2\n" + "}\n").execute(env);
    assertEquals(new RedsInteger(1), env.getVariable("a"));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 5 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class AssignmentTest method shouldStoreVariableAndReturnValueWhenAssignNewVariable.

@Test
void shouldStoreVariableAndReturnValueWhenAssignNewVariable() {
    Assignment assignment = createAssignment("ctrl", 250);
    assertEquals(new RedsInteger(250), assignment.execute(env));
    assertEquals(new RedsInteger(250), env.getVariable("ctrl"));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Aggregations

RedsInteger (net.taken.redsnake.lang.RedsInteger)28 Test (org.junit.jupiter.api.Test)28 Statement (net.taken.redsnake.tree.statements.Statement)7 TestUtils.parseStatement (net.taken.redsnake.tree.TestUtils.parseStatement)5 If (net.taken.redsnake.tree.statements.If)3 Program (net.taken.redsnake.tree.Program)2