diff options
| author | Bobby <[email protected]> | 2024-03-04 09:07:29 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-03-04 09:07:29 -0500 |
| commit | b52f4e9b4140f482ad966aa354b39cd305a212ec (patch) | |
| tree | baf7e8a78dae0fabca6f24cc10b0fa484771598b /evaluator/evaluator_test.go | |
| parent | c430bfcae07489ad52ae65cadee581be72dd35d1 (diff) | |
| download | mana-b52f4e9b4140f482ad966aa354b39cd305a212ec.tar.xz mana-b52f4e9b4140f482ad966aa354b39cd305a212ec.zip | |
LetStatements
Diffstat (limited to 'evaluator/evaluator_test.go')
| -rw-r--r-- | evaluator/evaluator_test.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index 6553f55..38fed91 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -177,6 +177,10 @@ func TestErrorhandling(t *testing.T) { `, "unknown operator: BOOLEAN + BOOLEAN", }, + { + "foobar", + "identifier not found: foobar", + }, } for _, tt := range tests { @@ -194,11 +198,29 @@ func TestErrorhandling(t *testing.T) { } } +func TestLetStatements(t *testing.T) { + tests := []struct { + input string + expected int64 + } { + {"let a = 5; a;", 5}, + {"let a = 5 * 5; a;", 25}, + {"let a = 5; let b = a; b;", 5}, + {"let a = 5; let b = a; let c = a + b + 5; c;", 15}, + } + + for _, tt := range tests { + testIntegerObject(t, testEval(tt.input), tt.expected) + } +} + func testEval(input string) object.Object { l := lexer.New(input) p := parser.New(l) program := p.ParseProgram() - return Eval(program) + env := object.NewEnvironment() + + return Eval(program, env) } func testIntegerObject(t *testing.T, obj object.Object, expected int64) bool { |
