muScript: support contains on lists
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
60fdea1457
commit
5a1329b884
|
@ -121,7 +121,8 @@ public class StandardLib {
|
|||
|
||||
public static DBool contains(DList args) {
|
||||
if (args.size() != 2) throw new IllegalArgumentException("Invalid number of arguments for contains: expected 2 but got " + args.size());
|
||||
return of(args.get(0).asString().getValue().contains(args.get(1).asString().getValue()));
|
||||
if (args.get(0) instanceof DList list) return of(list.getValue().contains(args.get(1)));
|
||||
else return of(args.get(0).asString().getValue().contains(args.get(1).asString().getValue()));
|
||||
}
|
||||
|
||||
public static DString replace(DList args) {
|
||||
|
|
|
@ -12,4 +12,12 @@ class ListTest {
|
|||
assertTrue(bool("list[1] < 3"));
|
||||
assertTrue(bool("list[2] || list[0] == '3true'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void contains() {
|
||||
assertFalse(bool("numbers::contains(',')"));
|
||||
assertFalse(bool("numbers::contains('1,')"));
|
||||
assertFalse(bool("numbers::contains('1')"));
|
||||
assertTrue(bool("numbers::contains(1)"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue