More tests for the Tokenizer
This commit is contained in:
parent
64a0e8bd92
commit
cd98dc0342
1 changed files with 37 additions and 0 deletions
|
@ -109,6 +109,43 @@ class TokenizerTests extends munit.FunSuite:
|
|||
)
|
||||
}
|
||||
|
||||
test("should capture all supported char escapes in a string literal") {
|
||||
assertTokens(
|
||||
"\"\\n\\r\\b\\f\\t\\\\\\\"\\\'\"",
|
||||
Right(Token.StringLiteral("\n\r\b\f\t\\\"\'", Nil))
|
||||
)
|
||||
}
|
||||
|
||||
test("should capture all supported char escapes in character literals") {
|
||||
assertTokens("\'\\n\'", Right(Token.CharacterLiteral('\n', Nil)))
|
||||
assertTokens("\'\\r\'", Right(Token.CharacterLiteral('\r', Nil)))
|
||||
assertTokens("\'\\b\'", Right(Token.CharacterLiteral('\b', Nil)))
|
||||
assertTokens("\'\\f\'", Right(Token.CharacterLiteral('\f', Nil)))
|
||||
assertTokens("\'\\t\'", Right(Token.CharacterLiteral('\t', Nil)))
|
||||
assertTokens("\'\\\\\'", Right(Token.CharacterLiteral('\\', Nil)))
|
||||
assertTokens("\'\\\"\'", Right(Token.CharacterLiteral('"', Nil)))
|
||||
assertTokens("\'\\'\'", Right(Token.CharacterLiteral('\'', Nil)))
|
||||
}
|
||||
|
||||
test("should handle a basic string literal") {
|
||||
assertTokens("\"foo\"", Right(Token.StringLiteral("foo", Nil)))
|
||||
}
|
||||
|
||||
test("should handle a string literal with an invalid character escape") {
|
||||
// Note: The character escape is simply not emitted, but we are able to
|
||||
// successfully close out the string, which allows us to recover and parse
|
||||
// more content.
|
||||
assertTokens(
|
||||
"\"foo\\!bar\"",
|
||||
Right(
|
||||
Token.StringLiteral(
|
||||
"foobar",
|
||||
List(Tokenizer.Error.InvalidCharEscape(pos(6, 1, 6), '!'))
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private def assertTokens(
|
||||
source: String,
|
||||
expectedOutput: Either[Tokenizer.Error, Token]*
|
||||
|
|
Loading…
Add table
Reference in a new issue