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"
func TestTokenizeAll (test *testing.T) {
file, err := file.Open("tests/lexer/all")
file, err := file.Open("../tests/lexer/all")
if err != nil {
test.Log(err)
test.Fail()
return
}
tokens, err := Tokenize(file)
if err == nil {
test.Log("Tokenize() have returned an error")
test.Log("Tokenize() should have returned an error")
test.Fail()
return
}
correct := []Token {
@ -57,13 +59,18 @@ func TestTokenizeAll (test *testing.T) {
}
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 {
if !token.Equals(correct[index]) {
test.Log("token", index, "not equal")
test.Fail()
return
}
}
test.Log("token slice content match")
}