Skip to content

Commit

Permalink
Fix typeOf with set and intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
5pilow committed May 12, 2024
1 parent 8a88aeb commit a05f241
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/leekscript/runner/LeekValueManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/leekscript/runner/values/LeekValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/test/TestGeneral.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a05f241

Please sign in to comment.