mirror of
https://github.com/status-im/nim-json-serialization.git
synced 2025-02-16 12:07:35 +00:00
Update the lexer test and add it to nimble test
This commit is contained in:
parent
6e9d69dafb
commit
c108ba90e6
@ -11,11 +11,7 @@ requires "nim >= 0.17.0",
|
||||
"serialization",
|
||||
"stew"
|
||||
|
||||
task test, "Run tests":
|
||||
for filename in [
|
||||
"test_lexer",
|
||||
"test_serialization",
|
||||
]:
|
||||
exec "nim c -r tests/" & filename
|
||||
rmFile "tests/" & filename
|
||||
task test, "Run all tests":
|
||||
exec "nim c -r --threads:off tests/test_all"
|
||||
exec "nim c -r --threads:on tests/test_all"
|
||||
|
||||
|
4
tests/test_all.nim
Normal file
4
tests/test_all.nim
Normal file
@ -0,0 +1,4 @@
|
||||
import
|
||||
test_lexer,
|
||||
test_serialization
|
||||
|
@ -2,11 +2,11 @@ import
|
||||
unittest,
|
||||
../json_serialization/lexer, ./utils
|
||||
|
||||
template expectedToken(token: TokKind, additionalTest = true) {.dirty.} =
|
||||
template expectedToken(token: TokKind, additionalCheck = true) {.dirty.} =
|
||||
lexer.next()
|
||||
check:
|
||||
lexer.tok == token
|
||||
additionalTest
|
||||
bool(additionalCheck)
|
||||
|
||||
template lexerTest(name, input: string, expectations) {.dirty.} =
|
||||
test name:
|
||||
@ -27,7 +27,7 @@ suite "lexer tests":
|
||||
expectedToken tkCurlyLe
|
||||
expectedToken tkString, lexer.strVal == "x"
|
||||
expectedToken tkColon
|
||||
expectedToken tkInt, lexer.intVal == 10
|
||||
expectedToken tkInt, lexer.absIntVal == 10
|
||||
expectedToken tkComma
|
||||
expectedToken tkString, lexer.strVal == "y"
|
||||
expectedToken tkColon
|
||||
@ -37,11 +37,11 @@ suite "lexer tests":
|
||||
expectedToken tkEof # check that reading past the end is benign
|
||||
|
||||
lexerTest "int literal", "190":
|
||||
expectedToken tkInt, lexer.intVal == 190
|
||||
expectedToken tkInt, lexer.absIntVal == 190
|
||||
expectedToken tkEof
|
||||
|
||||
lexerTest "int64 literal", "3568257348920230622":
|
||||
expectedToken tkInt, lexer.intVal == 3568257348920230622'i64
|
||||
expectedToken tkInt, lexer.absIntVal == 3568257348920230622'u64
|
||||
expectedToken tkEof
|
||||
|
||||
lexerTest "float literal", ".340":
|
||||
@ -54,7 +54,7 @@ suite "lexer tests":
|
||||
|
||||
lexerTest "mixed array", "[1, 2.0, \"test\", {}, [],]":
|
||||
expectedToken tkBracketLe
|
||||
expectedToken tkInt, lexer.intVal == 1
|
||||
expectedToken tkInt, lexer.absIntVal == 1
|
||||
expectedToken tkComma
|
||||
expectedToken tkFloat, lexer.floatVal =~ 2.0
|
||||
expectedToken tkComma
|
||||
|
Loading…
x
Reference in New Issue
Block a user