Skip to content

Commit

Permalink
more Object tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrtronium committed Apr 30, 2020
1 parent c6bf5c0 commit 7fb9128
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ func TestObjectMethods(t *testing.T) {
// manyProtosToRemove is an object that has many protos to test that
// removeAllProtos succeeds.
"manyProtosToRemove": vm.ObjectWith(nil, []*iolang.Object{vm.BaseObject, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil}, nil, nil),
// manyProtosToRemoveOne is an object that has many protos to test
// that removeProto succeeds.
"manyProtosToRemoveOne": vm.ObjectWith(nil, []*iolang.Object{vm.Nil, vm.BaseObject, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil, vm.Nil}, nil, nil),
// manyProtosNotToRemove is an object that has many protos to test
// that removeProto removes none of them.
"manyProtosNotToRemove": vm.ObjectWith(nil, []*iolang.Object{vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject}, nil, nil),
}
vm.SetSlot(vm.Lobby, "testValues", vm.NewObject(config))
cases := map[string]map[string]testutils.SourceTestCase{
Expand Down Expand Up @@ -680,6 +686,18 @@ func TestObjectMethods(t *testing.T) {
"none": {Source: `Object clone removeAllSlots`, Pass: testutils.PassSuccess()},
"one": {Source: `testValues slotsObj := Object clone do(x := 0); testValues slotsObj clone do(x := 1) removeAllSlots x`, Pass: testutils.PassEqual(vm.NewNumber(0))},
},
"removeProto": {
"none": {Source: `Object getSlot("removeProto") performOn(Object clone removeAllProtos)`, Pass: testutils.PassSuccess()},
"one": {Source: `Object getSlot("protos") performOn(Object clone removeProto(nil))`, Pass: testutils.PassEqual(vm.NewList(vm.BaseObject))},
"oneRemove": {Source: `Object getSlot("protos") performOn(Object clone removeProto(Object))`, Pass: testutils.PassEqual(vm.NewList())},
"ten": {Source: `Object getSlot("protos") performOn(testValues manyProtosNotToRemove removeProto(nil))`, Pass: testutils.PassEqual(vm.NewList(vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject, vm.BaseObject))},
"tenRemove": {Source: `Object getSlot("protos") performOn(testValues manyProtosToRemoveOne removeProto(nil))`, Pass: testutils.PassEqual(vm.NewList(vm.BaseObject))},
},
"removeSlot": {
"none": {Source: `Object clone removeSlot("nothing")`, Pass: testutils.PassSuccess()},
"one": {Source: `testValues slotsObj := Object clone do(x := 0); testValues slotsObj clone do(x := 1) removeSlot("y") x`, Pass: testutils.PassEqual(vm.NewNumber(1))},
"oneRemove": {Source: `testValues slotsObj := Object clone do(x := 0); testValues slotsObj clone do(x := 1) removeSlot("x") x`, Pass: testutils.PassEqual(vm.NewNumber(0))},
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit 7fb9128

Please sign in to comment.