35 lines
953 B
Kotlin
35 lines
953 B
Kotlin
package be.ugent.logprog.lexer
|
|
|
|
import lexer.Error
|
|
import lexer.Lexer
|
|
import lexer.TokenType
|
|
import org.junit.jupiter.api.Test
|
|
import org.junit.jupiter.api.assertThrows
|
|
import kotlin.test.assertEquals
|
|
|
|
class LexerScanTest {
|
|
@Test
|
|
fun scan_emptyString_returnsEOF() {
|
|
val lexer = Lexer("")
|
|
val tokens = lexer.scan()
|
|
assertEquals(1, tokens.size)
|
|
assertEquals(TokenType.EOF, tokens[0].type)
|
|
}
|
|
|
|
@Test
|
|
fun scan_unknownSymbol_returnsError() {
|
|
val lexer = Lexer("€")
|
|
assertThrows<Error>({
|
|
val tokens = lexer.scan()
|
|
})
|
|
}
|
|
|
|
@Test
|
|
fun scan_dot_returnsDot() {
|
|
val lexer = Lexer(".")
|
|
val tokens = lexer.scan()
|
|
assertEquals(2, tokens.size)
|
|
assertEquals(TokenType.DOT, tokens[0].type, "Expected DOT token, got ${tokens[0].type}")
|
|
assertEquals(TokenType.EOF, tokens[1].type, "Expected EOF token, got ${tokens[1].type}")
|
|
}
|
|
}
|