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
387387 default :
388388 return fmt .Errorf ("expected an int but got %q (%T)" , t , t .Value )
389389 }
390- n , err := strconv .ParseInt (sv , 10 , bits )
390+ n , err := strconv .ParseInt (sv , 0 , bits )
391391 if err != nil {
392392 return fmt .Errorf ("expected a valid %d bit int but got %q" , bits , sv )
393393 }
@@ -416,7 +416,7 @@ func uintDecoder(bits int) MapperFunc { //nolint: dupl
416416 default :
417417 return fmt .Errorf ("expected an int but got %q (%T)" , t , t .Value )
418418 }
419- n , err := strconv .ParseUint (sv , 10 , bits )
419+ n , err := strconv .ParseUint (sv , 0 , bits )
420420 if err != nil {
421421 return fmt .Errorf ("expected a valid %d bit uint but got %q" , bits , sv )
422422 }
Original file line number Diff line number Diff line change @@ -395,6 +395,31 @@ func TestNumbers(t *testing.T) {
395395 I64 : math .MinInt64 ,
396396 }, cli )
397397 })
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+ })
398423}
399424
400425func TestJSONLargeNumber (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments