all repos

gbf @ 35a5e15443419dd8762d773bb04a906ef0dc9ccb

⭐ gleaming brainfuck

gbf/test/gbf_lexer_test.gleam(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gbf/lexer
import gbf/token
import gleeunit/should

pub fn can_lex_test() {
  "><+-.,[] this is a comment"
  |> lexer.new
  |> lexer.lex
  |> should.equal([
    #(token.IncrementPointer, lexer.Position(0)),
    #(token.DecrementPointer, lexer.Position(1)),
    #(token.IncrementByte, lexer.Position(2)),
    #(token.DecrementByte, lexer.Position(3)),
    #(token.OutputByte, lexer.Position(4)),
    #(token.InputByte, lexer.Position(5)),
    #(token.StartBlock, lexer.Position(6)),
    #(token.EndBlock, lexer.Position(7)),
    #(token.Comment("this is a comment"), lexer.Position(9)),
  ])
}

pub fn multiline_test() {
  "this is a comment
+++
<.
  "
  |> lexer.new
  |> lexer.lex
  |> should.equal([
    #(token.Comment("this is a comment"), lexer.Position(0)),
    #(token.IncrementByte, lexer.Position(18)),
    #(token.IncrementByte, lexer.Position(19)),
    #(token.IncrementByte, lexer.Position(20)),
    #(token.DecrementPointer, lexer.Position(22)),
    #(token.OutputByte, lexer.Position(23)),
  ])
}