forked from bokwoon95/wgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_unix_test.go
71 lines (66 loc) · 2.02 KB
/
util_unix_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
59
60
61
62
63
64
65
66
67
68
69
70
71
//go:build !windows
// +build !windows
package main
import "testing"
func Test_joinArgs(t *testing.T) {
type TestTable struct {
description string
args []string
want string
}
tests := []TestTable{{
description: "bare string",
args: []string{"echo", "test"},
want: "echo test",
}, {
description: "contains spaces",
args: []string{"echo", "hello goodbye"},
want: "echo 'hello goodbye'",
}, {
description: "simple args",
args: []string{"echo", "hello", "goodbye"},
want: "echo hello goodbye",
}, {
description: "single quote",
args: []string{"echo", "don't you know the dewey decimal system?"},
want: "echo 'don'\\''t you know the dewey decimal system?'",
}, {
description: "args with single quote",
args: []string{"echo", "don't", "you", "know", "the", "dewey", "decimal", "system?"},
want: "echo don\\'t you know the dewey decimal system\\?",
}, {
description: "tilde bang",
args: []string{"echo", "~user", "u~ser", " ~user", "!~user"},
want: "echo \\~user u~ser ' ~user' \\!~user",
}, {
description: "glob brackets",
args: []string{"echo", "foo*", "M{ovies,usic}", "ab[cd]", "%3"},
want: "echo foo\\* M\\{ovies,usic} ab\\[cd] %3",
}, {
description: "empty string",
args: []string{"echo", "one", "", "three"},
want: "echo one '' three",
}, {
description: "parens",
args: []string{"echo", "some(parentheses)"},
want: "echo some\\(parentheses\\)",
}, {
description: "special chars",
args: []string{"echo", "$some_ot~her_)spe!cial_*_characters"},
want: "echo \\$some_ot~her_\\)spe\\!cial_\\*_characters",
}, {
description: "quote space",
args: []string{"echo", "' "},
want: "echo \\'' '",
}}
for _, tt := range tests {
tt := tt
t.Run(tt.description, func(t *testing.T) {
t.Parallel()
got := joinArgs(tt.args)
if got != tt.want {
t.Errorf("\ngot: %q\nwant: %q", got, tt.want)
}
})
}
}