package parser import ( "testing" "code.osinet.fr/fgm/waiig15/ast" "code.osinet.fr/fgm/waiig15/lexer" ) func TestIdentifierExpression(t *testing.T) { const input = "foobar" l := lexer.New(input) p := New(l) program := p.ParseProgram() checkParserErrors(t, p) if len(program.Statements) != 1 { t.Fatalf("program has not enough statements. got=%d", len(program.Statements)) } stmt, ok := program.Statements[0].(*ast.ExpressionStatement) if !ok { t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. Got=%T", program.Statements) } ident, ok := stmt.Expression.(*ast.Identifier) if !ok { t.Fatalf("exp not *ast.Identifier. got=%T", stmt.Expression) } // Why not use input instead of inline strings ? if ident.Value != input { t.Errorf("ident.Value not %s. got=%s", input, ident.Value) } if ident.TokenLiteral() != input { t.Errorf("ident.TokenLiteral not %s. got=%s", input, ident.TokenLiteral()) } }