-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
94 lines (79 loc) · 2.88 KB
/
Copy pathcommand_test.go
File metadata and controls
94 lines (79 loc) · 2.88 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
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 command_test
import (
"testing"
"github.com/gloo-foo/testable"
"github.com/gloo-foo/testable/assertion"
"github.com/gloo-foo/testable/run"
command "github.com/gloo-foo/cmd-xargs"
)
func TestXargs_DefaultSplitsEachField(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(), "one two three\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"one", "two", "three"})
}
func TestXargs_N1ExplicitSameAsDefault(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(command.XargsMaxArgs(1)), "a b c\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"a", "b", "c"})
}
func TestXargs_N2GroupsPairs(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(command.XargsMaxArgs(2)), "a b c d\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"a b", "c d"})
}
func TestXargs_N2OddRemainder(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(command.XargsMaxArgs(2)), "a b c\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"a b", "c"})
}
func TestXargs_N3GroupsTriples(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(command.XargsMaxArgs(3)), "1 2 3 4 5 6 7\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"1 2 3", "4 5 6", "7"})
}
func TestXargs_EmptyInput(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(), "")
assertion.NoError(t, err)
assertion.Empty(t, lines)
}
func TestXargs_SingleField(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(), "only\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"only"})
}
func TestXargs_SingleFieldN2(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(command.XargsMaxArgs(2)), "only\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"only"})
}
func TestXargs_MultiLineInput(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(command.XargsMaxArgs(2)), "a b\nc d\n")
assertion.NoError(t, err)
assertion.Lines(t, lines, []string{"a b", "c d"})
}
func TestXargs_WhitespaceOnlyLine(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(), " \n")
assertion.NoError(t, err)
assertion.Empty(t, lines)
}
func TestXargs_TableDriven(t *testing.T) {
tests := []struct {
name string
opts []any
input string
expected []string
}{
{"default-3-fields", nil, "x y z\n", []string{"x", "y", "z"}},
{"n2-even", []any{command.XargsMaxArgs(2)}, "a b c d\n", []string{"a b", "c d"}},
{"n2-odd", []any{command.XargsMaxArgs(2)}, "a b c\n", []string{"a b", "c"}},
{"n4-fewer", []any{command.XargsMaxArgs(4)}, "a b\n", []string{"a b"}},
{"tabs-and-spaces", nil, "a\tb c\n", []string{"a", "b", "c"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lines, err := testable.TestLines(command.Xargs(tt.opts...), run.Input(tt.input))
assertion.NoError(t, err)
assertion.Lines(t, lines, tt.expected)
})
}
}