diff --git a/x/logic/predicate/block_test.go b/x/logic/predicate/block_test.go index 24248045..9e9de15e 100644 --- a/x/logic/predicate/block_test.go +++ b/x/logic/predicate/block_test.go @@ -38,13 +38,13 @@ func TestBlock(t *testing.T) { ctx := sdk.NewContext(stateStore, tc.header, false, log.NewNopLogger()) Convey("and a vm", func() { - vm := testutil.NewVMMust(ctx) - vm.Register1(engine.NewAtom("block_height"), BlockHeight) - vm.Register1(engine.NewAtom("block_time"), BlockTime) - testutil.CompileMust(ctx, vm, fmt.Sprintf("test :- %s.", tc.implication)) + interpreter := testutil.NewInterpreterMust(ctx) + interpreter.Register1(engine.NewAtom("block_height"), BlockHeight) + interpreter.Register1(engine.NewAtom("block_time"), BlockTime) + testutil.CompileMust(ctx, interpreter, fmt.Sprintf("test :- %s.", tc.implication)) Convey("When the predicate is called", func() { - ok, err := vm.Arrive(engine.NewAtom("test"), []engine.Term{}, engine.Success, nil).Force(ctx) + ok, err := interpreter.Arrive(engine.NewAtom("test"), []engine.Term{}, engine.Success, nil).Force(ctx) Convey("Then the result should be true and there should be no error", func() { So(err, ShouldBeNil) diff --git a/x/logic/predicate/chain_test.go b/x/logic/predicate/chain_test.go index 1223c46e..4436d19e 100644 --- a/x/logic/predicate/chain_test.go +++ b/x/logic/predicate/chain_test.go @@ -33,13 +33,13 @@ func TestChainID(t *testing.T) { stateStore := store.NewCommitMultiStore(db) ctx := sdk.NewContext(stateStore, tc.header, false, log.NewNopLogger()) - Convey("and a vm", func() { - vm := testutil.NewVMMust(ctx) - vm.Register1(engine.NewAtom("chain_id"), ChainID) - testutil.CompileMust(ctx, vm, fmt.Sprintf("test :- %s.", tc.implication)) + Convey("and an interpreter", func() { + interpreter := testutil.NewInterpreterMust(ctx) + interpreter.Register1(engine.NewAtom("chain_id"), ChainID) + testutil.CompileMust(ctx, interpreter, fmt.Sprintf("test :- %s.", tc.implication)) Convey("When the predicate is called", func() { - ok, err := vm.Arrive(engine.NewAtom("test"), []engine.Term{}, engine.Success, nil).Force(ctx) + ok, err := interpreter.Arrive(engine.NewAtom("test"), []engine.Term{}, engine.Success, nil).Force(ctx) Convey("Then the result should be true and there should be no error", func() { So(err, ShouldBeNil) diff --git a/x/logic/testutil/logic.go b/x/logic/testutil/logic.go index 90cfbe4d..d8699836 100644 --- a/x/logic/testutil/logic.go +++ b/x/logic/testutil/logic.go @@ -3,18 +3,19 @@ package testutil import ( "context" + "github.com/ichiban/prolog" "github.com/ichiban/prolog/engine" ) -// NewVMMust returns a new VM with the given context or panics if it fails. -// The VM is configured with minimal settings to support testing. -func NewVMMust(ctx context.Context) (vm *engine.VM) { - vm = &engine.VM{} - vm.Register3(engine.NewAtom("op"), engine.Op) - vm.Register3(engine.NewAtom("compare"), engine.Compare) - vm.Register2(engine.NewAtom("="), engine.Unify) +// NewInterpreterMust returns a new Interpreter with the given context or panics if it fails. +// The Interpreter is configured with minimal settings to support testing. +func NewInterpreterMust(ctx context.Context) (interpreter *prolog.Interpreter) { + interpreter = &prolog.Interpreter{} + interpreter.Register3(engine.NewAtom("op"), engine.Op) + interpreter.Register3(engine.NewAtom("compare"), engine.Compare) + interpreter.Register2(engine.NewAtom("="), engine.Unify) - err := vm.Compile(ctx, ` + err := interpreter.Compile(ctx, ` :-(op(1200, xfx, ':-')). :-(op(1000, xfy, ',')). :-(op(700, xfx, '==')). @@ -30,8 +31,8 @@ func NewVMMust(ctx context.Context) (vm *engine.VM) { // CompileMust compiles the given source code and panics if it fails. // This is a convenience function for testing. -func CompileMust(ctx context.Context, vm *engine.VM, s string, args ...interface{}) { - err := vm.Compile(ctx, s, args...) +func CompileMust(ctx context.Context, interpreter *prolog.Interpreter, s string, args ...interface{}) { + err := interpreter.Compile(ctx, s, args...) if err != nil { panic(err) }