Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiban committed Apr 2, 2022
1 parent a5dd91e commit 9830dd2
Showing 1 changed file with 148 additions and 10 deletions.
158 changes: 148 additions & 10 deletions engine/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3871,6 +3871,45 @@ func TestState_WriteTerm(t *testing.T) {
assert.Equal(t, ops, m.ops)
assert.Equal(t, 1200, m.priority)
})

t.Run("invalid atom", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "quoted",
Args: []Term{Atom("meh")},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "quoted",
Args: []Term{Atom("meh")},
}), err)
})

t.Run("variable", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "quoted",
Args: []Term{Variable("Bool")},
}), Success, nil).Force(context.Background())
assert.Equal(t, ErrInstantiation, err)
})

t.Run("not an atom", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "quoted",
Args: []Term{Integer(0)},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "quoted",
Args: []Term{Integer(0)},
}), err)
})
})

t.Run("ignore_ops", func(t *testing.T) {
Expand Down Expand Up @@ -3904,7 +3943,45 @@ func TestState_WriteTerm(t *testing.T) {

assert.Nil(t, m.ops)
assert.Equal(t, 1200, m.priority)
})

t.Run("invalid atom", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "ignore_ops",
Args: []Term{Atom("meh")},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "ignore_ops",
Args: []Term{Atom("meh")},
}), err)
})

t.Run("variable", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "ignore_ops",
Args: []Term{Variable("Bool")},
}), Success, nil).Force(context.Background())
assert.Equal(t, ErrInstantiation, err)
})

t.Run("not an atom", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "ignore_ops",
Args: []Term{Integer(0)},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "ignore_ops",
Args: []Term{Integer(0)},
}), err)
})
})

Expand Down Expand Up @@ -4036,6 +4113,45 @@ func TestState_WriteTerm(t *testing.T) {
assert.True(t, m.numberVars)
assert.Equal(t, 1200, m.priority)
})

t.Run("invalid atom", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "numbervars",
Args: []Term{Atom("meh")},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "numbervars",
Args: []Term{Atom("meh")},
}), err)
})

t.Run("variable", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "numbervars",
Args: []Term{Variable("Bool")},
}), Success, nil).Force(context.Background())
assert.Equal(t, ErrInstantiation, err)
})

t.Run("not an atom", func(t *testing.T) {
var m mockTerm
defer m.AssertExpectations(t)

_, err := state.WriteTerm(s, &m, List(&Compound{
Functor: "numbervars",
Args: []Term{Integer(0)},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "numbervars",
Args: []Term{Integer(0)},
}), err)
})
})

t.Run("streamOrAlias is a variable", func(t *testing.T) {
Expand Down Expand Up @@ -4078,16 +4194,38 @@ func TestState_WriteTerm(t *testing.T) {
})

t.Run("an element E of the Options list is neither a variable nor a valid write-option", func(t *testing.T) {
var state State
ok, err := state.WriteTerm(s, Atom("foo"), List(&Compound{
Functor: "unknown",
Args: []Term{Atom("option")},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "unknown",
Args: []Term{Atom("option")},
}), err)
assert.False(t, ok)
t.Run("atom", func(t *testing.T) {
var state State
ok, err := state.WriteTerm(s, Atom("foo"), List(Atom("option")), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(Atom("option")), err)
assert.False(t, ok)
})

t.Run("compound of arity n != 1", func(t *testing.T) {
var state State
ok, err := state.WriteTerm(s, Atom("foo"), List(&Compound{
Functor: "unknown",
Args: []Term{Atom("foo"), Atom("bar")},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "unknown",
Args: []Term{Atom("foo"), Atom("bar")},
}), err)
assert.False(t, ok)
})

t.Run("unknown option of a boolean argument", func(t *testing.T) {
var state State
ok, err := state.WriteTerm(s, Atom("foo"), List(&Compound{
Functor: "unknown",
Args: []Term{Atom("true")},
}), Success, nil).Force(context.Background())
assert.Equal(t, domainErrorWriteOption(&Compound{
Functor: "unknown",
Args: []Term{Atom("true")},
}), err)
assert.False(t, ok)
})
})

t.Run("streamOrAlias is not associated with an open stream", func(t *testing.T) {
Expand Down

0 comments on commit 9830dd2

Please sign in to comment.