-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathinsert_more_test.go
205 lines (191 loc) · 7.72 KB
/
insert_more_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package frame
import (
"image"
"testing"
"github.com/google/go-cmp/cmp"
)
// TODO(rjk): Test having a height that's not a multiple of the font
// height. Particularly relevant for supporting lines of differing
// heights.
// TestInsertAligned is a high-level Insert test that uses a frame where
// the character edge aligns with the width of the text region.
func TestInsertAligned(t *testing.T) {
iv := &invariants{
topcorner: image.Pt(20, 10),
}
*validate = true
tests := []struct {
name string
fn func(t *testing.T, fr Frame, iv *invariants)
want []string
textarea image.Rectangle
knowntofail bool
}{
{
// Insert text that doesn't fit.
name: "insertPastEnd",
fn: insertPastEnd,
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,40) [0,1],[3,2]",
"fill (20,40)-(20,50) [0,3],[0,1]",
`screen-800x600 <- string "a本ポ" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "ポポポ" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "ポポh" atpoint: (20,30) [0,2] fill: black`},
textarea: image.Rect(20, 10, 59, 40),
},
{
// Split a wrapped line by inserting a newline.
name: "splitWrappedLine",
fn: splitWrappedLine,
textarea: image.Rect(20, 10, 59, 60),
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,50) [0,1],[3,3]",
"fill (20,50)-(33,60) [0,4],[1,1]",
`screen-800x600 <- string "a本ポ" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "ポポポ" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "ポポh" atpoint: (20,30) [0,2] fill: black`,
`screen-800x600 <- string "ell" atpoint: (20,40) [0,3] fill: black`,
`screen-800x600 <- string "o" atpoint: (20,50) [0,4] fill: black`,
// The previously failing insertion starts here. We didn't have to do
// anything in this case. But we still fill blank space at the end of the
// line over again. This is (hopefully) harmless.
// TODO(rjk): Elide the 0-width draws.
"fill (58,10)-(59,20) [-,0],[-,1]",
"fill (20,20)-(20,30) [0,1],[0,1]",
},
knowntofail: false,
},
{
// Insert a single character that forces conversion of non-wrapped to
// wrapped with wripple to end.
name: "insertForcesWrap",
fn: insertForcesWrap,
textarea: image.Rect(20, 10, 59, 60),
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,50) [0,1],[3,3]",
"fill (20,50)-(59,60) [0,4],[3,1]",
`screen-800x600 <- string "0ab" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "1cd" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "2ef" atpoint: (20,30) [0,2] fill: black`,
`screen-800x600 <- string "3gh" atpoint: (20,40) [0,3] fill: black`,
`screen-800x600 <- string "4ij" atpoint: (20,50) [0,4] fill: black`,
"blit (20,30)-(59,50) [0,2],[3,2], to (20,40)-(59,60) [0,3],[3,2]",
"blit (59,20)-(59,30) [3,1],[0,1], to (59,30)-(59,40) [3,2],[0,1]",
"blit (20,20)-(59,30) [0,1],[3,1], to (20,30)-(59,40) [0,2],[3,1]",
"fill (33,20)-(59,30) [1,1],[2,1]",
"blit (46,10)-(59,20) [2,0],[1,1], to (20,20)-(33,30) [0,1],[1,1]",
"fill (46,10)-(59,20) [2,0],[1,1]",
"fill (20,20)-(20,30) [0,1],[0,1]",
`screen-800x600 <- string "X" atpoint: (46,10) [2,0] fill: black`,
},
},
{
// Append a pair of characters at the end of the otherwise full text
// area.
name: "appendAtEnd",
fn: appendAtEnd,
textarea: image.Rect(20, 10, 59, 60),
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,50) [0,1],[3,3]",
"fill (20,50)-(59,60) [0,4],[3,1]",
`screen-800x600 <- string "0ab" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "1cd" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "2ef" atpoint: (20,30) [0,2] fill: black`,
`screen-800x600 <- string "3gh" atpoint: (20,40) [0,3] fill: black`,
`screen-800x600 <- string "4ij" atpoint: (20,50) [0,4] fill: black`,
"fill (58,50)-(59,60) [-,4],[-,1]",
// Doesn't this stick below? it's 0 wide?
"fill (20,60)-(20,70) [0,5],[0,1]",
},
},
{
// Append a multibox string that hangs off the end. TODO(rjk): Draws a
// zero-width fill off the end of text area. This is conceivably wrong.
// It would (for example) make some drawing stacks unhappy.
name: "appendHangingLongAtEnd",
fn: appendHangingLongAtEnd,
textarea: image.Rect(20, 10, 59, 60),
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,60) [0,1],[3,4]",
"fill (20,60)-(20,70) [0,5],[0,1]",
`screen-800x600 <- string "0" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "1" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "2" atpoint: (20,30) [0,2] fill: black`,
`screen-800x600 <- string "3" atpoint: (20,40) [0,3] fill: black`,
`screen-800x600 <- string "4" atpoint: (20,50) [0,4] fill: black`,
"fill (33,50)-(59,60) [1,4],[2,1]",
"fill (20,60)-(20,70) [0,5],[0,1]",
`screen-800x600 <- string "XX" atpoint: (33,50) [1,4] fill: black`,
},
},
{
// Insert a multibox string that forces ripple past the end.
name: "insertWrappedThatForcesRipple",
fn: insertWrappedThatForcesRipple,
textarea: image.Rect(20, 10, 59, 60),
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,60) [0,1],[3,4]",
"fill (20,60)-(20,70) [0,5],[0,1]",
`screen-800x600 <- string "0" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "1" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "2" atpoint: (20,30) [0,2] fill: black`,
`screen-800x600 <- string "3b" atpoint: (20,40) [0,3] fill: black`,
`screen-800x600 <- string "4" atpoint: (20,50) [0,4] fill: black`,
"fill (59,50)-(59,60) [3,4],[0,1]",
"blit (33,40)-(46,50) [1,3],[1,1], to (46,50)-(59,60) [2,4],[1,1]",
"fill (33,40)-(59,50) [1,3],[2,1]",
"fill (20,50)-(46,60) [0,4],[2,1]",
`screen-800x600 <- string "ij" atpoint: (33,40) [1,3] fill: black`,
`screen-800x600 <- string "XX" atpoint: (20,50) [0,4] fill: black`,
},
},
{
// Insert a string that pushes a blank line off the end.
name: "insertPushesBlankLineOffEnd",
fn: insertPushesBlankLineOffEnd,
textarea: image.Rect(20, 10, 59, 60),
want: []string{
"fill (20,10)-(59,20) [0,0],[3,1]",
"fill (20,20)-(59,60) [0,1],[3,4]",
"fill (20,60)-(20,70) [0,5],[0,1]",
`screen-800x600 <- string "0ab" atpoint: (20,10) [0,0] fill: black`,
`screen-800x600 <- string "1cd" atpoint: (20,20) [0,1] fill: black`,
`screen-800x600 <- string "2ef" atpoint: (20,30) [0,2] fill: black`,
`screen-800x600 <- string "3gh" atpoint: (20,40) [0,3] fill: black`,
"blit (20,30)-(59,50) [0,2],[3,2], to (20,40)-(59,60) [0,3],[3,2]",
"blit (59,20)-(59,30) [3,1],[0,1], to (59,30)-(59,40) [3,2],[0,1]",
"blit (20,20)-(59,30) [0,1],[3,1], to (20,30)-(59,40) [0,2],[3,1]",
"fill (33,20)-(59,30) [1,1],[2,1]",
"blit (46,10)-(59,20) [2,0],[1,1], to (20,20)-(33,30) [0,1],[1,1]",
"blit (33,10)-(46,20) [1,0],[1,1], to (46,10)-(59,20) [2,0],[1,1]",
"fill (59,10)-(59,20) [3,0],[0,1]",
"fill (33,10)-(46,20) [1,0],[1,1]",
`screen-800x600 <- string "X" atpoint: (33,10) [1,0] fill: black`,
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.knowntofail {
return
}
iv.textarea = tc.textarea
fr := setupFrame(t, iv)
// TODO(rjk): validate here
tc.fn(t, fr, iv)
// TODO(rjk): validate here
// Peek inside.
got := gdo(t, fr).DrawOps()
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("dump mismatch (-want +got):\n%s", diff)
}
visualizedoutputtest(t, fr)
})
}
}