-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpromptkit_test.go
47 lines (35 loc) · 964 Bytes
/
promptkit_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
package promptkit_test
import (
"testing"
"github.com/erikgeiser/promptkit"
"github.com/erikgeiser/promptkit/test"
)
func TestWordWrap(t *testing.T) {
t.Parallel()
text := "ab cde fgh ijklmnopq rs"
expected := "ab cde\nfgh\nijklmno\npq\nrs"
assertEqual(t, expected, promptkit.WordWrap(text, 7))
}
func TestHardWrap(t *testing.T) {
t.Parallel()
text := "ab cde fgh ijklmnopq rs"
expected := "ab cde \nfgh ijk\nlmnopq \nrs"
assertEqual(t, expected, promptkit.HardWrap(text, 7))
}
func TestTruncate(t *testing.T) {
t.Parallel()
text := "0123456789\n0123\n0123456789\n"
expected := "012345\n0123\n012345\n"
assertEqual(t, expected, promptkit.Truncate(text, 6))
}
func assertEqual(tb testing.TB, expected string, got string) {
tb.Helper()
if expected == got {
return
}
comparison := "Expected:\n%s\nGot:\n%s"
if *test.Inspect {
comparison = "Expected:\n%q\nGot:\n%q"
}
tb.Errorf("unexpected result:\n"+comparison, expected, got)
}