all repos

gbf @ 27cc7cd

⭐ gleaming brainfuck

gbf/test/gbf_parser_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
import gbf/lexer.{Position}
import gbf/parser.{Block, Leaf, Node}
import gbf/token.{DecrementByte, IncrementByte, IncrementPointer}
import gleeunit/should

pub fn should_parse_test() {
  "+[->+]>"
  |> lexer.new
  |> lexer.lex
  |> parser.parse
  |> should.equal(
    Ok(
      Node(
        Block(position: Position(0), children: [
          Leaf(#(IncrementByte, Position(0))),
          Node(
            Block(position: Position(1), children: [
              Leaf(#(DecrementByte, Position(2))),
              Leaf(#(IncrementPointer, Position(3))),
              Leaf(#(IncrementByte, Position(4))),
            ]),
          ),
          Leaf(#(IncrementPointer, Position(6))),
        ]),
      ),
    ),
  )
}