|
@@ -0,0 +1,40 @@
|
|
|
+package parser
|
|
|
+
|
|
|
+import (
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ "code.osinet.fr/fgm/waiig15/ast"
|
|
|
+ "code.osinet.fr/fgm/waiig15/lexer"
|
|
|
+)
|
|
|
+
|
|
|
+func TestIntegerLiteralExpression(t *testing.T) {
|
|
|
+ input := "5;"
|
|
|
+
|
|
|
+ l := lexer.New(input)
|
|
|
+ p := New(l)
|
|
|
+
|
|
|
+ program := p.ParseProgram()
|
|
|
+ checkParserErrors(t, p)
|
|
|
+
|
|
|
+ if len(program.Statements) != 1 {
|
|
|
+ t.Fatalf("program does not have 1 statement. 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[0])
|
|
|
+ }
|
|
|
+
|
|
|
+ literal, ok := stmt.Expression.(*ast.IntegerLiteral)
|
|
|
+ if !ok {
|
|
|
+ t.Fatalf("expression not *ast.IntegerLiteral. got=%T",
|
|
|
+ stmt.Expression)
|
|
|
+ }
|
|
|
+
|
|
|
+ if literal.Value != 5 {
|
|
|
+ t.Errorf("literal.Value not %s. got=%s", "5",
|
|
|
+ literal.TokenLiteral())
|
|
|
+ }
|
|
|
+}
|