-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrender_test.go
137 lines (131 loc) · 2.49 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
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
/*
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
logpkg "log"
"os"
"testing"
)
func init() {
log = logpkg.New(os.Stderr, "", logpkg.LstdFlags)
}
func compareRunePage(rs [][]rune, ss []string) error {
if len(rs) != len(ss) {
max := len(rs)
if len(ss) > max {
max = len(ss)
}
for i := 0; i < max; i++ {
if i < len(rs) {
fmt.Printf(">%s\n", string(rs[i]))
}
if i < len(ss) {
fmt.Printf("<%s\n", ss[i])
}
}
return fmt.Errorf("wrong number of lines: got %d, want %d", len(rs), len(ss))
}
for i := range rs {
if string(rs[i]) != ss[i] {
return fmt.Errorf("line %d: got %q, want %q", i, string(rs[i]), ss[i])
}
}
return nil
}
func TestGetBufferLinesToShow(t *testing.T) {
type c struct {
in string
outs []string
}
for i, tc := range []c{
{
"one short line",
[]string{
"one short line",
},
},
{
"two short\nlines",
[]string{
"two short",
"lines",
},
},
{
"one long line that is past the 20 char limit",
[]string{
"one long line that i",
"s past the 20 char l",
"imit",
},
},
{
"a string\n\nwith a blank line",
[]string{
"a string",
"",
"with a blank line",
},
},
{
"\n\n",
[]string{
"",
"",
},
},
{
"too\nmany\nlines\nto\nshow",
[]string{
"lines",
"to",
"show",
},
},
{
"\tone tab\nk\ttwo tab\n",
[]string{
" one tab",
"k two tab",
"",
},
},
} {
rs, _ := getBufferLinesToShow(3, 20, 0, tc.in)
if err := compareRunePage(rs, tc.outs); err != nil {
t.Errorf("Case %d: %v", i, err)
}
}
}
func TestGetBufferLinesToShowScroll(t *testing.T) {
type c struct {
in string
outs []string
}
for i, tc := range []c{
{
"too\nmany\nlines\nto\nshow",
[]string{
"too",
"many",
"lines",
},
},
} {
rs, _ := getBufferLinesToShow(3, 20, 2, tc.in)
if err := compareRunePage(rs, tc.outs); err != nil {
t.Errorf("Case %d: %v", i, err)
}
}
}