-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsoleMock.go
50 lines (42 loc) · 855 Bytes
/
consoleMock.go
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
package main
import "fmt"
type consoleMock struct {
linesIn []string
lineIn int
output string
env *environment
}
func newConsoleMock(env *environment, linesIn []string) *consoleMock {
var c consoleMock
c.linesIn = linesIn
c.output = ""
c.env = env
return &c
}
func (c *consoleMock) readline() (string, bool) {
if c.lineIn >= len(c.linesIn) {
c.env.stop = true
return "", true
}
line := c.linesIn[c.lineIn]
c.write(line + "\n")
c.lineIn++
return line, false
}
func (c *consoleMock) readChar() (uint8, bool) {
s, stop := c.readline()
if s == "" {
return ' ', stop
} else {
return s[0], stop
}
}
func (c *consoleMock) write(s string) {
c.output += s
c.env.writeSpool(s)
}
func (c *consoleMock) writef(format string, a ...interface{}) {
s := fmt.Sprintf(format, a...)
c.write(s)
}
func (c *consoleMock) close() {}