1- // Copyright © 2023  Kaleido, Inc. 
1+ // Copyright © 2025  Kaleido, Inc. 
22// 
33// SPDX-License-Identifier: Apache-2.0 
44// 
@@ -19,6 +19,7 @@ package config
1919import  (
2020	"context" 
2121	"fmt" 
22+ 	"math/big" 
2223	"os" 
2324	"path" 
2425	"strings" 
@@ -522,3 +523,75 @@ func TestSetEnvPrefix(t *testing.T) {
522523
523524	assert .Equal (t , "two" , cfg .GetString ("conf" ))
524525}
526+ 
527+ func  TestGetBigInt (t  * testing.T ) {
528+ 	defer  RootConfigReset ()
529+ 
530+ 	// Test valid decimal 
531+ 	key1  :=  AddRootKey ("bigint.key1" )
532+ 	Set (key1 , "12345678901234567890" )
533+ 	result1  :=  GetBigInt (key1 )
534+ 	require .NotNil (t , result1 )
535+ 	expected1  :=  big .NewInt (0 )
536+ 	expected1 .SetString ("12345678901234567890" , 10 )
537+ 	assert .Equal (t , expected1 , result1 )
538+ 
539+ 	// Test valid hex 
540+ 	key2  :=  AddRootKey ("bigint.key2" )
541+ 	Set (key2 , "0xFF" )
542+ 	assert .Equal (t , big .NewInt (255 ), GetBigInt (key2 ))
543+ 
544+ 	// Test valid octal 
545+ 	key3  :=  AddRootKey ("bigint.key3" )
546+ 	Set (key3 , "0777" )
547+ 	assert .Equal (t , big .NewInt (511 ), GetBigInt (key3 ))
548+ 
549+ 	// Test very large value 
550+ 	key4  :=  AddRootKey ("bigint.key4" )
551+ 	Set (key4 , "999999999999999999999999999999" )
552+ 	result4  :=  GetBigInt (key4 )
553+ 	require .NotNil (t , result4 )
554+ 	expected4  :=  big .NewInt (0 )
555+ 	expected4 .SetString ("999999999999999999999999999999" , 10 )
556+ 	assert .Equal (t , expected4 , result4 )
557+ 
558+ 	// Test trimming whitespace 
559+ 	key5  :=  AddRootKey ("bigint.key5" )
560+ 	Set (key5 , "  999  " )
561+ 	assert .Equal (t , big .NewInt (999 ), GetBigInt (key5 ))
562+ 
563+ 	// Test zero value 
564+ 	key6  :=  AddRootKey ("bigint.key6" )
565+ 	Set (key6 , "0" )
566+ 	assert .Equal (t , big .NewInt (0 ), GetBigInt (key6 ))
567+ 
568+ 	// Test negative value 
569+ 	key7  :=  AddRootKey ("bigint.key7" )
570+ 	Set (key7 , "-123456789" )
571+ 	assert .Equal (t , big .NewInt (- 123456789 ), GetBigInt (key7 ))
572+ 
573+ 	// Test empty string returns nil 
574+ 	key8  :=  AddRootKey ("bigint.key8" )
575+ 	Set (key8 , "" )
576+ 	assert .Nil (t , GetBigInt (key8 ))
577+ 
578+ 	// Test whitespace only returns nil 
579+ 	key9  :=  AddRootKey ("bigint.key9" )
580+ 	Set (key9 , "   " )
581+ 	assert .Nil (t , GetBigInt (key9 ))
582+ 
583+ 	// Test invalid string returns nil 
584+ 	key10  :=  AddRootKey ("bigint.key10" )
585+ 	Set (key10 , "not a number" )
586+ 	assert .Nil (t , GetBigInt (key10 ))
587+ 
588+ 	// Test with config section 
589+ 	section  :=  RootSection ("bigintsection" )
590+ 	section .AddKnownKey ("value" )
591+ 	section .Set ("value" , "98765432109876543210" )
592+ 	resultSection  :=  section .GetBigInt ("value" )
593+ 	require .NotNil (t , resultSection )
594+ 	expectedSection  :=  big .NewInt (0 )
595+ 	expectedSection .SetString ("98765432109876543210" , 10 )
596+ 	assert .Equal (t , expectedSection , resultSection )
597+ }
0 commit comments