-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender_test.go
104 lines (95 loc) · 1.97 KB
/
render_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package anansi_test
import (
"bytes"
"image"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
. "github.com/jcorbin/anansi"
anansitest "github.com/jcorbin/anansi/test"
)
func makeTestBitmap(set string, lines ...string) Bitmap {
var bi Bitmap
bi.Load(MustParseBitmap(set, lines...))
return bi
}
func TestWriteBitmap(t *testing.T) {
for _, tc := range []struct {
name string
sz image.Point
bi Bitmap
outLines []string
styles []Style
}{
{
name: "basic test pattern",
sz: image.Pt(2, 2),
bi: makeTestBitmap("# ",
"# . # . ",
". # . # ",
"# . # . ",
". # . # ",
"# . # . ",
". # . # ",
"# . # . ",
". # . # ",
),
outLines: []string{
"⢕⢕",
"⢕⢕",
},
},
{
name: "basic test pattern",
sz: image.Pt(3, 3),
bi: makeTestBitmap("# ",
"# . # . ",
". # . # ",
"# . # . ",
". # . # ",
"# . # . ",
". # . # ",
"# . # . ",
". # . # ",
),
outLines: []string{
"⢕⢕ ",
"⢕⢕ ",
" ",
},
},
} {
t.Run(tc.name, testWithScreenModes(tc.sz, tc.outLines, func(t *testing.T, w io.Writer) error {
_, err := WriteBitmap(w, tc.bi, tc.styles...)
return err
}))
}
}
// TODO func TestWriteGrid
func testWithScreenModes(
sz image.Point, outLines []string,
f func(t *testing.T, w io.Writer) error,
) func(t *testing.T) {
return func(t *testing.T) {
t.Run("direct to anansi.Screen", func(t *testing.T) {
var sc ScreenDiffer
sc.Resize(sz)
require.NoError(t, f(t, &sc))
outLines := anansitest.GridLines(sc.Grid, ' ')
assert.Equal(t, outLines, outLines)
})
t.Run("buffered flush to anansi.Screen", func(t *testing.T) {
var sc ScreenDiffer
sc.Resize(sz)
var buf bytes.Buffer
err := f(t, &buf)
if err == nil {
_, err = buf.WriteTo(&sc)
}
require.NoError(t, err)
outLines := anansitest.GridLines(sc.Grid, ' ')
assert.Equal(t, outLines, outLines)
})
}
}