forked from blampe/goat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
canvas_test.go
61 lines (45 loc) · 1001 Bytes
/
canvas_test.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
51
52
53
54
55
56
57
58
59
60
61
package goat
import (
"bytes"
"testing"
qt "github.com/frankban/quicktest"
)
func TestReadASCII(t *testing.T) {
c := qt.New(t)
var buf bytes.Buffer
// TODO: UNICODE
buf.WriteString(" +-->\n")
buf.WriteString(" | å\n")
buf.WriteString(" +----->")
canvas := NewCanvas(&buf)
c.Assert(canvas.Width, qt.Equals, 8)
c.Assert(canvas.Height, qt.Equals, 3)
buf.Reset()
buf.WriteString(" +--> \n")
buf.WriteString(" | å \n")
buf.WriteString(" +----->\n")
expected := buf.String()
c.Assert(expected, qt.Equals, canvas.String())
}
func (c *Canvas) String() string {
var buffer bytes.Buffer
for h := 0; h < c.Height; h++ {
for w := 0; w < c.Width; w++ {
idx := Index{w, h}
// Search 'text' map; if nothing there try the 'data' map.
r, ok := c.text[idx]
if !ok {
r = c.runeAt(idx)
}
_, err := buffer.WriteRune(r)
if err != nil {
continue
}
}
err := buffer.WriteByte('\n')
if err != nil {
continue
}
}
return buffer.String()
}