Skip to content

Commit b4b1832

Browse files
author
dmullis
committed
Refactor: Move testing-specific code into appropriate file
1 parent 7b93703 commit b4b1832

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

‎canvas.go‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package goat
22

33
import (
44
"bufio"
5-
"bytes"
65
"io"
76
)
87

@@ -101,34 +100,6 @@ type Canvas struct {
101100
text map[Index]rune
102101
}
103102

104-
func (c *Canvas) String() string {
105-
var buffer bytes.Buffer
106-
107-
for h := 0; h < c.Height; h++ {
108-
for w := 0; w < c.Width; w++ {
109-
idx := Index{w, h}
110-
111-
// Search 'text' map; if nothing there try the 'data' map.
112-
r, ok := c.text[idx]
113-
if !ok {
114-
r = c.runeAt(idx)
115-
}
116-
117-
_, err := buffer.WriteRune(r)
118-
if err != nil {
119-
continue
120-
}
121-
}
122-
123-
err := buffer.WriteByte('\n')
124-
if err != nil {
125-
continue
126-
}
127-
}
128-
129-
return buffer.String()
130-
}
131-
132103
func (c *Canvas) heightScreen() int {
133104
return c.Height*16 + 8 + 1
134105
}
@@ -158,6 +129,7 @@ func (c *Canvas) runeAt(i Index) rune {
158129

159130
// NewCanvas creates a new canvas with contents read from the given io.Reader.
160131
// Content should be newline delimited.
132+
// XX Move this to top of file.
161133
func NewCanvas(in io.Reader) (c Canvas) {
162134
width := 0
163135
height := 0

‎canvas_test.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,31 @@ func TestReadASCII(t *testing.T) {
3131

3232
c.Assert(expected, qt.Equals, canvas.String())
3333
}
34+
35+
func (c *Canvas) String() string {
36+
var buffer bytes.Buffer
37+
38+
for h := 0; h < c.Height; h++ {
39+
for w := 0; w < c.Width; w++ {
40+
idx := Index{w, h}
41+
42+
// Search 'text' map; if nothing there try the 'data' map.
43+
r, ok := c.text[idx]
44+
if !ok {
45+
r = c.runeAt(idx)
46+
}
47+
48+
_, err := buffer.WriteRune(r)
49+
if err != nil {
50+
continue
51+
}
52+
}
53+
54+
err := buffer.WriteByte('\n')
55+
if err != nil {
56+
continue
57+
}
58+
}
59+
60+
return buffer.String()
61+
}

0 commit comments

Comments
 (0)