Added new test for string and rune literals (which it passes)

This commit is contained in:
Sasha Koshka 2022-08-11 12:12:41 -05:00
parent 4f37715a8c
commit f7a823687e
3 changed files with 23 additions and 1 deletions

View File

@ -117,3 +117,21 @@ func TestTokenizeNumbers (test *testing.T) {
Token { kind: TokenKindNewline },
}, test)
}
func TestTokenizeText (test *testing.T) {
checkTokenSlice("../tests/lexer/text", []Token {
Token { kind: TokenKindString, value: "hello world!\a\b\f\n\r\t\v'\"\\" },
Token { kind: TokenKindNewline },
Token { kind: TokenKindRune, value: '\a' },
Token { kind: TokenKindRune, value: '\b' },
Token { kind: TokenKindRune, value: '\f' },
Token { kind: TokenKindRune, value: '\n' },
Token { kind: TokenKindRune, value: '\r' },
Token { kind: TokenKindRune, value: '\t' },
Token { kind: TokenKindRune, value: '\v' },
Token { kind: TokenKindRune, value: '\'' },
Token { kind: TokenKindRune, value: '"' },
Token { kind: TokenKindRune, value: '\\' },
Token { kind: TokenKindNewline },
}, test)
}

View File

@ -100,7 +100,9 @@ func (lexer *LexingOperation) tokenizeNumber (
err = lexer.nextRune()
if err != nil { return }
}
// TODO: increase accuracy of this so that TestTokenizeNumbers is
// passed.
if lexer.char == '.' {
isFloat = true
err = lexer.nextRune()

2
tests/lexer/text Normal file
View File

@ -0,0 +1,2 @@
"hello world!\a\b\f\n\r\t\v\'\"\\"
'\a' '\b' '\f' '\n' '\r' '\t' '\v' '\'' '\"' '\\'