optimizations
This commit is contained in:
@@ -126,6 +126,37 @@ func TestIntegerLiteralExpression(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloatLiteralExpression(t *testing.T) {
|
||||
input := "2.5;"
|
||||
|
||||
l := lexer.New(input)
|
||||
p := New("<test>", 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[0])
|
||||
}
|
||||
|
||||
literal, ok := stmt.Expression.(*ast.FloatLiteral)
|
||||
if !ok {
|
||||
t.Fatalf("exp not *ast.FloatLiteral. got=%T", stmt.Expression)
|
||||
}
|
||||
if literal.Value != 2.5 {
|
||||
t.Errorf("literal.Value not %f. got=%f", 2.5, literal.Value)
|
||||
}
|
||||
if literal.TokenLiteral() != "2.5" {
|
||||
t.Errorf("literal.TokenLiteral not %s. got=%s", "2.5",
|
||||
literal.TokenLiteral())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsingPrefixExpressions(t *testing.T) {
|
||||
prefixTests := []struct {
|
||||
input string
|
||||
|
||||
Reference in New Issue
Block a user