Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
Problem: interpteret evalPrefixExpression is untested
Browse files Browse the repository at this point in the history
Solution: add TestPrefixExpression that covers evalPrefixExpression.

Increases test coverage.

Updates #25
Signed-off-by: Iskander Sharipov <[email protected]>
  • Loading branch information
quasilyte authored and AlekSi committed Oct 3, 2018
1 parent de72af0 commit 5198cfb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ func TestInfixExpression(t *testing.T) {
}
}

func TestPrefixExpression(t *testing.T) {
for input, expected := range map[string]bool{
// Since we already tested infix `==`, use it here
// to have a nice way to check for different result types.
`-(10) == -10`: true,
`!true == false`: true,
`!!true == true`: true,
`!false == true`: true,
`-(10) == 10`: false,
`!true == true`: false,
} {
t.Run(input, func(t *testing.T) {
gofuzz.AddDataToCorpus("interpreter", []byte(input))

actual, res := eval(t, input)
require.IsType(t, &objects.Boolean{}, actual)
assert.Equal(t, expected, actual.(*objects.Boolean).Value)
assert.Empty(t, res.String())
})
}
}

func TestLen(t *testing.T) {
for input, expected := range map[string]int{
`len("FizzBuzz")`: 8,
Expand Down

0 comments on commit 5198cfb

Please sign in to comment.