String Implementation is done. Still has TODO that would make for good excercise.
git-svn-id: https://svn.tlawal.org/svn/monkey@57 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
This commit is contained in:
parent
2791a27f1f
commit
2c2c936b29
@ -85,6 +85,9 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
|
|||||||
return args[0]
|
return args[0]
|
||||||
}
|
}
|
||||||
return apply_function(function, args)
|
return apply_function(function, args)
|
||||||
|
|
||||||
|
case *ast.StringLiteral:
|
||||||
|
return &object.String{Value: node.Value }
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -237,6 +237,20 @@ func TestClosures(l_test *testing.T) {
|
|||||||
test_integer_object(l_test, test_eval(input), 4)
|
test_integer_object(l_test, test_eval(input), 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStringLiteral(l_test *testing.T){
|
||||||
|
input := `"Hello, world!"`
|
||||||
|
|
||||||
|
evaluated := test_eval(input)
|
||||||
|
string, ok := evaluated.(*object.String)
|
||||||
|
if !ok {
|
||||||
|
l_test.Fatalf("object is not String, got=%T (%+v)", evaluated, evaluated)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string.Value != "Hello, world!" {
|
||||||
|
l_test.Errorf("String has wrong value, got=%q", string.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
func test_eval(input string) object.Object {
|
func test_eval(input string) object.Object {
|
||||||
l_lexer := lexer.New(input)
|
l_lexer := lexer.New(input)
|
||||||
|
@ -109,4 +109,4 @@ type String struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *String) Type() ObjectType { return STRING_OBJECT }
|
func (s *String) Type() ObjectType { return STRING_OBJECT }
|
||||||
func (s *String) Inspec() string { return s.Value }
|
func (s *String) Inspect() string { return s.Value }
|
||||||
|
Loading…
Reference in New Issue
Block a user