-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathscreen_test.go
53 lines (48 loc) · 1.13 KB
/
screen_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
package terminal
import (
"testing"
"github.com/google/go-cmp/cmp"
)
var currentLineForWritingTestCases = []struct {
name string
input string
want []string
maxlines int
}{
{
name: "Test no index out of range panic",
input: "\n",
want: []string{" \n"},
maxlines: 1,
},
{
name: "Test scroll out first line",
input: "a\n",
want: []string{"a\n"},
maxlines: 1,
},
{
name: "Test scroll out several lines",
input: "a\nb\nc\nd",
want: []string{"a\n", "b\n"},
maxlines: 2,
},
}
func TestCurrentLineForWriting(t *testing.T) {
for _, test := range currentLineForWritingTestCases {
t.Run(test.name, func(t *testing.T) {
s, err := NewScreen(WithMaxSize(0, test.maxlines))
if err != nil {
t.Fatalf("NewScreen(WithMaxSize(0, %d)) error: %s", test.maxlines, err)
}
got := []string{}
s.ScrollOutFunc = func(line string) { got = append(got, line) }
_ = s.currentLineForWriting()
s.Write([]byte(test.input))
_ = s.currentLineForWriting()
if diff := cmp.Diff(got, test.want); diff != "" {
t.Errorf("scrolledOutFunc sequence of parameters diff (-got +want):\n%s", diff)
}
})
}
}