closures and they can recurse!!!
This commit is contained in:
@@ -845,6 +845,37 @@ func TestParsingHashLiteralsWithExpressions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFunctionLiteralWithName(t *testing.T) {
|
||||
input := `let myFunction = fn() { };`
|
||||
|
||||
l := lexer.New(input)
|
||||
p := New(l)
|
||||
program := p.ParseProgram()
|
||||
checkParserErrors(t, p)
|
||||
|
||||
if len(program.Statements) != 1 {
|
||||
t.Fatalf("program.Body does not contain %d statements. got=%d\n",
|
||||
1, len(program.Statements))
|
||||
}
|
||||
|
||||
stmt, ok := program.Statements[0].(*ast.LetStatement)
|
||||
if !ok {
|
||||
t.Fatalf("program.Statements[0] is not ast.LetStatement. got=%T",
|
||||
program.Statements[0])
|
||||
}
|
||||
|
||||
function, ok := stmt.Value.(*ast.FunctionLiteral)
|
||||
if !ok {
|
||||
t.Fatalf("stmt.Value is not ast.FunctionLiteral. got=%T",
|
||||
stmt.Value)
|
||||
}
|
||||
|
||||
if function.Name != "myFunction" {
|
||||
t.Fatalf("function literal name wrong. want 'myFunction', got=%q\n",
|
||||
function.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func testLetStatement(t *testing.T, s ast.Statement, name string) bool {
|
||||
if s.TokenLiteral() != "let" {
|
||||
t.Errorf("s.TokenLiteral not 'let'. got=%q", s.TokenLiteral())
|
||||
|
||||
Reference in New Issue
Block a user