@@ -152,6 +152,34 @@ func TestImplicitFalse(t *testing.T) {
152152 }
153153}
154154
155+ func TestCustomIsBoolFlagGetsNoOptDefaultAutomatically (t * testing.T ) {
156+ var tristate triStateValue
157+ f := NewFlagSet ("test" , ContinueOnError )
158+ tristate = triStateFalse
159+ f .VarPF (& tristate , "tristate" , "t" , "tristate value (true, maybe or false)" )
160+
161+ if err := f .Parse ([]string {"--tristate" }); err != nil {
162+ t .Fatal ("expected no error; got" , err )
163+ }
164+ if tristate != triStateTrue {
165+ t .Fatal ("expected" , triStateTrue , "(triStateTrue) but got" , tristate , "instead" )
166+ }
167+ }
168+
169+ func TestCustomIsBoolFlagShortFormGetsNoOptDefaultAutomatically (t * testing.T ) {
170+ var tristate triStateValue
171+ f := NewFlagSet ("test" , ContinueOnError )
172+ tristate = triStateFalse
173+ f .VarPF (& tristate , "tristate" , "t" , "tristate value (true, maybe or false)" )
174+
175+ if err := f .Parse ([]string {"-t" }); err != nil {
176+ t .Fatal ("expected no error; got" , err )
177+ }
178+ if tristate != triStateTrue {
179+ t .Fatal ("expected" , triStateTrue , "(triStateTrue) but got" , tristate , "instead" )
180+ }
181+ }
182+
155183func TestInvalidValue (t * testing.T ) {
156184 var tristate triStateValue
157185 f := setUpFlagSet (& tristate )
0 commit comments