From 64004fc2c140dcb25687fd984fd05545901ea762 Mon Sep 17 00:00:00 2001 From: Felix O'Brien <12935468+FelixOBrien@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:32:22 +1100 Subject: [PATCH] Bump EvalEx to 3.0.5. (#327) * Updated EvalEx dependency to 3.0.5. Rewrote Evalex functions. * Added Unit Tests for ConditionFunction, corrected some functions. * Fixed date formatting in ConditionalFunctions * Updated tests for ConditionFunctions --- build.gradle | 2 +- core/build.gradle | 2 +- .../condition/AfterDateLazyFunction.java | 27 ++-- .../condition/BeforeDateLazyFunction.java | 28 +++-- .../function/condition/CheckTickFunction.java | 16 ++- .../function/condition/ConditionFunction.java | 50 +++----- .../condition/ContainsLazyFunction.java | 25 ++-- .../condition/EndsWithLazyFunction.java | 25 ++-- .../function/condition/EqualLazyFunction.java | 25 ++-- .../IgnoreCaseEqualLazyFunction.java | 26 ++-- .../condition/StartsWithLazyFunction.java | 25 ++-- .../test/function/ConditionFunctionTest.java | 118 ++++++++++++++++++ 12 files changed, 233 insertions(+), 136 deletions(-) create mode 100644 core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConditionFunctionTest.java diff --git a/build.gradle b/build.gradle index f241d0cc6..90d44996d 100644 --- a/build.gradle +++ b/build.gradle @@ -77,7 +77,7 @@ subprojects { relocate 'org.aopalliance.intercept', 'com.clubobsidian.dynamicgui.shaded.aopalliance.intercept' relocate 'org.aopalliance.aop', 'com.clubobsidian.dynamicgui.shaded.aopalliance.aop' relocate 'javax.inject', 'com.clubobsidian.dynamicgui.shaded.javax.inject' - relocate 'com.udojava.evalex', 'com.clubobsidian.dynamicgui.shaded.evalex' + relocate 'com.ezylang.evalex', 'com.clubobsidian.dynamicgui.shaded.evalex' relocate 'com.typesafe.config', 'com.clubobsidian.dynamicgui.shaded.typesafeconfig' relocate 'com.google.j2objc', 'com.clubobsidian.dynamicgui.shaded.j2objc' relocate 'com.google.inject', 'com.clubobsidian.dynamicgui.shaded.guice' diff --git a/core/build.gradle b/core/build.gradle index 81f06aa8d..90bb48f0d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -12,7 +12,7 @@ dependencies { api project(path: ':api') api project(path: ':parser') testImplementation project(path: ':mock') - api 'com.udojava:EvalEx:2.1' + api 'com.ezylang:EvalEx:3.0.5' api 'com.github.ClubObsidian:FuzzUtil:1.1.0' api("com.google.inject:guice:$guiceVersion") api "net.kyori:adventure-text-minimessage:$adventureVersion" diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/AfterDateLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/AfterDateLazyFunction.java index 1ee341129..0eb8b0e74 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/AfterDateLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/AfterDateLazyFunction.java @@ -17,33 +17,32 @@ package com.clubobsidian.dynamicgui.core.function.condition; import com.clubobsidian.dynamicgui.api.DynamicGui; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.AbstractFunction; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; +import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.Date; -import java.util.List; - -public class AfterDateLazyFunction extends AbstractLazyFunction { - - protected AfterDateLazyFunction() { - super("AFTERDATE", 1, true); - } +@FunctionParameter(name = "AfterDate", isLazy = true) +public class AfterDateLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { try { String format = DynamicGui.get().getConfig().getDateTimeFormat(); Date now = Date.from(Instant.now()); - Date expected = new SimpleDateFormat(format).parse(lazyParams.get(0).getString()); + Date expected = new SimpleDateFormat(format).parse(parameterValues[0].getExpressionNode().getToken().getValue()); if (now.after(expected)) { - return ConditionFunction.ONE; + return new EvaluationValue(BigDecimal.ONE); } } catch (ParseException ignore) { - DynamicGui.get().getLogger().error("Invalid Date: %s", lazyParams.get(0).getString()); + DynamicGui.get().getLogger().error("Invalid Date: %s", parameterValues[0].getStringValue()); } - return ConditionFunction.ZERO; + return new EvaluationValue(BigDecimal.ZERO); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/BeforeDateLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/BeforeDateLazyFunction.java index e0c51ae05..fb8f54a76 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/BeforeDateLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/BeforeDateLazyFunction.java @@ -17,33 +17,35 @@ package com.clubobsidian.dynamicgui.core.function.condition; import com.clubobsidian.dynamicgui.api.DynamicGui; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.AbstractFunction; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; +import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; import java.util.Date; -import java.util.List; -public class BeforeDateLazyFunction extends AbstractLazyFunction { - - protected BeforeDateLazyFunction() { - super("BEFOREDATE", 1, true); - } +@FunctionParameter(name = "BeforeDate", isLazy = true) +public class BeforeDateLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { try { + String format = DynamicGui.get().getConfig().getDateTimeFormat(); + System.out.println(format); Date now = Date.from(Instant.now()); - Date expected = new SimpleDateFormat(format).parse(lazyParams.get(0).getString()); + Date expected = new SimpleDateFormat(format).parse(parameterValues[0].getExpressionNode().getToken().getValue()); if (now.before(expected)) { - return ConditionFunction.ONE; + return new EvaluationValue(BigDecimal.ONE); } } catch (ParseException ignore) { - DynamicGui.get().getLogger().error("Invalid Date: %s", lazyParams.get(0).getString()); + DynamicGui.get().getLogger().error("Invalid Date: %s", parameterValues[0].getExpressionNode().getToken().getValue()); } - return ConditionFunction.ZERO; + return new EvaluationValue(BigDecimal.ZERO); } } diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/CheckTickFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/CheckTickFunction.java index c53d8f01c..a95e47d71 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/CheckTickFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/CheckTickFunction.java @@ -20,7 +20,11 @@ import com.clubobsidian.dynamicgui.api.function.Function; import com.clubobsidian.dynamicgui.api.function.FunctionOwner; import com.clubobsidian.dynamicgui.api.gui.Slot; -import com.udojava.evalex.Expression; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.config.ExpressionConfiguration; + +import java.math.BigDecimal; +import java.util.Map; public class CheckTickFunction extends Function { @@ -45,14 +49,8 @@ public boolean function(PlayerWrapper playerWrapper) { String tickData = this.getData() .replace("%tick%", String.valueOf(tick)) .replace("%frame%", String.valueOf(frame)); - Expression expr = new Expression(tickData); - expr.addLazyFunction(new EqualLazyFunction()); - - if (!expr.isBoolean()) { - return false; - } - - return expr.eval().intValue() == 1; + Expression expr = new Expression(tickData, ExpressionConfiguration.defaultConfiguration().withAdditionalFunctions(Map.entry("STREQUAL", new EqualLazyFunction()))); + return expr.evaluate().getNumberValue().equals(BigDecimal.ONE); } catch (Exception ex) { ex.printStackTrace(); return false; diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ConditionFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ConditionFunction.java index f3f5f3b58..9750b4a2e 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ConditionFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ConditionFunction.java @@ -18,10 +18,11 @@ import com.clubobsidian.dynamicgui.api.entity.PlayerWrapper; import com.clubobsidian.dynamicgui.api.function.Function; -import com.udojava.evalex.Expression; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.config.ExpressionConfiguration; import java.math.BigDecimal; +import java.util.Map; public class ConditionFunction extends Function { @@ -37,43 +38,20 @@ public ConditionFunction() { @Override public boolean function(PlayerWrapper playerWrapper) { try { - Expression expr = new Expression(this.getData()); - - expr.addLazyFunction(new EqualLazyFunction()); - expr.addLazyFunction(new IgnoreCaseEqualLazyFunction()); - expr.addLazyFunction(new ContainsLazyFunction()); - expr.addLazyFunction(new EndsWithLazyFunction()); - expr.addLazyFunction(new StartsWithLazyFunction()); - expr.addLazyFunction(new AfterDateLazyFunction()); - expr.addLazyFunction(new BeforeDateLazyFunction()); - - if (!expr.isBoolean()) - return false; - - return expr.eval().intValue() == 1; + ExpressionConfiguration config = ExpressionConfiguration.defaultConfiguration().withAdditionalFunctions( + Map.entry("STREQUAL", new EqualLazyFunction()), + Map.entry("STREQUALIGNORECASE", new IgnoreCaseEqualLazyFunction()), + Map.entry("STRCONTAINS", new ContainsLazyFunction()), + Map.entry("STRENDSWITH", new EndsWithLazyFunction()), + Map.entry("STRSTARTSWITH", new StartsWithLazyFunction()), + Map.entry("AFTERDATE", new AfterDateLazyFunction()), + Map.entry("BEFOREDATE", new BeforeDateLazyFunction()) + ); + Expression expr = new Expression(this.getData(), config); + return expr.evaluate().getNumberValue().equals(BigDecimal.ONE); } catch (Exception ex) { ex.printStackTrace(); return false; } } - - public static LazyNumber ZERO = new LazyNumber() { - public BigDecimal eval() { - return BigDecimal.ZERO; - } - - public String getString() { - return "0"; - } - }; - - public static LazyNumber ONE = new LazyNumber() { - public BigDecimal eval() { - return BigDecimal.ONE; - } - - public String getString() { - return null; - } - }; } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ContainsLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ContainsLazyFunction.java index cf239d4e8..bbad3bfcf 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ContainsLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/ContainsLazyFunction.java @@ -16,22 +16,23 @@ package com.clubobsidian.dynamicgui.core.function.condition; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.AbstractFunction; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; -import java.util.List; -public class ContainsLazyFunction extends AbstractLazyFunction { - - protected ContainsLazyFunction() { - super("STRCONTAINS", 2, true); - } +import java.math.BigDecimal; +@FunctionParameter(name = "value", isLazy = true) +@FunctionParameter(name = "character", isLazy = true) +public class ContainsLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { - if (lazyParams.get(0).getString().contains(lazyParams.get(1).getString())) { - return ConditionFunction.ONE; + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { + if (parameterValues[0].getExpressionNode().getToken().getValue().contains(parameterValues[1].getExpressionNode().getToken().getValue())) { + return new EvaluationValue(BigDecimal.ONE); } - return ConditionFunction.ZERO; + return new EvaluationValue(BigDecimal.ZERO); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EndsWithLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EndsWithLazyFunction.java index f7b601e67..1759f4e1b 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EndsWithLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EndsWithLazyFunction.java @@ -16,22 +16,21 @@ package com.clubobsidian.dynamicgui.core.function.condition; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.AbstractFunction; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; -import java.util.List; - -public class EndsWithLazyFunction extends AbstractLazyFunction { - - protected EndsWithLazyFunction() { - super("STRENDSWITH", 2, true); - } +@FunctionParameter(name = "value", isLazy = true) +@FunctionParameter(name = "endsWith", isLazy = true) +public class EndsWithLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { - if (lazyParams.get(0).getString().endsWith(lazyParams.get(1).getString())) { - return ConditionFunction.ONE; + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { + if (parameterValues[0].getExpressionNode().getToken().getValue().endsWith(parameterValues[1].getExpressionNode().getToken().getValue())) { + return new EvaluationValue(1); } - return ConditionFunction.ZERO; + return new EvaluationValue(0); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EqualLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EqualLazyFunction.java index 223051b97..579291ec8 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EqualLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/EqualLazyFunction.java @@ -16,22 +16,23 @@ package com.clubobsidian.dynamicgui.core.function.condition; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.AbstractFunction; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; -import java.util.List; +import java.math.BigDecimal; -public class EqualLazyFunction extends AbstractLazyFunction { - - protected EqualLazyFunction() { - super("STREQUAL", 2, true); - } +@FunctionParameter(name = "stringA", isLazy = true) +@FunctionParameter(name = "stringB", isLazy = true) +public class EqualLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { - if (lazyParams.get(0).getString().equals(lazyParams.get(1).getString())) { - return ConditionFunction.ONE; + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { + if(parameterValues[0].getExpressionNode().getToken().getValue().equals(parameterValues[1].getExpressionNode().getToken().getValue())) { + return new EvaluationValue(BigDecimal.ONE); } - return ConditionFunction.ZERO; + return new EvaluationValue(BigDecimal.ZERO); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/IgnoreCaseEqualLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/IgnoreCaseEqualLazyFunction.java index 55cdffa85..3d55e3eca 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/IgnoreCaseEqualLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/IgnoreCaseEqualLazyFunction.java @@ -16,22 +16,22 @@ package com.clubobsidian.dynamicgui.core.function.condition; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; +import com.ezylang.evalex.functions.AbstractFunction; -import java.util.List; - -public class IgnoreCaseEqualLazyFunction extends AbstractLazyFunction { - - protected IgnoreCaseEqualLazyFunction() { - super("STREQUALIGNORECASE", 2, true); - } +import java.math.BigDecimal; +@FunctionParameter(name = "stringA", isLazy = true) +@FunctionParameter(name = "stringB", isLazy = true) +public class IgnoreCaseEqualLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { - if (lazyParams.get(0).getString().equalsIgnoreCase(lazyParams.get(1).getString())) { - return ConditionFunction.ONE; + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { + if(parameterValues[0].getExpressionNode().getToken().getValue().equalsIgnoreCase(parameterValues[1].getExpressionNode().getToken().getValue())){ + return new EvaluationValue(BigDecimal.ONE); } - return ConditionFunction.ZERO; + return new EvaluationValue(BigDecimal.ZERO); } } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/StartsWithLazyFunction.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/StartsWithLazyFunction.java index 66985a0d1..50bdd70b4 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/StartsWithLazyFunction.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/function/condition/StartsWithLazyFunction.java @@ -16,22 +16,23 @@ package com.clubobsidian.dynamicgui.core.function.condition; -import com.udojava.evalex.AbstractLazyFunction; -import com.udojava.evalex.Expression.LazyNumber; +import com.ezylang.evalex.Expression; +import com.ezylang.evalex.data.EvaluationValue; +import com.ezylang.evalex.functions.FunctionParameter; +import com.ezylang.evalex.parser.Token; +import com.ezylang.evalex.functions.AbstractFunction; -import java.util.List; +import java.math.BigDecimal; -public class StartsWithLazyFunction extends AbstractLazyFunction { - - protected StartsWithLazyFunction() { - super("STRSTARTSWITH", 2, true); - } +@FunctionParameter(name = "value", isLazy = true) +@FunctionParameter(name = "startsWith", isLazy = true) +public class StartsWithLazyFunction extends AbstractFunction { @Override - public LazyNumber lazyEval(List lazyParams) { - if (lazyParams.get(0).getString().startsWith(lazyParams.get(1).getString())) { - return ConditionFunction.ONE; + public EvaluationValue evaluate(Expression expression, Token functionToken, EvaluationValue... parameterValues) { + if(parameterValues[0].getExpressionNode().getToken().getValue().startsWith(parameterValues[1].getExpressionNode().getToken().getValue())){ + return new EvaluationValue(BigDecimal.ONE); } - return ConditionFunction.ZERO; + return new EvaluationValue(BigDecimal.ZERO); } } \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConditionFunctionTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConditionFunctionTest.java new file mode 100644 index 000000000..f6a55b980 --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/function/ConditionFunctionTest.java @@ -0,0 +1,118 @@ +package com.clubobsidian.dynamicgui.core.test.function; + +import com.clubobsidian.dynamicgui.api.entity.PlayerWrapper; +import com.clubobsidian.dynamicgui.core.function.condition.*; +import com.clubobsidian.dynamicgui.core.test.mock.test.FactoryTest; +import org.junit.jupiter.api.Test; + + + +import static org.junit.jupiter.api.Assertions.*; + +public class ConditionFunctionTest extends FactoryTest { + @Test + public void testStringEquals() { + ConditionFunction condition = new ConditionFunction(); + condition.setData("STREQUAL(\"test\", \"test\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringNotEquals(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STREQUAL(\"test\", \"test1\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + + @Test + public void testStringEqualsIgnoreCase(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STREQUALIGNORECASE(\"tEST\", \"test\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringNotEqualsIgnoreCase(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STREQUALIGNORECASE(\"tEST\", \"test1\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringStartsWith(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STRSTARTSWITH(\"test\", \"te\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringNotStartsWith(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STRSTARTSWITH(\"end\", \"s\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringEndsWith(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STRENDSWITH(\"test\", \"st\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringNotEndsWith(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STRENDSWITH(\"test\", \"end\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringContains(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STRCONTAINS(\"test\", \"es\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testStringNotContains(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("STRCONTAINS(\"test\", \"end\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testAfterDate(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("AFTERDATE(\"01 01, 2023 00:00:00\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testNotAfterDate(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("AFTERDATE(\"01 01, 2100 00:00:00\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testBeforeDate(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("BEFOREDATE(\"01 01, 2100 00:00:00\")"); + assertTrue(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testNotBeforeDate(){ + ConditionFunction condition = new ConditionFunction(); + condition.setData("BEFOREDATE(\"01 01, 2023 00:00:00\")"); + assertFalse(condition.function(this.getFactory().createPlayer())); + } + + @Test + public void testCheckTickFunction(){ + PlayerWrapper playerWrapper = this.getFactory().createPlayer(); + CheckTickFunction checkTickFunction = new CheckTickFunction(); + assertFalse(checkTickFunction.function(playerWrapper)); + } +}