package parser import ( "testing" "code.osinet.fr/fgm/waiig15/lexer" "code.osinet.fr/fgm/waiig15/ast" ) func TestReturnStatements(t *testing.T) { // Try removing the ident, the =, or both, to get human-readable errors. input := ` return 5; return 10; return 993322; ` l := lexer.New(input) p := New(l) program := p.ParseProgram() checkParserErrors(t, p) if program == nil { t.Fatalf("ParseProgram() returned nil.") } if len(program.Statements) != 3 { t.Fatalf("program.Statements does not contain 3 statements, got=%d", len(program.Statements)) } for _, stmt := range program.Statements { // Statement is an interface, we need a concrete type for the value, and // our test input only contains Let statements. returnStmt, ok := stmt.(*ast.ReturnStatement) if !ok { t.Errorf("s not *ast.ReturnStatement{}, got=%T", stmt) continue } if returnStmt.TokenLiteral() != "return" { t.Errorf("s.TokenLiteral not 'return', got=%q", stmt.TokenLiteral()) } } }