File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424 just sysinfo
2525 - name : Run Go Test
2626 run : |
27- just init tidy lint test
27+ just init tidy lint tests
2828
Original file line number Diff line number Diff line change @@ -13,9 +13,15 @@ default:
1313tidy :
1414 go mod tidy
1515
16+ # run specific unit test
17+ [group (' build' )]
18+ [no-cd ]
19+ test unit :
20+ go test -v -count=1 -race -run {{ unit}} 2 >/ dev/ null
21+
1622# run tests across source tree
1723[group (' build' )]
18- test :
24+ tests :
1925 go test -v -race -count=1 ./ ...
2026
2127# apply go vet command on source tree
Original file line number Diff line number Diff line change @@ -251,20 +251,23 @@ func BoolOr(b *bool, alt bool) Parser {
251251}
252252
253253func (p * boolParser ) Parse (values []string ) error {
254+ var b bool
255+ var err error
256+
254257 switch {
255258 case len (values ) > 1 :
256259 return ErrMulitpleValues
257260 case len (values ) == 0 && p .required :
258261 return ErrNoValue
259262 case len (values ) == 0 :
260263 return nil
261- }
262-
263- b , err := strconv . ParseBool ( values [ 0 ])
264- if err != nil {
265- return err
264+ case values [ 0 ] == "on" :
265+ // HTML checkbox uses "on" to indicate checked
266+ b = true
267+ default :
268+ b , err = strconv . ParseBool ( values [ 0 ])
266269 }
267270
268271 * p .destination = b
269- return nil
272+ return err
270273}
Original file line number Diff line number Diff line change @@ -247,6 +247,21 @@ func Test_Parse_float_malformed(t *testing.T) {
247247 must .Error (t , err )
248248}
249249
250+ func Test_Parse_Bool_checkbox_on (t * testing.T ) {
251+ t .Parallel ()
252+
253+ data := url.Values {
254+ "checkbox" : []string {"on" },
255+ }
256+
257+ var cb bool
258+ err := ParseValues (data , Schema {
259+ "checkbox" : Bool (& cb ),
260+ })
261+ must .NoError (t , err )
262+ must .True (t , cb )
263+ }
264+
250265func Test_Parse_bool_value_missing (t * testing.T ) {
251266 t .Parallel ()
252267
You can’t perform that action at this time.
0 commit comments