From e452a2ec377334144aa9204514b8ad4bd2c2254e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 24 Aug 2022 14:27:07 +0200 Subject: more cleanup --- ast/modify_test.go | 3 +- evaluator/evaluator_test.go | 27 +++---- evaluator/macro_expansion_test.go | 9 +-- evaluator/quote_unquote_test.go | 12 +-- lexer/lexer_test.go | 6 +- parser/parser_test.go | 153 +++++++++++++------------------------- parser/parser_tracing.go | 3 +- 7 files changed, 72 insertions(+), 141 deletions(-) diff --git a/ast/modify_test.go b/ast/modify_test.go index 20fe907..6a96539 100644 --- a/ast/modify_test.go +++ b/ast/modify_test.go @@ -125,8 +125,7 @@ func TestModify(t *testing.T) { equal := reflect.DeepEqual(modified, tt.expected) if !equal { - t.Errorf("not equal. got=%#v, want=%#v", - modified, tt.expected) + t.Errorf("not equal. got=%#v, want=%#v", modified, tt.expected) } } diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index 606078a..fd1cef2 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -233,14 +233,12 @@ if (10 > 1) { errObj, ok := evaluated.(*object.Error) if !ok { - t.Errorf("no error object returned. got=%T(%+v)", - evaluated, evaluated) + t.Errorf("no error object returned. got=%T(%+v)", evaluated, evaluated) continue } if errObj.Message != tt.expectedMessage { - t.Errorf("wrong error message. expected=%q, got=%q", - tt.expectedMessage, errObj.Message) + t.Errorf("wrong error message. expected=%q, got=%q", tt.expectedMessage, errObj.Message) } } } @@ -271,8 +269,7 @@ func TestFunctionObject(t *testing.T) { } if len(fn.Parameters) != 1 { - t.Fatalf("function has wrong parameters. Parameters=%+v", - fn.Parameters) + t.Fatalf("function has wrong parameters. Parameters=%+v", fn.Parameters) } if fn.Parameters[0].String() != "x" { @@ -397,13 +394,11 @@ func TestBuiltinFunctions(t *testing.T) { case string: errObj, ok := evaluated.(*object.Error) if !ok { - t.Errorf("object is not Error. got=%T (%+v)", - evaluated, evaluated) + t.Errorf("object is not Error. got=%T (%+v)", evaluated, evaluated) continue } if errObj.Message != expected { - t.Errorf("wrong error message. expected=%q, got=%q", - expected, errObj.Message) + t.Errorf("wrong error message. expected=%q, got=%q", expected, errObj.Message) } case []int: array, ok := evaluated.(*object.Array) @@ -413,8 +408,7 @@ func TestBuiltinFunctions(t *testing.T) { } if len(array.Elements) != len(expected) { - t.Errorf("wrong num of elements. want=%d, got=%d", - len(expected), len(array.Elements)) + t.Errorf("wrong num of elements. want=%d, got=%d", len(expected), len(array.Elements)) continue } @@ -435,8 +429,7 @@ func TestArrayLiterals(t *testing.T) { } if len(result.Elements) != 3 { - t.Fatalf("array has wrong num of elements. got=%d", - len(result.Elements)) + t.Fatalf("array has wrong num of elements. got=%d", len(result.Elements)) } testIntegerObject(t, result.Elements[0], 1) @@ -605,8 +598,7 @@ func testIntegerObject(t *testing.T, obj object.Object, expected int64) bool { return false } if result.Value != expected { - t.Errorf("object has wrong value. got=%d, want=%d", - result.Value, expected) + t.Errorf("object has wrong value. got=%d, want=%d", result.Value, expected) return false } @@ -621,8 +613,7 @@ func testBooleanObject(t *testing.T, obj object.Object, expected bool) bool { return false } if result.Value != expected { - t.Errorf("object has wrong value. got=%t, want=%t", - result.Value, expected) + t.Errorf("object has wrong value. got=%t, want=%t", result.Value, expected) return false } return true diff --git a/evaluator/macro_expansion_test.go b/evaluator/macro_expansion_test.go index 9d4f3d1..df0042d 100644 --- a/evaluator/macro_expansion_test.go +++ b/evaluator/macro_expansion_test.go @@ -22,8 +22,7 @@ let mymacro = macro(x, y) { x + y; }; DefineMacros(program, env) if len(program.Statements) != 2 { - t.Fatalf("Wrong number of statements. got=%d", - len(program.Statements)) + t.Fatalf("Wrong number of statements. got=%d", len(program.Statements)) } _, ok := env.Get("number") @@ -46,8 +45,7 @@ let mymacro = macro(x, y) { x + y; }; } if len(macro.Parameters) != 2 { - t.Fatalf("Wrong number of macro parameters. got=%d", - len(macro.Parameters)) + t.Fatalf("Wrong number of macro parameters. got=%d", len(macro.Parameters)) } if macro.Parameters[0].String() != "x" { @@ -118,8 +116,7 @@ func TestExpandMacros(t *testing.T) { expanded := ExpandMacros(program, env) if expanded.String() != expected.String() { - t.Errorf("not equal. want=%q, got=%q", - expected.String(), expanded.String()) + t.Errorf("not equal. want=%q, got=%q", expected.String(), expanded.String()) } } } diff --git a/evaluator/quote_unquote_test.go b/evaluator/quote_unquote_test.go index 9b0de5b..edcff16 100644 --- a/evaluator/quote_unquote_test.go +++ b/evaluator/quote_unquote_test.go @@ -33,8 +33,7 @@ func TestQuote(t *testing.T) { evaluated := testEval(t, tt.input) quote, ok := evaluated.(*object.Quote) if !ok { - t.Fatalf("expected *object.Quote. got=%T (%+v)", - evaluated, evaluated) + t.Fatalf("expected *object.Quote. got=%T (%+v)", evaluated, evaluated) } if quote.Node == nil { @@ -42,8 +41,7 @@ func TestQuote(t *testing.T) { } if quote.Node.String() != tt.expected { - t.Errorf("not equal. got=%q, want=%q", - quote.Node.String(), tt.expected) + t.Errorf("not equal. got=%q, want=%q", quote.Node.String(), tt.expected) } } } @@ -102,8 +100,7 @@ func TestQuoteUnquote(t *testing.T) { evaluated := testEval(t, tt.input) quote, ok := evaluated.(*object.Quote) if !ok { - t.Fatalf("expected *object.Quote. got=%T (%+v)", - evaluated, evaluated) + t.Fatalf("expected *object.Quote. got=%T (%+v)", evaluated, evaluated) } if quote.Node == nil { @@ -111,8 +108,7 @@ func TestQuoteUnquote(t *testing.T) { } if quote.Node.String() != tt.expected { - t.Errorf("not equal. got=%q, want=%q", - quote.Node.String(), tt.expected) + t.Errorf("not equal. got=%q, want=%q", quote.Node.String(), tt.expected) } } } diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index d66ad73..5818dbe 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -145,13 +145,11 @@ macro(x, y) { x + y; }; tok := l.NextToken() if tok.Type != tt.expectedType { - t.Fatalf("tests[%d] - tokentype wrong. expected=%q, got=%q", - i, tt.expectedType, tok.Type) + t.Fatalf("tests[%d] - tokentype wrong. expected=%q, got=%q", i, tt.expectedType, tok.Type) } if tok.Literal != tt.expectedLiteral { - t.Fatalf("tests[%d] - literal wrong. expected=%q, got=%q", - i, tt.expectedLiteral, tok.Literal) + t.Fatalf("tests[%d] - literal wrong. expected=%q, got=%q", i, tt.expectedLiteral, tok.Literal) } } } diff --git a/parser/parser_test.go b/parser/parser_test.go index ed019af..a7f9775 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -26,8 +26,7 @@ func TestLetStatements(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Statements does not contain 1 statements. got=%d", - len(program.Statements)) + t.Fatalf("program.Statements does not contain 1 statements. got=%d", len(program.Statements)) } stmt := program.Statements[0] @@ -59,8 +58,7 @@ func TestReturnStatements(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Statements does not contain 1 statements. got=%d", - len(program.Statements)) + t.Fatalf("program.Statements does not contain 1 statements. got=%d", len(program.Statements)) } stmt := program.Statements[0] @@ -69,8 +67,7 @@ func TestReturnStatements(t *testing.T) { t.Fatalf("stmt not *ast.returnStatement. got=%T", stmt) } if returnStmt.TokenLiteral() != "return" { - t.Fatalf("returnStmt.TokenLiteral not 'return', got %q", - returnStmt.TokenLiteral()) + t.Fatalf("returnStmt.TokenLiteral not 'return', got %q", returnStmt.TokenLiteral()) } if testLiteralExpression(t, returnStmt.ReturnValue, tt.expectedValue) { return @@ -87,13 +84,11 @@ func TestIdentifierExpression(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program has not enough statements. got=%d", - len(program.Statements)) + 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } ident, ok := stmt.Expression.(*ast.Identifier) @@ -104,8 +99,7 @@ func TestIdentifierExpression(t *testing.T) { t.Errorf("ident.Value not %s. got=%s", "foobar", ident.Value) } if ident.TokenLiteral() != "foobar" { - t.Errorf("ident.TokenLiteral not %s. got=%s", "foobar", - ident.TokenLiteral()) + t.Errorf("ident.TokenLiteral not %s. got=%s", "foobar", ident.TokenLiteral()) } } @@ -118,13 +112,11 @@ func TestIntegerLiteralExpression(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program has not enough statements. got=%d", - len(program.Statements)) + 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } literal, ok := stmt.Expression.(*ast.IntegerLiteral) @@ -135,8 +127,7 @@ func TestIntegerLiteralExpression(t *testing.T) { t.Errorf("literal.Value not %d. got=%d", 5, literal.Value) } if literal.TokenLiteral() != "5" { - t.Errorf("literal.TokenLiteral not %s. got=%s", "5", - literal.TokenLiteral()) + t.Errorf("literal.TokenLiteral not %s. got=%s", "5", literal.TokenLiteral()) } } @@ -161,14 +152,12 @@ func TestParsingPrefixExpressions(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Statements does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Statements does not contain %d statements. got=%d", 1, 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } exp, ok := stmt.Expression.(*ast.PrefixExpression) @@ -176,8 +165,7 @@ func TestParsingPrefixExpressions(t *testing.T) { t.Fatalf("stmt is not ast.PrefixExpression. got=%T", stmt.Expression) } if exp.Operator != tt.operator { - t.Fatalf("exp.Operator is not '%s'. got=%s", - tt.operator, exp.Operator) + t.Fatalf("exp.Operator is not '%s'. got=%s", tt.operator, exp.Operator) } if !testLiteralExpression(t, exp.Right, tt.value) { return @@ -220,18 +208,15 @@ func TestParsingInfixExpressions(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Statements does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Statements does not contain %d statements. got=%d", 1, 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } - if !testInfixExpression(t, stmt.Expression, tt.leftValue, - tt.operator, tt.rightValue) { + if !testInfixExpression(t, stmt.Expression, tt.leftValue, tt.operator, tt.rightValue) { return } } @@ -385,14 +370,12 @@ func TestBooleanExpression(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program has not enough statements. got=%d", - len(program.Statements)) + 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } boolean, ok := stmt.Expression.(*ast.Boolean) @@ -400,8 +383,7 @@ func TestBooleanExpression(t *testing.T) { t.Fatalf("exp not *ast.Boolean. got=%T", stmt.Expression) } if boolean.Value != tt.expectedBoolean { - t.Errorf("boolean.Value not %t. got=%t", tt.expectedBoolean, - boolean.Value) + t.Errorf("boolean.Value not %t. got=%t", tt.expectedBoolean, boolean.Value) } } } @@ -415,20 +397,17 @@ func TestIfExpression(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Body does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Body does not contain %d statements. got=%d", 1, 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } exp, ok := stmt.Expression.(*ast.IfExpression) if !ok { - t.Fatalf("stmt.Expression is not ast.IfExpression. got=%T", - stmt.Expression) + t.Fatalf("stmt.Expression is not ast.IfExpression. got=%T", stmt.Expression) } if !testInfixExpression(t, exp.Condition, "x", "<", "y") { @@ -436,14 +415,12 @@ func TestIfExpression(t *testing.T) { } if len(exp.Consequence.Statements) != 1 { - t.Errorf("consequence is not 1 statements. got=%d\n", - len(exp.Consequence.Statements)) + t.Errorf("consequence is not 1 statements. got=%d", len(exp.Consequence.Statements)) } consequence, ok := exp.Consequence.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", - exp.Consequence.Statements[0]) + t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", exp.Consequence.Statements[0]) } if !testIdentifier(t, consequence.Expression, "x") { @@ -464,14 +441,12 @@ func TestIfElseExpression(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Body does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Body does not contain %d statements. got=%d", 1, 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } exp, ok := stmt.Expression.(*ast.IfExpression) @@ -484,14 +459,12 @@ func TestIfElseExpression(t *testing.T) { } if len(exp.Consequence.Statements) != 1 { - t.Errorf("consequence is not 1 statements. got=%d\n", - len(exp.Consequence.Statements)) + t.Errorf("consequence is not 1 statements. got=%d", len(exp.Consequence.Statements)) } consequence, ok := exp.Consequence.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", - exp.Consequence.Statements[0]) + t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", exp.Consequence.Statements[0]) } if !testIdentifier(t, consequence.Expression, "x") { @@ -499,14 +472,12 @@ func TestIfElseExpression(t *testing.T) { } if len(exp.Alternative.Statements) != 1 { - t.Errorf("exp.Alternative.Statements does not contain 1 statements. got=%d\n", - len(exp.Alternative.Statements)) + t.Errorf("exp.Alternative.Statements does not contain 1 statements. got=%d", len(exp.Alternative.Statements)) } alternative, ok := exp.Alternative.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", - exp.Alternative.Statements[0]) + t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", exp.Alternative.Statements[0]) } if !testIdentifier(t, alternative.Expression, "y") { @@ -523,39 +494,33 @@ func TestFunctionLiteralParsing(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Body does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Body does not contain %d statements. got=%d", 1, 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]) + t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0]) } function, ok := stmt.Expression.(*ast.FunctionLiteral) if !ok { - t.Fatalf("stmt.Expression is not ast.FunctionLiteral. got=%T", - stmt.Expression) + t.Fatalf("stmt.Expression is not ast.FunctionLiteral. got=%T", stmt.Expression) } if len(function.Parameters) != 2 { - t.Fatalf("function literal parameters wrong. want 2, got=%d\n", - len(function.Parameters)) + t.Fatalf("function literal parameters wrong. want 2, got=%d", len(function.Parameters)) } testLiteralExpression(t, function.Parameters[0], "x") testLiteralExpression(t, function.Parameters[1], "y") if len(function.Body.Statements) != 1 { - t.Fatalf("function.Body.Statements has not 1 statements. got=%d\n", - len(function.Body.Statements)) + t.Fatalf("function.Body.Statements has not 1 statements. got=%d", len(function.Body.Statements)) } bodyStmt, ok := function.Body.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("function body stmt is not ast.ExpressionStatement. got=%T", - function.Body.Statements[0]) + t.Fatalf("function body stmt is not ast.ExpressionStatement. got=%T", function.Body.Statements[0]) } testInfixExpression(t, bodyStmt.Expression, "x", "+", "y") @@ -581,8 +546,7 @@ func TestFunctionParameterParsing(t *testing.T) { function := stmt.Expression.(*ast.FunctionLiteral) if len(function.Parameters) != len(tt.expectedParams) { - t.Errorf("length parameters wrong. want %d, got=%d\n", - len(tt.expectedParams), len(function.Parameters)) + t.Errorf("length parameters wrong. want %d, got=%d", len(tt.expectedParams), len(function.Parameters)) } for i, ident := range tt.expectedParams { @@ -600,20 +564,17 @@ func TestCallExpressionParsing(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Statements does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Statements does not contain %d statements. got=%d", 1, len(program.Statements)) } stmt, ok := program.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("stmt is not ast.ExpressionStatement. got=%T", - program.Statements[0]) + t.Fatalf("stmt is not ast.ExpressionStatement. got=%T", program.Statements[0]) } exp, ok := stmt.Expression.(*ast.CallExpression) if !ok { - t.Fatalf("stmt.Expression is not ast.CallExpression. got=%T", - stmt.Expression) + t.Fatalf("stmt.Expression is not ast.CallExpression. got=%T", stmt.Expression) } if !testIdentifier(t, exp.Function, "add") { @@ -661,8 +622,7 @@ func TestCallExpressionParameterParsing(t *testing.T) { stmt := program.Statements[0].(*ast.ExpressionStatement) exp, ok := stmt.Expression.(*ast.CallExpression) if !ok { - t.Fatalf("stmt.Expression is not ast.CallExpression. got=%T", - stmt.Expression) + t.Fatalf("stmt.Expression is not ast.CallExpression. got=%T", stmt.Expression) } if !testIdentifier(t, exp.Function, tt.expectedIdent) { @@ -670,14 +630,12 @@ func TestCallExpressionParameterParsing(t *testing.T) { } if len(exp.Arguments) != len(tt.expectedArgs) { - t.Fatalf("wrong number of arguments. want=%d, got=%d", - len(tt.expectedArgs), len(exp.Arguments)) + t.Fatalf("wrong number of arguments. want=%d, got=%d", len(tt.expectedArgs), len(exp.Arguments)) } for i, arg := range tt.expectedArgs { if exp.Arguments[i].String() != arg { - t.Errorf("argument %d wrong. want=%q, got=%q", i, - arg, exp.Arguments[i].String()) + t.Errorf("argument %d wrong. want=%q, got=%q", i, arg, exp.Arguments[i].String()) } } } @@ -1030,8 +988,7 @@ func testIntegerLiteral(t *testing.T, il ast.Expression, value int64) bool { } if integ.TokenLiteral() != fmt.Sprintf("%d", value) { - t.Errorf("integ.TokenLiteral not %d. got=%s", value, - integ.TokenLiteral()) + t.Errorf("integ.TokenLiteral not %d. got=%s", value, integ.TokenLiteral()) return false } @@ -1052,8 +1009,7 @@ func testIdentifier(t *testing.T, exp ast.Expression, value string) bool { } if ident.TokenLiteral() != value { - t.Errorf("ident.TokenLiteral not %s. got=%s", value, - ident.TokenLiteral()) + t.Errorf("ident.TokenLiteral not %s. got=%s", value, ident.TokenLiteral()) return false } @@ -1074,8 +1030,7 @@ func testBooleanLiteral(t *testing.T, exp ast.Expression, value bool) bool { } if bo.TokenLiteral() != fmt.Sprintf("%t", value) { - t.Errorf("bo.TokenLiteral not %t. got=%s", - value, bo.TokenLiteral()) + t.Errorf("bo.TokenLiteral not %t. got=%s", value, bo.TokenLiteral()) return false } @@ -1104,39 +1059,33 @@ func TestMacroLiteralParsing(t *testing.T) { checkParserErrors(t, p) if len(program.Statements) != 1 { - t.Fatalf("program.Statements does not contain %d statements. got=%d\n", - 1, len(program.Statements)) + t.Fatalf("program.Statements does not contain %d statements. got=%d", 1, len(program.Statements)) } stmt, ok := program.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("statement is not ast.ExpressionStatement. got=%T", - program.Statements[0]) + t.Fatalf("statement is not ast.ExpressionStatement. got=%T", program.Statements[0]) } macro, ok := stmt.Expression.(*ast.MacroLiteral) if !ok { - t.Fatalf("stmt.Expression is not ast.MacroLiteral. got=%T", - stmt.Expression) + t.Fatalf("stmt.Expression is not ast.MacroLiteral. got=%T", stmt.Expression) } if len(macro.Parameters) != 2 { - t.Fatalf("macro literal parameters wrong. want 2, got=%d\n", - len(macro.Parameters)) + t.Fatalf("macro literal parameters wrong. want 2, got=%d", len(macro.Parameters)) } testLiteralExpression(t, macro.Parameters[0], "x") testLiteralExpression(t, macro.Parameters[1], "y") if len(macro.Body.Statements) != 1 { - t.Fatalf("macro.Body.Statements has not 1 statements. got=%d\n", - len(macro.Body.Statements)) + t.Fatalf("macro.Body.Statements has not 1 statements. got=%d", len(macro.Body.Statements)) } bodyStmt, ok := macro.Body.Statements[0].(*ast.ExpressionStatement) if !ok { - t.Fatalf("macro body stmt is not ast.ExpressionStatement. got=%T", - macro.Body.Statements[0]) + t.Fatalf("macro body stmt is not ast.ExpressionStatement. got=%T", macro.Body.Statements[0]) } testInfixExpression(t, bodyStmt.Expression, "x", "+", "y") diff --git a/parser/parser_tracing.go b/parser/parser_tracing.go index bdffbd5..937aee3 100644 --- a/parser/parser_tracing.go +++ b/parser/parser_tracing.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore package parser @@ -16,7 +17,7 @@ func identLevel() string { } func tracePrint(fs string) { - fmt.Printf("%s%s\n", identLevel(), fs) + fmt.Println(identLevel(), fs) } func incIdent() { traceLevel = traceLevel + 1 } -- cgit v1.2.3