|
|
|
@ -503,15 +503,22 @@ func TestIfElseExpression(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFunctionLiteralParsing(t *testing.T) {
|
|
|
|
func TestFunctionLiteralParsing(t *testing.T) {
|
|
|
|
input := `fn(x, y) { x + y; }`
|
|
|
|
tests := []struct {
|
|
|
|
|
|
|
|
input string
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{"fn(x, y) { x + y; }"},
|
|
|
|
|
|
|
|
{"fn(x, y) -> x + y;"},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
l := lexer.New(input)
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l := lexer.New(tt.input)
|
|
|
|
p := New(l)
|
|
|
|
p := New(l)
|
|
|
|
program := p.ParseProgram()
|
|
|
|
program := p.ParseProgram()
|
|
|
|
checkParserErrors(t, p)
|
|
|
|
checkParserErrors(t, p)
|
|
|
|
|
|
|
|
|
|
|
|
if len(program.Statements) != 1 {
|
|
|
|
if len(program.Statements) != 1 {
|
|
|
|
t.Fatalf("program.Statements does not contain %d statements. got=%d\n",
|
|
|
|
t.Fatalf("program.Body does not contain %d statements. got=%d\n",
|
|
|
|
1, len(program.Statements))
|
|
|
|
1, len(program.Statements))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -547,6 +554,7 @@ func TestFunctionLiteralParsing(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
testInfixExpression(t, bodyStmt.Expression, "x", "+", "y")
|
|
|
|
testInfixExpression(t, bodyStmt.Expression, "x", "+", "y")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFunctionParameterParsing(t *testing.T) {
|
|
|
|
func TestFunctionParameterParsing(t *testing.T) {
|
|
|
|
|