diff options
Diffstat (limited to 'parser/parser_test.go')
| -rw-r--r-- | parser/parser_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/parser/parser_test.go b/parser/parser_test.go index 08539b7..3a574a7 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -772,3 +772,22 @@ func TestCallExpressionParsing(t *testing.T) { testInfixExpression(t, exp.Arguments[1], 2, "*", 3) testInfixExpression(t, exp.Arguments[2], 4, "+", 5) } + +func TestStringLiteralExpression(t *testing.T) { + input := `"hello world";` + + var l *lexer.Lexer = lexer.New(input) + var p *Parser = New(l) + var program *ast.Program = p.ParseProgram() + checkParserErrors(t, p) + + stmt := program.Statements[0].(*ast.ExpressionStatement) + literal, ok := stmt.Expression.(*ast.StringLiteral) + if !ok { + t.Fatalf("exp not *ast.StringLiteral. got=%T", stmt.Expression) + } + + if literal.Value != "hello world" { + t.Errorf("literal.Value not %q. got=%q", "hello world", literal.Value) + } +} |
