File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -387,7 +387,7 @@ func intDecoder(bits int) MapperFunc { //nolint: dupl
387
387
default :
388
388
return fmt .Errorf ("expected an int but got %q (%T)" , t , t .Value )
389
389
}
390
- n , err := strconv .ParseInt (sv , 10 , bits )
390
+ n , err := strconv .ParseInt (sv , 0 , bits )
391
391
if err != nil {
392
392
return fmt .Errorf ("expected a valid %d bit int but got %q" , bits , sv )
393
393
}
@@ -416,7 +416,7 @@ func uintDecoder(bits int) MapperFunc { //nolint: dupl
416
416
default :
417
417
return fmt .Errorf ("expected an int but got %q (%T)" , t , t .Value )
418
418
}
419
- n , err := strconv .ParseUint (sv , 10 , bits )
419
+ n , err := strconv .ParseUint (sv , 0 , bits )
420
420
if err != nil {
421
421
return fmt .Errorf ("expected a valid %d bit uint but got %q" , bits , sv )
422
422
}
Original file line number Diff line number Diff line change @@ -395,6 +395,31 @@ func TestNumbers(t *testing.T) {
395
395
I64 : math .MinInt64 ,
396
396
}, cli )
397
397
})
398
+ t .Run ("Integer literals" , func (t * testing.T ) {
399
+ integerLiterals := "10_0"
400
+
401
+ _ , err := p .Parse ([]string {
402
+ fmt .Sprintf ("--i-8=%s" , integerLiterals ),
403
+ fmt .Sprintf ("--i-16=%s" , integerLiterals ),
404
+ fmt .Sprintf ("--i-32=%s" , integerLiterals ),
405
+ fmt .Sprintf ("--i-64=%s" , integerLiterals ),
406
+ fmt .Sprintf ("--u-8=%s" , integerLiterals ),
407
+ fmt .Sprintf ("--u-16=%s" , integerLiterals ),
408
+ fmt .Sprintf ("--u-32=%s" , integerLiterals ),
409
+ fmt .Sprintf ("--u-64=%s" , integerLiterals ),
410
+ })
411
+ assert .NoError (t , err )
412
+ assert .Equal (t , CLI {
413
+ I8 : int8 (100 ),
414
+ I16 : int16 (100 ),
415
+ I32 : int32 (100 ),
416
+ I64 : int64 (100 ),
417
+ U8 : uint8 (100 ),
418
+ U16 : uint16 (100 ),
419
+ U32 : uint32 (100 ),
420
+ U64 : uint64 (100 ),
421
+ }, cli )
422
+ })
398
423
}
399
424
400
425
func TestJSONLargeNumber (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments