-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test.go
104 lines (100 loc) · 2.03 KB
/
unit_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
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 xopconsole
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOneString(t *testing.T) {
cases := []struct {
name string
input string
want string
remainder string
}{
{
input: "",
want: "",
},
{
input: "foo xyz",
want: "foo",
remainder: " xyz",
},
{
input: "foo=bar xyz",
want: "foo",
remainder: "=bar xyz",
},
{
input: "foo-bar=bar xyz",
want: "foo-bar",
},
{
name: "oddchars",
input: "foo-'$#@[]bar=bar xyz",
want: "foo-'$#@[]bar",
},
{
name: "quoted",
input: strconv.Quote(`f"oo-'$#\@[]bar`) + "=bar xyz",
want: `f"oo-'$#\@[]bar`,
remainder: "=bar xyz",
},
}
for _, tc := range cases {
name := tc.name
if name == "" {
name = tc.input
}
t.Run(name, func(t *testing.T) {
got, gotRemainder := oneString(tc.input)
var wantRemainder string
if tc.remainder == "" {
wantRemainder = tc.input[len(tc.want):]
} else {
wantRemainder = tc.remainder
}
if assert.Equal(t, tc.want, got, "string") {
assert.Equal(t, wantRemainder, gotRemainder, "remainder")
}
})
}
}
func TestOneWord(t *testing.T) {
cases := []struct {
name string
input string
breakOn string
want string
remainder string
wantSep byte
}{
{
name: "regression",
input: `"a test {foo} with {num}" foo=bar num=38`,
breakOn: " ",
want: "a test {foo} with {num}",
wantSep: ' ',
remainder: "foo=bar num=38",
},
}
for _, tc := range cases {
name := tc.name
if name == "" {
name = tc.input
}
t.Run(name, func(t *testing.T) {
got, sep, gotRemainder := oneWordMaybeQuoted(tc.input, tc.breakOn)
var wantRemainder string
if tc.remainder == "" {
wantRemainder = tc.input[len(tc.want):]
} else {
wantRemainder = tc.remainder
}
if assert.Equal(t, tc.want, got, "string") {
assert.Equal(t, wantRemainder, gotRemainder, "remainder")
}
assert.Equal(t, string(tc.wantSep), string(sep), "sep")
})
}
}