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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package bf
import (
"bufio"
"io"
"os"
"testing"
)
func TestInterpretInstruction(t *testing.T) {
var writer io.Writer
writer = flushingWriter{
w: bufio.NewWriter(os.Stdout),
}
src := []instruction{
{
idx: 0,
instructionType: incD,
},
}
for i := 0; i < 65; i++ {
src = append(src, instruction{
idx: uint(i),
instructionType: incD,
})
}
src = append(src, instruction{
idx: 65,
instructionType: outD,
})
intepreterState := state{
src: src,
buffer: make([]byte, 1),
writer: writer,
}
writer.Write([]byte("hello\n"))
for i := 0; i < 66; i++ {
intepreterState.interpretInstruction()
}
intepreterState.interpretInstruction()
}
func TestInterpreter(t *testing.T) {
input := ","
interpreter := NewInterpreter(input)
Run(interpreter)
}
|