This patch adds some tests to ensure that quoted flags are properly
handled by the mflag package.
Docker-DCO-1.1-Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> (github: cyphar)
| ... | ... |
@@ -173,6 +173,12 @@ func testParse(f *FlagSet, t *testing.T) {
|
| 173 | 173 |
uintFlag := f.Uint([]string{"uint"}, 0, "uint value")
|
| 174 | 174 |
uint64Flag := f.Uint64([]string{"-uint64"}, 0, "uint64 value")
|
| 175 | 175 |
stringFlag := f.String([]string{"string"}, "0", "string value")
|
| 176 |
+ singleQuoteFlag := f.String([]string{"squote"}, "", "single quoted value")
|
|
| 177 |
+ doubleQuoteFlag := f.String([]string{"dquote"}, "", "double quoted value")
|
|
| 178 |
+ mixedQuoteFlag := f.String([]string{"mquote"}, "", "mixed quoted value")
|
|
| 179 |
+ mixed2QuoteFlag := f.String([]string{"mquote2"}, "", "mixed2 quoted value")
|
|
| 180 |
+ nestedQuoteFlag := f.String([]string{"nquote"}, "", "nested quoted value")
|
|
| 181 |
+ nested2QuoteFlag := f.String([]string{"nquote2"}, "", "nested2 quoted value")
|
|
| 176 | 182 |
float64Flag := f.Float64([]string{"float64"}, 0, "float64 value")
|
| 177 | 183 |
durationFlag := f.Duration([]string{"duration"}, 5*time.Second, "time.Duration value")
|
| 178 | 184 |
extra := "one-extra-argument" |
| ... | ... |
@@ -184,6 +190,12 @@ func testParse(f *FlagSet, t *testing.T) {
|
| 184 | 184 |
"-uint", "24", |
| 185 | 185 |
"--uint64", "25", |
| 186 | 186 |
"-string", "hello", |
| 187 |
+ "-squote='single'", |
|
| 188 |
+ `-dquote="double"`, |
|
| 189 |
+ `-mquote='mixed"`, |
|
| 190 |
+ `-mquote2="mixed2'`, |
|
| 191 |
+ `-nquote="'single nested'"`, |
|
| 192 |
+ `-nquote2='"double nested"'`, |
|
| 187 | 193 |
"-float64", "2718e28", |
| 188 | 194 |
"-duration", "2m", |
| 189 | 195 |
extra, |
| ... | ... |
@@ -215,6 +227,24 @@ func testParse(f *FlagSet, t *testing.T) {
|
| 215 | 215 |
if *stringFlag != "hello" {
|
| 216 | 216 |
t.Error("string flag should be `hello`, is ", *stringFlag)
|
| 217 | 217 |
} |
| 218 |
+ if *singleQuoteFlag != "single" {
|
|
| 219 |
+ t.Error("single quote string flag should be `single`, is ", *singleQuoteFlag)
|
|
| 220 |
+ } |
|
| 221 |
+ if *doubleQuoteFlag != "double" {
|
|
| 222 |
+ t.Error("double quote string flag should be `double`, is ", *doubleQuoteFlag)
|
|
| 223 |
+ } |
|
| 224 |
+ if *mixedQuoteFlag != `'mixed"` {
|
|
| 225 |
+ t.Error("mixed quote string flag should be `'mixed\"`, is ", *mixedQuoteFlag)
|
|
| 226 |
+ } |
|
| 227 |
+ if *mixed2QuoteFlag != `"mixed2'` {
|
|
| 228 |
+ t.Error("mixed2 quote string flag should be `\"mixed2'`, is ", *mixed2QuoteFlag)
|
|
| 229 |
+ } |
|
| 230 |
+ if *nestedQuoteFlag != "'single nested'" {
|
|
| 231 |
+ t.Error("nested quote string flag should be `'single nested'`, is ", *nestedQuoteFlag)
|
|
| 232 |
+ } |
|
| 233 |
+ if *nested2QuoteFlag != `"double nested"` {
|
|
| 234 |
+ t.Error("double quote string flag should be `\"double nested\"`, is ", *nested2QuoteFlag)
|
|
| 235 |
+ } |
|
| 218 | 236 |
if *float64Flag != 2718e28 {
|
| 219 | 237 |
t.Error("float64 flag should be 2718e28, is ", *float64Flag)
|
| 220 | 238 |
} |