Lexer unit test now works properly
This commit is contained in:
parent
2e965d6f68
commit
cf04dfd600
@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user