From a05f2418c137e34eb918c4f4fb26854cec6b65a0 Mon Sep 17 00:00:00 2001 From: Pilow Date: Sun, 12 May 2024 17:36:43 +0700 Subject: [PATCH] Fix typeOf with set and intervals --- src/main/java/leekscript/runner/LeekValueManager.java | 6 ++++++ src/main/java/leekscript/runner/values/LeekValueType.java | 2 ++ src/test/java/test/TestGeneral.java | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/main/java/leekscript/runner/LeekValueManager.java b/src/main/java/leekscript/runner/LeekValueManager.java index 9be8b115..c547b5f9 100644 --- a/src/main/java/leekscript/runner/LeekValueManager.java +++ b/src/main/java/leekscript/runner/LeekValueManager.java @@ -16,9 +16,11 @@ import leekscript.runner.values.MapLeekValue; import leekscript.runner.values.ClassLeekValue; import leekscript.runner.values.FunctionLeekValue; +import leekscript.runner.values.IntervalLeekValue; import leekscript.runner.values.LeekValue; import leekscript.runner.values.LeekValueType; import leekscript.runner.values.ObjectLeekValue; +import leekscript.runner.values.SetLeekValue; import leekscript.runner.values.Box; import leekscript.common.AccessLevel; import leekscript.common.Error; @@ -123,6 +125,8 @@ public static int getType(Object v) { if (v instanceof ObjectLeekValue || v instanceof NativeObjectLeekValue) return LeekValueType.OBJECT; if (v instanceof ClassLeekValue) return LeekValueType.CLASS; if (v instanceof FunctionLeekValue) return LeekValueType.FUNCTION; + if (v instanceof SetLeekValue) return LeekValueType.SET; + if (v instanceof IntervalLeekValue) return LeekValueType.INTERVAL; if (v instanceof Box) return getType(((Box) v).get()); return 0; } @@ -136,6 +140,8 @@ public static int getV1Type(Object v) { if (v instanceof ObjectLeekValue || v instanceof NativeObjectLeekValue) return LeekValueType.OBJECT_V1; if (v instanceof ClassLeekValue) return LeekValueType.CLASS_V1; if (v instanceof FunctionLeekValue) return LeekValueType.FUNCTION_V1; + if (v instanceof SetLeekValue) return LeekValueType.SET_V1; + if (v instanceof IntervalLeekValue) return LeekValueType.INTERVAL_V1; if (v instanceof Box box) return getV1Type(box.get()); return 0; } diff --git a/src/main/java/leekscript/runner/values/LeekValueType.java b/src/main/java/leekscript/runner/values/LeekValueType.java index 6ddb5762..2660e759 100644 --- a/src/main/java/leekscript/runner/values/LeekValueType.java +++ b/src/main/java/leekscript/runner/values/LeekValueType.java @@ -12,6 +12,8 @@ public class LeekValueType { public final static int FUNCTION_V1 = 6; public final static int CLASS_V1 = 7; public final static int OBJECT_V1 = 8; + public final static int SET_V1 = 9; + public final static int INTERVAL_V1 = 10; public final static int NULL = 0; public final static int NUMBER = 1; diff --git a/src/test/java/test/TestGeneral.java b/src/test/java/test/TestGeneral.java index 19f4ea23..12df7ef7 100644 --- a/src/test/java/test/TestGeneral.java +++ b/src/test/java/test/TestGeneral.java @@ -54,6 +54,8 @@ public void run() { code("return typeOf(null)").equals(String.valueOf(LeekConstants.TYPE_NULL.getIntValue())); // Test piège code("return typeOf(function(){ return 4; }())").equals(String.valueOf(LeekConstants.TYPE_NUMBER.getIntValue())); + code_v4_("return typeOf(<1, 2, 3>)").equals(String.valueOf(LeekConstants.TYPE_SET.getIntValue())); + code_v4_("return typeOf([1..10])").equals(String.valueOf(LeekConstants.TYPE_INTERVAL.getIntValue())); section("color()"); code_v4_("color(0, 0, 0)").error(Error.REMOVED_FUNCTION_REPLACEMENT);