Skip to content

Commit

Permalink
multiple fixes on sets
Browse files Browse the repository at this point in the history
  • Loading branch information
5pilow committed Oct 4, 2023
1 parent 685b16e commit 5f10f25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/leekscript/runner/AI.java
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ public boolean bool(Object value) {
return ((LegacyArrayLeekValue) value).size() != 0;
} else if (value instanceof ArrayLeekValue) {
return ((ArrayLeekValue) value).size() != 0;
} else if (value instanceof SetLeekValue set) {
return set.size() != 0;
} else if (value instanceof IntervalLeekValue) {
return !((IntervalLeekValue) value).intervalIsEmpty(this);
} else if (value instanceof MapLeekValue) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/leekscript/runner/classes/StandardClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import leekscript.runner.values.ArrayLeekValue;
import leekscript.runner.values.ClassLeekValue;
import leekscript.runner.values.FunctionLeekValue;
import leekscript.runner.values.IntervalLeekValue;
import leekscript.runner.values.LegacyArrayLeekValue;
import leekscript.runner.values.MapLeekValue;
import leekscript.runner.values.ObjectLeekValue;
import leekscript.runner.values.SetLeekValue;
import leekscript.common.Type;

public class StandardClass {
Expand All @@ -21,6 +23,8 @@ public static Type getType(AI ai, Object value) throws LeekRunException {
if (value instanceof LegacyArrayLeekValue || value instanceof ArrayLeekValue) return Type.ARRAY;
if (value instanceof MapLeekValue) return Type.MAP;
if (value instanceof String) return Type.STRING;
if (value instanceof SetLeekValue) return Type.SET;
if (value instanceof IntervalLeekValue) return Type.INTERVAL;
if (value instanceof ObjectLeekValue o) return o.clazz.getType();
if (value instanceof NativeObjectLeekValue o) return ai.classOf(o).getType();
if (value instanceof ClassLeekValue) return Type.CLASS;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/test/TestSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public void run() throws Exception {
code_strict_v4_("Set i = <1, 2>; return i instanceof Set").equals("true");
code_strict_v4_("Set<integer> i = <1, 2>; return i instanceof Set").equals("true");

section("Set operator !");
code("var i = <> return !i").equals("true");
code("var i = <1> return !i").equals("false");

section("Set.setPut()");
code("var i = <1, 2> setPut(i, 3) return i").debug().equals("<1, 2, 3>");
code("var i = <1, 2> setPut(i, 3) setPut(i, 4) return i").equals("<1, 2, 3, 4>");
Expand Down

0 comments on commit 5f10f25

Please sign in to comment.