1
0
forked from Mirror/wren

Define equality on ranges.

This commit is contained in:
Gavin Schulz
2015-01-25 19:50:54 -08:00
parent 44db50e7ef
commit f482a53d0e
2 changed files with 30 additions and 2 deletions

View File

@ -798,7 +798,7 @@ DEF_NATIVE(map_iterate)
DEF_NATIVE(map_remove)
{
if (!validateKey(vm, args, 1)) return PRIM_ERROR;
RETURN_VAL(wrenMapRemoveKey(vm, AS_MAP(args[0]), args[1]));
}
@ -1073,6 +1073,16 @@ DEF_NATIVE(object_instantiate)
RETURN_ERROR("Must provide a class to 'new' to construct.");
}
DEF_NATIVE(range_eqeq)
{
RETURN_BOOL(wrenValuesEqual(args[0], args[1]));
}
DEF_NATIVE(range_bangeq)
{
RETURN_BOOL(!wrenValuesEqual(args[0], args[1]));
}
DEF_NATIVE(range_from)
{
ObjRange* range = AS_RANGE(args[0]);
@ -1508,7 +1518,8 @@ void wrenInitializeCore(WrenVM* vm)
// TODO: More map methods.
vm->rangeClass = AS_CLASS(findGlobal(vm, "Range"));
// TODO: == operator.
NATIVE(vm->rangeClass, "== ", range_eqeq);
NATIVE(vm->rangeClass, "!= ", range_bangeq);
NATIVE(vm->rangeClass, "from", range_from);
NATIVE(vm->rangeClass, "to", range_to);
NATIVE(vm->rangeClass, "min", range_min);

17
test/range/equality.wren Normal file
View File

@ -0,0 +1,17 @@
var a = 2..5
var b = 2..6
var c = 2...5
var d = 2...6
IO.print(a == 2..5) // expect: true
IO.print(a == 2..6) // expect: false
IO.print(c == 2...5) // expect: true
IO.print(c == 2...6) // expect: false
IO.print(b != 2..5) // expect: true
IO.print(b != 2..6) // expect: false
IO.print(d != 2...5) // expect: true
IO.print(d != 2...6) // expect: false
IO.print(a != c) // expect: true
IO.print(b != d) // expect: true