Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiban committed Jan 29, 2023
1 parent 673c5a2 commit 48771d9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions engine/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,7 @@ func TestFindAll(t *testing.T) {
ok bool
err error
env map[Variable]Term
mem int64
}{
// 8.10.1.4 Examples
{title: "1", template: x, goal: atomSemiColon.Apply(atomEqual.Apply(x, Integer(1)), atomEqual.Apply(x, Integer(2))), instances: s, ok: true, env: map[Variable]Term{
Expand All @@ -2031,6 +2032,15 @@ func TestFindAll(t *testing.T) {

// 8.10.1.3 Errors
{title: "c", template: x, goal: atomSemiColon.Apply(atomEqual.Apply(x, Integer(1)), atomEqual.Apply(x, Integer(2))), instances: NewAtom("foo"), err: typeError(validTypeList, NewAtom("foo"), nil)},

{
title: "out of memory",
template: tuple(NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable()),
goal: atomEqual.Apply(x, Integer(1)),
instances: s,
err: Exception{term: atomError.Apply(atomResourceError.Apply(resourceMemory.Term()), atomSlash.Apply(atomEqual, Integer(2)))},
mem: 1,
},
}

var vm VM
Expand All @@ -2048,6 +2058,8 @@ func TestFindAll(t *testing.T) {

for _, tt := range tests {
t.Run(tt.title, func(t *testing.T) {
defer setMemFree(tt.mem)()

ok, err := FindAll(&vm, tt.template, tt.goal, tt.instances, func(env *Env) *Promise {
for k, v := range tt.env {
_, ok := env.Unify(v, k)
Expand Down Expand Up @@ -5444,6 +5456,21 @@ func TestClause(t *testing.T) {
assert.Equal(t, typeError(validTypeCallable, Integer(0), nil), err)
assert.False(t, ok)
})

t.Run("out of memory", func(t *testing.T) {
defer setMemFree(1)()

vm := VM{
procedures: map[procedureIndicator]procedure{
{name: NewAtom("green"), arity: 1}: &userDefined{public: true, clauses: []clause{
{raw: NewAtom("green").Apply(NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable(), NewVariable())},
}},
},
}
ok, err := Clause(&vm, NewAtom("green").Apply(NewVariable()), NewVariable(), Success, nil).Force(context.Background())
assert.Equal(t, resourceError(resourceMemory, nil), err)
assert.False(t, ok)
})
}

func TestAtomLength(t *testing.T) {
Expand Down

0 comments on commit 48771d9

Please sign in to comment.