Skip to content

Commit 54ff5c3

Browse files
committed
Tests
1 parent e6dc0c7 commit 54ff5c3

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/main/java/ch/njol/skript/expressions/arithmetic/ExprArithmetic.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,20 @@ private Expression<T> simplifyInternal() {
386386
return this;
387387
}
388388

389+
/**
390+
* For testing purposes only.
391+
* @return the first expression
392+
*/
393+
Expression<L> getFirst() {
394+
return first;
395+
}
396+
397+
/**
398+
* For testing purposes only.
399+
* @return the second expression
400+
*/
401+
Expression<R> getSecond() {
402+
return second;
403+
}
404+
389405
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package ch.njol.skript.expressions.arithmetic;
2+
3+
import ch.njol.skript.lang.SkriptParser;
4+
import ch.njol.skript.lang.Variable;
5+
import ch.njol.skript.lang.util.ContextlessEvent;
6+
import ch.njol.skript.test.runner.SkriptJUnitTest;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
import org.skriptlang.skript.lang.simplification.SimplifiedLiteral;
10+
11+
/**
12+
* Check if arithmetic expressions are simplified correctly.
13+
*/
14+
public class ArithmeticSimplificationTest extends SkriptJUnitTest {
15+
16+
@Test
17+
public void test() {
18+
//noinspection unchecked
19+
var arithmetic = new SkriptParser("5 * 2 - 3 + 4").parseExpression(Number.class);
20+
Assert.assertTrue(arithmetic instanceof SimplifiedLiteral<? extends Number>);
21+
Assert.assertEquals(5 * 2 - 3 + 4, ((SimplifiedLiteral<? extends Number>) arithmetic).getSingle().intValue());
22+
23+
//noinspection unchecked
24+
arithmetic = new SkriptParser("5 + 4").parseExpression(Number.class);
25+
Assert.assertTrue(arithmetic instanceof SimplifiedLiteral<? extends Number>);
26+
Assert.assertEquals(5 + 4, ((SimplifiedLiteral<? extends Number>) arithmetic).getSingle().intValue());
27+
28+
//noinspection unchecked
29+
arithmetic = new SkriptParser("5 - 10 + {_loc}").parseExpression(Number.class);
30+
Assert.assertTrue(arithmetic instanceof ExprArithmetic<?,?,?>);
31+
var leftArith = ((ExprArithmetic<?,?,?>) arithmetic).getFirst();
32+
var rightArith = ((ExprArithmetic<?,?,?>) arithmetic).getSecond();
33+
Assert.assertTrue(leftArith instanceof SimplifiedLiteral<?>);
34+
Assert.assertTrue(rightArith instanceof Variable<?>);
35+
//noinspection unchecked,DataFlowIssue
36+
Assert.assertEquals(5 - 10, ((ExprArithmetic<?,?,Number>) arithmetic).getSingle(ContextlessEvent.get()).intValue());
37+
}
38+
39+
}

0 commit comments

Comments
 (0)