|
|
@@ -22,6 +22,21 @@ func TestEvalIntegerExpression(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+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 testIntegerObject(t *testing.T, obj object.Object, expected int64) bool {
|
|
|
result, ok := obj.(*object.Integer)
|
|
|
if !ok {
|
|
|
@@ -34,7 +49,18 @@ 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
|
|
|
+}
|
|
|
func testEval(input string) object.Object {
|
|
|
l := lexer.New(input)
|
|
|
p := parser.New(l)
|