Browse code

Add missing unit testcase for new IsSet() func in mflag

Forgot to add this when I did PR #9259

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2014/11/22 22:25:57
Showing 1 changed files
... ...
@@ -168,11 +168,14 @@ func testParse(f *FlagSet, t *testing.T) {
168 168
 	}
169 169
 	boolFlag := f.Bool([]string{"bool"}, false, "bool value")
170 170
 	bool2Flag := f.Bool([]string{"bool2"}, false, "bool2 value")
171
+	f.Bool([]string{"bool3"}, false, "bool3 value")
172
+	bool4Flag := f.Bool([]string{"bool4"}, false, "bool4 value")
171 173
 	intFlag := f.Int([]string{"-int"}, 0, "int value")
172 174
 	int64Flag := f.Int64([]string{"-int64"}, 0, "int64 value")
173 175
 	uintFlag := f.Uint([]string{"uint"}, 0, "uint value")
174 176
 	uint64Flag := f.Uint64([]string{"-uint64"}, 0, "uint64 value")
175 177
 	stringFlag := f.String([]string{"string"}, "0", "string value")
178
+	f.String([]string{"string2"}, "0", "string2 value")
176 179
 	singleQuoteFlag := f.String([]string{"squote"}, "", "single quoted value")
177 180
 	doubleQuoteFlag := f.String([]string{"dquote"}, "", "double quoted value")
178 181
 	mixedQuoteFlag := f.String([]string{"mquote"}, "", "mixed quoted value")
... ...
@@ -185,6 +188,7 @@ func testParse(f *FlagSet, t *testing.T) {
185 185
 	args := []string{
186 186
 		"-bool",
187 187
 		"-bool2=true",
188
+		"-bool4=false",
188 189
 		"--int", "22",
189 190
 		"--int64", "0x23",
190 191
 		"-uint", "24",
... ...
@@ -212,6 +216,18 @@ func testParse(f *FlagSet, t *testing.T) {
212 212
 	if *bool2Flag != true {
213 213
 		t.Error("bool2 flag should be true, is ", *bool2Flag)
214 214
 	}
215
+	if !f.IsSet("bool2") {
216
+		t.Error("bool2 should be marked as set")
217
+	}
218
+	if f.IsSet("bool3") {
219
+		t.Error("bool3 should not be marked as set")
220
+	}
221
+	if !f.IsSet("bool4") {
222
+		t.Error("bool4 should be marked as set")
223
+	}
224
+	if *bool4Flag != false {
225
+		t.Error("bool4 flag should be false, is ", *bool4Flag)
226
+	}
215 227
 	if *intFlag != 22 {
216 228
 		t.Error("int flag should be 22, is ", *intFlag)
217 229
 	}
... ...
@@ -227,6 +243,12 @@ func testParse(f *FlagSet, t *testing.T) {
227 227
 	if *stringFlag != "hello" {
228 228
 		t.Error("string flag should be `hello`, is ", *stringFlag)
229 229
 	}
230
+	if !f.IsSet("string") {
231
+		t.Error("string flag should be marked as set")
232
+	}
233
+	if f.IsSet("string2") {
234
+		t.Error("string2 flag should not be marked as set")
235
+	}
230 236
 	if *singleQuoteFlag != "single" {
231 237
 		t.Error("single quote string flag should be `single`, is ", *singleQuoteFlag)
232 238
 	}