Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gravataLonga committed Jun 30, 2022
1 parent ab63b10 commit 4c90afc
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions parser/arguments_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser

import (
"fmt"
"ninja/ast"
"ninja/lexer"
"strings"
Expand Down Expand Up @@ -48,24 +49,26 @@ func TestFunctionParameterParsing(t *testing.T) {
}

for _, tt := range tests {
l := lexer.New(strings.NewReader(tt.input))
p := New(l)
program := p.ParseProgram()
checkParserErrors(t, p)
t.Run(fmt.Sprintf("TestFunctionParameter %s", tt.input), func(t *testing.T) {
l := lexer.New(strings.NewReader(tt.input))
p := New(l)
program := p.ParseProgram()
checkParserErrors(t, p)

stmt := program.Statements[0].(*ast.ExpressionStatement)
function := stmt.Expression.(*ast.Function)
stmt := program.Statements[0].(*ast.ExpressionStatement)
function := stmt.Expression.(*ast.Function)

if len(function.Parameters) != len(tt.expectedParams) {
t.Errorf("length parameters wrong. want %d, got=%d\n", len(tt.expectedParams), len(function.Parameters))
}
if len(function.Parameters) != len(tt.expectedParams) {
t.Errorf("length parameters wrong. want %d, got=%d\n", len(tt.expectedParams), len(function.Parameters))
}

for i, ident := range tt.expectedParams {
testLiteralExpression(t, function.Parameters[i], ident)
}
for i, ident := range tt.expectedParams {
testLiteralExpression(t, function.Parameters[i], ident)
}

if function.Name.String() != tt.ident {
t.Errorf("Identitier of function not match. want %s, got=%s\n", tt.ident, function.Name.String())
}
if function.Name.String() != tt.ident {
t.Errorf("Identitier of function not match. want %s, got=%s\n", tt.ident, function.Name.String())
}
})
}
}

0 comments on commit 4c90afc

Please sign in to comment.