fortheck/test/fortheck/token_test.gleam

44 lines
872 B
Gleam

import fortheck/token.{UnexpectedEndOfTokens}
import gleam/iterator
import gleeunit
import gleeunit/should
pub fn main() {
gleeunit.main()
}
pub fn tokenize_test() {
let string = "3 4\nMUL\t5 \n\n \n dIv"
string
|> token.tokenize
|> iterator.to_list
|> should.equal([
token.Number(3),
token.Number(4),
token.Word("MUL"),
token.Number(5),
token.Word("DIV"),
])
}
pub fn skip_over_test() {
let string = "3 4\nMUL\t5 \n\n \n mul dIv"
string
|> token.tokenize
|> token.skip_over(token.Word("MUL"))
|> should.be_ok
|> iterator.to_list
|> should.equal([token.Number(5), token.Word("MUL"), token.Word("DIV")])
}
pub fn skip_over_eof_test() {
let string = "3 4\nMUL\t5 \n\n \n mul dIv"
string
|> token.tokenize
|> token.skip_over(token.Word("DIV"))
|> should.be_error
|> should.equal(UnexpectedEndOfTokens)
}