32 lines
1.3 KiB
Java
32 lines
1.3 KiB
Java
package io.gitlab.jfronny.muscript.test;
|
|
|
|
import io.gitlab.jfronny.muscript.ast.StringExpr;
|
|
import io.gitlab.jfronny.muscript.ast.dynamic.assign.DynamicAssign;
|
|
import io.gitlab.jfronny.muscript.ast.literal.StringLiteral;
|
|
import io.gitlab.jfronny.muscript.compiler.Parser;
|
|
import io.gitlab.jfronny.muscript.data.Scope;
|
|
import io.gitlab.jfronny.muscript.test.util.UnforkableScope;
|
|
import org.junit.jupiter.api.*;
|
|
|
|
import static io.gitlab.jfronny.muscript.test.util.MuTestUtil.number;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class AssignTest {
|
|
@Test
|
|
void testAssignSimple() {
|
|
StringExpr expr = Parser.parse("someval = 'test'").asStringExpr();
|
|
assertEquals(new DynamicAssign(0, 6, "someval", new StringLiteral(10, 15, "test").asDynamicExpr()).asStringExpr(), expr);
|
|
assertEquals("someval = 'test'", expr.toString());
|
|
Scope scope = new UnforkableScope();
|
|
assertEquals("test", expr.get(scope));
|
|
assertEquals("test", scope.getValue().get("someval").asString().getValue());
|
|
}
|
|
|
|
@Test
|
|
void testAssignInner() {
|
|
assertEquals(2, number("{->some = other = 2; other}()"));
|
|
assertEquals(2, number("{->some = other = 2; some}()"));
|
|
assertEquals(2, number("{->some = 2 + 4 * (other = 4 / 2); other}()"));
|
|
}
|
|
}
|