Spelling corrections
Interpreter can now evaluate Booleans git-svn-id: https://svn.tlawal.org/svn/monkey@45 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
This commit is contained in:
parent
1b97196361
commit
886a16e706
@ -17,6 +17,9 @@ func Eval(node ast.Node) object.Object {
|
||||
// Expressions
|
||||
case *ast.IntegerLiteral:
|
||||
return &object.Integer{Value: node.Value}
|
||||
|
||||
case *ast.Boolean:
|
||||
return &object.Boolean{Value: node.Value}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -22,6 +22,22 @@ func TestEvalIntegerExpression(l_test *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalBooleanExpression(l_test *testing.T){
|
||||
tests := []struct {
|
||||
input string
|
||||
expected bool
|
||||
}{
|
||||
{"true", true},
|
||||
{"false", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests{
|
||||
evaluated := test_eval(tt.input)
|
||||
test_boolean_object(l_test, evaluated, tt.expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Helpers
|
||||
func test_eval(input string) object.Object {
|
||||
l_lexer := lexer.New(input)
|
||||
@ -43,3 +59,17 @@ func test_integer_object(l_test *testing.T, l_object object.Object, expected int
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func test_boolean_object(l_test *testing.T, l_object object.Object, expected bool)bool {
|
||||
result, ok := l_object.(*object.Boolean)
|
||||
if !ok {
|
||||
l_test.Errorf("object is not Boolean, got=%T (%+v)", l_object, l_object)
|
||||
return false
|
||||
}
|
||||
|
||||
if result.Value != expected {
|
||||
l_test.Errorf("object has wrong value, got=%T, want=%t", result.Value, expected)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func (b *Boolean) Type() ObjectType {
|
||||
return BOOLEAN_OBJECT
|
||||
}
|
||||
|
||||
func (b *Boolean) Inpect() string {
|
||||
func (b *Boolean) Inspect() string {
|
||||
return fmt.Sprintf("%t", b.Value)
|
||||
}
|
||||
|
||||
@ -48,6 +48,6 @@ func (n *Null) Type() ObjectType {
|
||||
return NULL_OBJECT
|
||||
}
|
||||
|
||||
func (n *Null) Inpect() string {
|
||||
func (n *Null) Inspect() string {
|
||||
return "null"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user