-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_test.go
More file actions
104 lines (93 loc) · 2.34 KB
/
Copy pathsplit_test.go
File metadata and controls
104 lines (93 loc) · 2.34 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
95
96
97
98
99
100
101
102
103
104
package netargv
import (
"reflect"
"testing"
)
func TestSplitWords_Simple(t *testing.T) {
got, err := splitWords("hello world")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, []string{"hello", "world"}) {
t.Fatalf("got %v", got)
}
}
func TestSplitWords_DoubleQuoted(t *testing.T) {
got, err := splitWords(`--message="Job not supported"`)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, []string{"--message=Job not supported"}) {
t.Fatalf("got %v", got)
}
}
func TestSplitWords_SingleQuoted(t *testing.T) {
got, err := splitWords("--message='hello world'")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, []string{"--message=hello world"}) {
t.Fatalf("got %v", got)
}
}
func TestSplitWords_QuotedTokenMergesWithBarePrefix(t *testing.T) {
// The quote immediately follows = so prefix and quoted content merge into one token.
got, err := splitWords(`--flag="spaced value"`)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, []string{"--flag=spaced value"}) {
t.Fatalf("got %v", got)
}
}
func TestSplitWords_MultipleTokens(t *testing.T) {
got, err := splitWords(`cmd arg1 --flag=val`)
if err != nil {
t.Fatal(err)
}
want := []string{"cmd", "arg1", "--flag=val"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("want %v, got %v", want, got)
}
}
func TestSplitWords_ExtraWhitespace(t *testing.T) {
got, err := splitWords(" cmd arg1 ")
if err != nil {
t.Fatal(err)
}
want := []string{"cmd", "arg1"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("want %v, got %v", want, got)
}
}
func TestSplitWords_EmptyString(t *testing.T) {
got, err := splitWords("")
if err != nil {
t.Fatal(err)
}
if len(got) != 0 {
t.Fatalf("expected empty, got %v", got)
}
}
func TestSplitWords_UnclosedDoubleQuote(t *testing.T) {
_, err := splitWords(`--msg="never closed`)
if err == nil {
t.Fatal("expected error for unclosed double quote")
}
}
func TestSplitWords_UnclosedSingleQuote(t *testing.T) {
_, err := splitWords(`--msg='never closed`)
if err == nil {
t.Fatal("expected error for unclosed single quote")
}
}
func TestSplitWords_AdjacentQuotedAndBare(t *testing.T) {
// Quoted span abutting a bare span — both belong to the same token.
got, err := splitWords(`pre"mid"suf`)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, []string{"premidsuf"}) {
t.Fatalf("got %v", got)
}
}