Lexer unit test now works properly

This commit is contained in:
Sasha Koshka 2022-08-10 12:58:47 -04:00
parent 2e965d6f68
commit cf04dfd600
1 changed files with 10 additions and 3 deletions

View File

@ -5,16 +5,18 @@ import "github.com/sashakoshka/arf/file"
import "github.com/sashakoshka/arf/types" import "github.com/sashakoshka/arf/types"
func TestTokenizeAll (test *testing.T) { func TestTokenizeAll (test *testing.T) {
file, err := file.Open("tests/lexer/all") file, err := file.Open("../tests/lexer/all")
if err != nil { if err != nil {
test.Log(err) test.Log(err)
test.Fail() test.Fail()
return
} }
tokens, err := Tokenize(file) tokens, err := Tokenize(file)
if err == nil { if err == nil {
test.Log("Tokenize() have returned an error") test.Log("Tokenize() should have returned an error")
test.Fail() test.Fail()
return
} }
correct := []Token { correct := []Token {
@ -57,13 +59,18 @@ func TestTokenizeAll (test *testing.T) {
} }
if len(tokens) != len(correct) { if len(tokens) != len(correct) {
test.Log("lexed", tokens, "tokens, want", correct) test.Log("lexed", len(tokens), "tokens, want", len(correct))
test.Fail()
return
} }
test.Log("token slice length match", len(tokens), "=", len(correct))
for index, token := range tokens { for index, token := range tokens {
if !token.Equals(correct[index]) { if !token.Equals(correct[index]) {
test.Log("token", index, "not equal") test.Log("token", index, "not equal")
test.Fail() test.Fail()
return
} }
} }
test.Log("token slice content match")
} }