2016-09-10 08:30:40 +00:00
|
|
|
import ../private/lex
|
|
|
|
|
2016-09-10 10:38:03 +00:00
|
|
|
import unittest, strutils
|
|
|
|
|
|
|
|
const tokensWithValue = [ltScalarPart, ltQuotedScalar]
|
2016-09-10 08:30:40 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TokenWithValue = object
|
|
|
|
case kind: LexerToken
|
2016-09-10 10:38:03 +00:00
|
|
|
of tokensWithValue:
|
2016-09-10 08:30:40 +00:00
|
|
|
value: string
|
|
|
|
else: discard
|
|
|
|
|
|
|
|
proc assertEquals(input: string, expected: varargs[TokenWithValue]) =
|
2016-09-10 10:38:03 +00:00
|
|
|
let lex = newYamlLexer(input)
|
|
|
|
lex.init()
|
|
|
|
for expectedToken in expected:
|
|
|
|
let t = lex.next()
|
|
|
|
doAssert t == expectedToken.kind, "Wrong token kind: Expected " &
|
|
|
|
$expectedToken.kind & ", got " & $t
|
|
|
|
if expectedToken.kind in tokensWithValue:
|
|
|
|
doAssert lex.buf == expectedToken.value,
|
|
|
|
"Wrong token content: Expected " & escape(expectedToken.value) &
|
|
|
|
", got " & escape(lex.buf)
|
|
|
|
|
|
|
|
proc se(): TokenWithValue = TokenWithValue(kind: ltStreamEnd)
|
2016-09-10 08:30:40 +00:00
|
|
|
|
|
|
|
suite "Lexer":
|
|
|
|
test "Empty document":
|
2016-09-10 10:38:03 +00:00
|
|
|
assertEquals("", se())
|