forked from profclems/glab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtruncate_test.go
94 lines (85 loc) · 2.01 KB
/
truncate_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
package text
import "testing"
func TestTruncate(t *testing.T) {
type args struct {
s string
length int
}
tests := []struct {
name string
args args
want string
}{
{
name: "short",
args: args{
s: "shortword",
length: 9,
},
want: "shortword",
},
{
name: "long sentence",
args: args{
s: "this is a really long sentence",
length: 10,
},
want: "this is...",
},
{
name: "hyperlink prefix",
args: args{
s: "\033]8;;https://example.com\033\\this\033]8;;\033\\ is a really long sentence",
length: 10,
},
want: "\033]8;;https://example.com\033\\this\033]8;;\033\\ is...",
},
{
name: "hyperlink prefix but shorter",
args: args{
s: "\033]8;;https://example.com\033\\this\033]8;;\033\\ is a really long sentence",
length: 4,
},
want: "\033]8;;https://example.com\033\\t...\033]8;;\033\\",
},
{
name: "hyperlink infix",
args: args{
s: "this \033]8;;https://example.com\033\\is\033]8;;\033\\ a really long sentence",
length: 10,
},
want: "this \033]8;;https://example.com\033\\is\033]8;;\033\\...",
},
{
name: "hyperlink infix straddling ellipsis",
args: args{
s: "this \033]8;;https://example.com\033\\is\033]8;;\033\\ a really long sentence",
length: 9,
},
want: "this \033]8;;https://example.com\033\\i.\033]8;;\033\\..",
},
{
name: "hyperlink suffix",
args: args{
s: "this is a really long \033]8;;https://example.com\033\\sentence\033]8;;\033\\",
length: 10,
},
want: "this is...",
},
{
name: "hyperlink suffix take 2",
args: args{
s: "this \033]8;;https://example.com\033\\is a really long sentence\033]8;;\033\\",
length: 10,
},
want: "this \033]8;;https://example.com\033\\is...\033]8;;\033\\",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Truncate(tt.args.s, tt.args.length); got != tt.want {
t.Errorf("Truncate() = %q, want %q", got, tt.want)
}
})
}
}