aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2020-02-21 17:57:10 +0100
committerDimitri Sokolyuk <demon@dim13.org>2020-02-21 17:57:10 +0100
commitdb2a15515c910ca6bd3f097c5d2c9ca5612a35cc (patch)
treeca5bc3f47f1b8025aab319bf6f4caefe646ebb35
parent4e76dadb7bf520b4fd96178c5ddf2e4b646b33ad (diff)
extend testingHEADmaster
-rw-r--r--evaluator/evaluator_test.go42
-rw-r--r--evaluator/macro_expansion_test.go9
-rw-r--r--evaluator/quote_unquote_test.go4
-rw-r--r--parser/parser_test.go6
4 files changed, 36 insertions, 25 deletions
diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go
index f8fb53b..606078a 100644
--- a/evaluator/evaluator_test.go
+++ b/evaluator/evaluator_test.go
@@ -31,7 +31,7 @@ func TestEvalIntegerExpression(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
testIntegerObject(t, evaluated, tt.expected)
}
}
@@ -67,7 +67,7 @@ func TestEvalBooleanExpression(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
testBooleanObject(t, evaluated, tt.expected)
}
}
@@ -86,7 +86,7 @@ func TestBangOperator(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
testBooleanObject(t, evaluated, tt.expected)
}
}
@@ -106,7 +106,7 @@ func TestIfElseExpressions(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
integer, ok := tt.expected.(int)
if ok {
testIntegerObject(t, evaluated, int64(integer))
@@ -160,7 +160,7 @@ f(10);`,
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
testIntegerObject(t, evaluated, tt.expected)
}
}
@@ -229,7 +229,7 @@ if (10 > 1) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
errObj, ok := evaluated.(*object.Error)
if !ok {
@@ -257,14 +257,14 @@ func TestLetStatements(t *testing.T) {
}
for _, tt := range tests {
- testIntegerObject(t, testEval(tt.input), tt.expected)
+ testIntegerObject(t, testEval(t, tt.input), tt.expected)
}
}
func TestFunctionObject(t *testing.T) {
input := "fn(x) { x + 2; };"
- evaluated := testEval(input)
+ evaluated := testEval(t, input)
fn, ok := evaluated.(*object.Function)
if !ok {
t.Fatalf("object is not Function. got=%T (%+v)", evaluated, evaluated)
@@ -300,7 +300,7 @@ func TestFunctionApplication(t *testing.T) {
}
for _, tt := range tests {
- testIntegerObject(t, testEval(tt.input), tt.expected)
+ testIntegerObject(t, testEval(t, tt.input), tt.expected)
}
}
@@ -318,7 +318,7 @@ let ourFunction = fn(first) {
ourFunction(20) + first + second;`
- testIntegerObject(t, testEval(input), 70)
+ testIntegerObject(t, testEval(t, input), 70)
}
func TestClosures(t *testing.T) {
@@ -330,13 +330,13 @@ let newAdder = fn(x) {
let addTwo = newAdder(2);
addTwo(2);`
- testIntegerObject(t, testEval(input), 4)
+ testIntegerObject(t, testEval(t, input), 4)
}
func TestStringLiteral(t *testing.T) {
input := `"Hello World!"`
- evaluated := testEval(input)
+ evaluated := testEval(t, input)
str, ok := evaluated.(*object.String)
if !ok {
t.Fatalf("object is not String. got=%T (%+v)", evaluated, evaluated)
@@ -350,7 +350,7 @@ func TestStringLiteral(t *testing.T) {
func TestStringConcatenation(t *testing.T) {
input := `"Hello" + " " + "World!"`
- evaluated := testEval(input)
+ evaluated := testEval(t, input)
str, ok := evaluated.(*object.String)
if !ok {
t.Fatalf("object is not String. got=%T (%+v)", evaluated, evaluated)
@@ -387,7 +387,7 @@ func TestBuiltinFunctions(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
switch expected := tt.expected.(type) {
case int:
@@ -428,7 +428,7 @@ func TestBuiltinFunctions(t *testing.T) {
func TestArrayLiterals(t *testing.T) {
input := "[1, 2 * 2, 3 + 3]"
- evaluated := testEval(input)
+ evaluated := testEval(t, input)
result, ok := evaluated.(*object.Array)
if !ok {
t.Fatalf("object is not Array. got=%T (%+v)", evaluated, evaluated)
@@ -492,7 +492,7 @@ func TestArrayIndexExpressions(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
integer, ok := tt.expected.(int)
if ok {
testIntegerObject(t, evaluated, int64(integer))
@@ -513,7 +513,7 @@ func TestHashLiterals(t *testing.T) {
false: 6
}`
- evaluated := testEval(input)
+ evaluated := testEval(t, input)
result, ok := evaluated.(*object.Hash)
if !ok {
t.Fatalf("Eval didn't return Hash. got=%T (%+v)", evaluated, evaluated)
@@ -578,7 +578,7 @@ func TestHashIndexExpressions(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
integer, ok := tt.expected.(int)
if ok {
testIntegerObject(t, evaluated, int64(integer))
@@ -587,7 +587,8 @@ func TestHashIndexExpressions(t *testing.T) {
}
}
}
-func testEval(input string) object.Object {
+func testEval(t *testing.T, input string) object.Object {
+ t.Helper()
l := lexer.New(input)
p := parser.New(l)
program := p.ParseProgram()
@@ -597,6 +598,7 @@ func testEval(input string) object.Object {
}
func testIntegerObject(t *testing.T, obj object.Object, expected int64) bool {
+ t.Helper()
result, ok := obj.(*object.Integer)
if !ok {
t.Errorf("object is not Integer. got=%T (%+v)", obj, obj)
@@ -612,6 +614,7 @@ func testIntegerObject(t *testing.T, obj object.Object, expected int64) bool {
}
func testBooleanObject(t *testing.T, obj object.Object, expected bool) bool {
+ t.Helper()
result, ok := obj.(*object.Boolean)
if !ok {
t.Errorf("object is not Boolean. got=%T (%+v)", obj, obj)
@@ -626,6 +629,7 @@ func testBooleanObject(t *testing.T, obj object.Object, expected bool) bool {
}
func testNullObject(t *testing.T, obj object.Object) bool {
+ t.Helper()
if obj != NULL {
t.Errorf("object is not NULL. got=%T (%+v)", obj, obj)
return false
diff --git a/evaluator/macro_expansion_test.go b/evaluator/macro_expansion_test.go
index 81c03ef..9d4f3d1 100644
--- a/evaluator/macro_expansion_test.go
+++ b/evaluator/macro_expansion_test.go
@@ -17,7 +17,7 @@ let mymacro = macro(x, y) { x + y; };
`
env := object.NewEnvironment()
- program := testParseProgram(input)
+ program := testParseProgram(t, input)
DefineMacros(program, env)
@@ -64,7 +64,8 @@ let mymacro = macro(x, y) { x + y; };
}
}
-func testParseProgram(input string) *ast.Program {
+func testParseProgram(t *testing.T, input string) *ast.Program {
+ t.Helper()
l := lexer.New(input)
p := parser.New(l)
return p.ParseProgram()
@@ -109,8 +110,8 @@ func TestExpandMacros(t *testing.T) {
}
for _, tt := range tests {
- expected := testParseProgram(tt.expected)
- program := testParseProgram(tt.input)
+ expected := testParseProgram(t, tt.expected)
+ program := testParseProgram(t, tt.input)
env := object.NewEnvironment()
DefineMacros(program, env)
diff --git a/evaluator/quote_unquote_test.go b/evaluator/quote_unquote_test.go
index 0f79589..9b0de5b 100644
--- a/evaluator/quote_unquote_test.go
+++ b/evaluator/quote_unquote_test.go
@@ -30,7 +30,7 @@ func TestQuote(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
quote, ok := evaluated.(*object.Quote)
if !ok {
t.Fatalf("expected *object.Quote. got=%T (%+v)",
@@ -99,7 +99,7 @@ func TestQuoteUnquote(t *testing.T) {
}
for _, tt := range tests {
- evaluated := testEval(tt.input)
+ evaluated := testEval(t, tt.input)
quote, ok := evaluated.(*object.Quote)
if !ok {
t.Fatalf("expected *object.Quote. got=%T (%+v)",
diff --git a/parser/parser_test.go b/parser/parser_test.go
index df040ad..ed019af 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -951,6 +951,7 @@ func TestParsingHashLiteralsWithExpressions(t *testing.T) {
}
func testLetStatement(t *testing.T, s ast.Statement, name string) bool {
+ t.Helper()
if s.TokenLiteral() != "let" {
t.Errorf("s.TokenLiteral not 'let'. got=%q", s.TokenLiteral())
return false
@@ -976,6 +977,7 @@ func testLetStatement(t *testing.T, s ast.Statement, name string) bool {
}
func testInfixExpression(t *testing.T, exp ast.Expression, left interface{}, operator string, right interface{}) bool {
+ t.Helper()
opExp, ok := exp.(*ast.InfixExpression)
if !ok {
t.Errorf("exp is not ast.OperatorExpression. got=%T(%s)", exp, exp)
@@ -999,6 +1001,7 @@ func testInfixExpression(t *testing.T, exp ast.Expression, left interface{}, ope
}
func testLiteralExpression(t *testing.T, exp ast.Expression, expected interface{}) bool {
+ t.Helper()
switch v := expected.(type) {
case int:
return testIntegerLiteral(t, exp, int64(v))
@@ -1014,6 +1017,7 @@ func testLiteralExpression(t *testing.T, exp ast.Expression, expected interface{
}
func testIntegerLiteral(t *testing.T, il ast.Expression, value int64) bool {
+ t.Helper()
integ, ok := il.(*ast.IntegerLiteral)
if !ok {
t.Errorf("il not *ast.IntegerLiteral. got=%T", il)
@@ -1035,6 +1039,7 @@ func testIntegerLiteral(t *testing.T, il ast.Expression, value int64) bool {
}
func testIdentifier(t *testing.T, exp ast.Expression, value string) bool {
+ t.Helper()
ident, ok := exp.(*ast.Identifier)
if !ok {
t.Errorf("exp not *ast.Identifier. got=%T", exp)
@@ -1056,6 +1061,7 @@ func testIdentifier(t *testing.T, exp ast.Expression, value string) bool {
}
func testBooleanLiteral(t *testing.T, exp ast.Expression, value bool) bool {
+ t.Helper()
bo, ok := exp.(*ast.Boolean)
if !ok {
t.Errorf("exp not *ast.Boolean. got=%T", exp)