Added number lexing unit test
This commit is contained in:
parent
6acc11d046
commit
7a0ed247e2
@ -4,8 +4,8 @@ import "testing"
|
|||||||
import "github.com/sashakoshka/arf/file"
|
import "github.com/sashakoshka/arf/file"
|
||||||
import "github.com/sashakoshka/arf/types"
|
import "github.com/sashakoshka/arf/types"
|
||||||
|
|
||||||
func TestTokenizeAll (test *testing.T) {
|
func checkTokenSlice (filePath string, correct []Token, test *testing.T) {
|
||||||
file, err := file.Open("../tests/lexer/all")
|
file, err := file.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
test.Log(err)
|
test.Log(err)
|
||||||
test.Fail()
|
test.Fail()
|
||||||
@ -26,7 +26,28 @@ func TestTokenizeAll (test *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
correct := []Token {
|
if len(tokens) != len(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.Log (
|
||||||
|
"have", token.Describe(),
|
||||||
|
"want", correct[index].Describe())
|
||||||
|
test.Fail()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
test.Log("token slice content match")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTokenizeAll (test *testing.T) {
|
||||||
|
checkTokenSlice("../tests/lexer/all", []Token {
|
||||||
Token { kind: TokenKindSeparator },
|
Token { kind: TokenKindSeparator },
|
||||||
Token { kind: TokenKindPermission, value: types.Permission {
|
Token { kind: TokenKindPermission, value: types.Permission {
|
||||||
Internal: types.ModeRead,
|
Internal: types.ModeRead,
|
||||||
@ -65,24 +86,34 @@ func TestTokenizeAll (test *testing.T) {
|
|||||||
Token { kind: TokenKindBinaryAnd },
|
Token { kind: TokenKindBinaryAnd },
|
||||||
Token { kind: TokenKindLogicalAnd },
|
Token { kind: TokenKindLogicalAnd },
|
||||||
Token { kind: TokenKindNewline },
|
Token { kind: TokenKindNewline },
|
||||||
}
|
}, test)
|
||||||
|
}
|
||||||
if len(tokens) != len(correct) {
|
|
||||||
test.Log("lexed", len(tokens), "tokens, want", len(correct))
|
func TestTokenizeNumbers (test *testing.T) {
|
||||||
test.Fail()
|
checkTokenSlice("../tests/lexer/numbers", []Token {
|
||||||
return
|
Token { kind: TokenKindUInt, value: uint64(83628266) },
|
||||||
}
|
Token { kind: TokenKindNewline },
|
||||||
test.Log("token slice length match", len(tokens), "=", len(correct))
|
Token { kind: TokenKindUInt, value: uint64(83628266) },
|
||||||
|
Token { kind: TokenKindNewline },
|
||||||
for index, token := range tokens {
|
Token { kind: TokenKindUInt, value: uint64(83628266) },
|
||||||
if !token.Equals(correct[index]) {
|
Token { kind: TokenKindNewline },
|
||||||
test.Log("token", index, "not equal")
|
Token { kind: TokenKindUInt, value: uint64(83628266) },
|
||||||
test.Log (
|
Token { kind: TokenKindNewline },
|
||||||
"have", token.Describe(),
|
|
||||||
"want", correct[index].Describe())
|
Token { kind: TokenKindInt, value: int64(-83628266) },
|
||||||
test.Fail()
|
Token { kind: TokenKindNewline },
|
||||||
return
|
Token { kind: TokenKindInt, value: int64(-83628266) },
|
||||||
}
|
Token { kind: TokenKindNewline },
|
||||||
}
|
Token { kind: TokenKindInt, value: int64(-83628266) },
|
||||||
test.Log("token slice content match")
|
Token { kind: TokenKindNewline },
|
||||||
|
Token { kind: TokenKindInt, value: int64(-83628266) },
|
||||||
|
Token { kind: TokenKindNewline },
|
||||||
|
|
||||||
|
Token { kind: TokenKindFloat, value: float64(0.123478) },
|
||||||
|
Token { kind: TokenKindNewline },
|
||||||
|
Token { kind: TokenKindFloat, value: float64(234.3095) },
|
||||||
|
Token { kind: TokenKindNewline },
|
||||||
|
Token { kind: TokenKindFloat, value: float64(-2.312) },
|
||||||
|
Token { kind: TokenKindNewline },
|
||||||
|
}, test)
|
||||||
}
|
}
|
||||||
|
13
tests/lexer/numbers
Normal file
13
tests/lexer/numbers
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
83628266
|
||||||
|
0b100111111000001000011101010
|
||||||
|
0x4Fc10Ea
|
||||||
|
0477010352
|
||||||
|
|
||||||
|
-83628266
|
||||||
|
-0b100111111000001000011101010
|
||||||
|
-0x4Fc10Ea
|
||||||
|
-0477010352
|
||||||
|
|
||||||
|
0.123478
|
||||||
|
234.3095
|
||||||
|
-2.312
|
Reference in New Issue
Block a user