-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrap_test.go
More file actions
62 lines (53 loc) · 1.43 KB
/
wrap_test.go
File metadata and controls
62 lines (53 loc) · 1.43 KB
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
package str
import "testing"
func TestWrap(t *testing.T) {
long := "This is a string that could very likely be broken up into more than one line"
t.Run("before word default", func(t *testing.T) {
got := Wrap(24)(long)
// Each line should be <= 24 runes (words aren't split).
if got == long {
t.Error("expected wrapping")
}
if got == "" {
t.Error("got empty string")
}
})
t.Run("after word", func(t *testing.T) {
got := Wrap(24, WrapAfterWord)(long)
if got == long {
t.Error("expected wrapping")
}
})
t.Run("hard break", func(t *testing.T) {
got := Wrap(24, WrapHardBreak)("abcdefghijklmnopqrstuvwxyz1234567890")
expected := "abcdefghijklmnopqrstuvwx\nyz1234567890"
if got != expected {
t.Errorf("got %q, want %q", got, expected)
}
})
t.Run("custom line break", func(t *testing.T) {
got := Wrap(10, WrapHardBreak, WithLineBreak("<br>"))("abcdefghijklmnop")
expected := "abcdefghij<br>klmnop"
if got != expected {
t.Errorf("got %q, want %q", got, expected)
}
})
t.Run("with indent", func(t *testing.T) {
got := Wrap(20, WithIndent(" "))("hello world this is a test")
if got == "" {
t.Error("got empty string")
}
})
t.Run("width zero", func(t *testing.T) {
got := Wrap(0)("hello")
if got != "hello" {
t.Errorf("got %q, want %q", got, "hello")
}
})
t.Run("empty input", func(t *testing.T) {
got := Wrap(10)("")
if got != "" {
t.Errorf("got %q, want empty", got)
}
})
}