Return statements

This commit is contained in:
Chuck Smith
2024-01-19 17:50:02 -05:00
parent e6d5567681
commit 7eba7471c8
3 changed files with 70 additions and 7 deletions

View File

@@ -111,6 +111,34 @@ func TestIfElseExpression(t *testing.T) {
}
}
func TestReturnStatements(t *testing.T) {
tests := []struct {
input string
expected int64
}{
{"return 10;", 10},
{"return 10; 9;", 10},
{"return 2 * 5; 9;", 10},
{"9; return 2 * 5; 9;", 10},
{`
if (10 > 1) {
if (10 > 1) {
return 10;
}
return 1;
}
`,
10,
},
}
for _, tt := range tests {
evaluated := testEval(tt.input)
testIntegerObject(t, evaluated, tt.expected)
}
}
func testEval(input string) object.Object {
l := lexer.New(input)
p := parser.New(l)