-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples_test.go
58 lines (52 loc) · 1.21 KB
/
examples_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
package wordwrap_test
import (
"fmt"
"github.com/spenserblack/go-wordwrap"
)
// Words are wrapped at whitespace and at hyphens. Wrapping whitespace is
// trimmed, hyphens are kept. If a word is too long to fit in the limit, it
// will be broken at the limit.
func Example() {
lines := wordwrap.WordWrap("this test-string has been successfully wrapped successfully", 10)
for _, line := range lines {
fmt.Println(line)
}
// Output:
// this test-
// string has
// been
// successful
// ly wrapped
// successful
// ly
}
// Words are wrapped at spaces.
func ExampleWordWrap_space() {
lines := wordwrap.WordWrap("we wrap at spaces", 9)
for _, line := range lines {
fmt.Println(line)
}
// Output:
// we wrap
// at spaces
}
// Words are wrapped at hyphens, and the hyphens are kept at the ends of lines.
func ExampleWordWrap_hyphen() {
lines := wordwrap.WordWrap("hyphenated-words", 15)
for _, line := range lines {
fmt.Println(line)
}
// Output:
// hyphenated-
// words
}
// Words that are too long for the limit will be broken.
func ExampleWordWrap_long() {
lines := wordwrap.WordWrap("longwordsarewrapped", 10)
for _, line := range lines {
fmt.Println(line)
}
// Output:
// longwordsa
// rewrapped
}