diff options
Diffstat (limited to 'evaluator/evaluator_test.go')
| -rw-r--r-- | evaluator/evaluator_test.go | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index cd1edb1..aa1833a 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -18,8 +18,42 @@ func TestEvalIntegerExpression(t *testing.T) { } for _, tt := range tests { - evalated := testEval(tt.input) - testIntegerObject(t, evalated, tt.expected) + evaluated := testEval(tt.input) + testIntegerObject(t, evaluated, tt.expected) + } +} + +func TestEvalBooleanExpression(t *testing.T) { + tests := []struct { + input string + expected bool + }{ + {"true", true}, + {"false", false}, + } + + for _, tt := range tests { + evaluated := testEval(tt.input) + testBooleanObject(t, evaluated, tt.expected) + } +} + +func TestBangOperator(t *testing.T) { + tests := []struct { + input string + expected bool + }{ + {"!true", false}, + {"!false", true}, + {"!5", false}, + {"!!true", true}, + {"!!false", false}, + {"!!5", true}, + } + + for _, tt := range tests { + evaluated := testEval(tt.input) + testBooleanObject(t, evaluated, tt.expected) } } @@ -42,3 +76,16 @@ func testIntegerObject(t *testing.T, obj object.Object, expected int64) bool { } return true } + +func testBooleanObject(t *testing.T, obj object.Object, expected bool) bool { + result, ok := obj.(*object.Boolean) + if !ok { + t.Errorf("object is not Boolean. got=%T (%+v)", obj, obj) + return false + } + if result.Value != expected { + t.Errorf("object has wrong value. got=%t, want=%t", result.Value, expected) + return false + } + return true +} |
