-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils_test.go
More file actions
59 lines (53 loc) · 1.38 KB
/
Copy pathutils_test.go
File metadata and controls
59 lines (53 loc) · 1.38 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
package main
import (
"strings"
"testing"
)
func TestWrapSingleLine(t *testing.T) {
line := "one two three four"
got := wrapSingleLine(line, 8)
want := "one two\nthree\nfour"
if got != want {
t.Errorf("wrapSingleLine() = %q, want %q", got, want)
}
if got := wrapSingleLine(line, 50); got != line {
t.Errorf("wrapSingleLine() = %q, want %q", got, line)
}
}
func TestSplitIntoLines(t *testing.T) {
input := "a\nb\r\nc"
want := []string{"a", "b", "c"}
got := splitIntoLines(input)
if len(got) != len(want) {
t.Fatalf("splitIntoLines length = %d, want %d", len(got), len(want))
}
for i := range want {
if got[i] != want[i] {
t.Errorf("splitIntoLines[%d] = %q, want %q", i, got[i], want[i])
}
}
}
func TestWrap(t *testing.T) {
text := "hello world\n\nfoo bar baz"
want := "hello\nworld\n\nfoo\nbar\nbaz"
if got := wrap(text, 6); got != want {
t.Errorf("wrap() = %q, want %q", got, want)
}
}
func TestExampleCommands(t *testing.T) {
examples := []example{{"-h", "help"}, {"--version", "print version"}}
output := exampleCommands("cmd", examples)
lines := strings.Split(output, "\n")
if len(lines) != 2 {
t.Fatalf("expected 2 lines, got %d", len(lines))
}
expected := []string{
" cmd -h help",
" cmd --version print version",
}
for i, line := range lines {
if line != expected[i] {
t.Errorf("line %d = %q, want %q", i, line, expected[i])
}
}
}