diff options
| author | Bobby <[email protected]> | 2024-03-29 20:19:31 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-03-29 20:19:31 +0000 |
| commit | cf6dd4b0e5efa1f8041d5570497a5228c737c454 (patch) | |
| tree | c15fa426e3a2c74ff6aa5261452ebadfbb3e0fed /evaluator | |
| parent | c6a3c37f268ba3189a4902b852121e979c70817f (diff) | |
| download | mana-cf6dd4b0e5efa1f8041d5570497a5228c737c454.tar.xz mana-cf6dd4b0e5efa1f8041d5570497a5228c737c454.zip | |
Strings
Diffstat (limited to 'evaluator')
| -rw-r--r-- | evaluator/evaluator.go | 3 | ||||
| -rw-r--r-- | evaluator/evaluator_test.go | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index 87bfc48..9129a98 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -83,6 +83,9 @@ func Eval(node ast.Node, env *object.Environment) object.Object { return &object.Function{Parameters: params, Body: body, Env: env} + case *ast.StringLiteral: + return &object.String{Value: node.Value} + case *ast.ReturnStatement: val := Eval(node.ReturnValue, env) if isError(val) { diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index 75480dc..cf9e320 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -313,3 +313,17 @@ func testNullObject(t *testing.T, obj object.Object) bool { } return true } + +func TestStringLiteral(t *testing.T) { + input := `"Hello World!"` + + evaluated := testEval(input) + str, ok := evaluated.(*object.String) + if !ok { + t.Fatalf("object is not String. got=%T (%+v)", evaluated, evaluated) + } + + if str.Value != "Hello World!" { + t.Errorf("String has wrong value. got=%q", str.Value) + } +} |
