@@ -68,3 +68,81 @@ fn invalid_signedness() {
6868
6969 let _: u32 = c. get ( "settings.port" ) . unwrap ( ) ;
7070}
71+
72+ #[ cfg( feature = "preserve_order" ) ]
73+ #[ test]
74+ fn serde_i128_min ( ) {
75+ use serde:: { Deserialize , Serialize } ;
76+
77+ #[ derive( Debug , Deserialize , Eq , PartialEq , Serialize ) ]
78+ struct Container < T > {
79+ inner : T ,
80+ }
81+
82+ #[ derive( Clone , Copy , Debug , Deserialize , Eq , PartialEq , Serialize ) ]
83+ struct I128 {
84+ val : i128 ,
85+ }
86+
87+ impl From < I128 > for config:: ValueKind {
88+ fn from ( i : I128 ) -> Self {
89+ let mut properties = indexmap:: IndexMap :: new ( ) ;
90+ properties. insert ( "val" . to_owned ( ) , config:: Value :: from ( i. val ) ) ;
91+
92+ Self :: Table ( properties)
93+ }
94+ }
95+
96+ let num = I128 { val : i128:: MIN } ;
97+ let container = Container { inner : num } ;
98+ let built = Config :: builder ( )
99+ . set_default ( "inner" , num)
100+ . unwrap ( )
101+ . build ( )
102+ . unwrap ( ) ;
103+
104+ let deserialized = built. clone ( ) . try_deserialize :: < Container < I128 > > ( ) . unwrap ( ) ;
105+ assert_eq ! ( deserialized, container) ;
106+
107+ let serialized = Config :: try_from ( & container) . unwrap ( ) ;
108+ assert_eq ! ( serialized. cache, built. cache) ;
109+ }
110+
111+ #[ cfg( feature = "preserve_order" ) ]
112+ #[ test]
113+ fn serde_u128_max ( ) {
114+ use serde:: { Deserialize , Serialize } ;
115+
116+ #[ derive( Debug , Deserialize , Eq , PartialEq , Serialize ) ]
117+ struct Container < T > {
118+ inner : T ,
119+ }
120+
121+ #[ derive( Clone , Copy , Debug , Deserialize , Eq , PartialEq , Serialize ) ]
122+ struct U128 {
123+ val : u128 ,
124+ }
125+
126+ impl From < U128 > for config:: ValueKind {
127+ fn from ( i : U128 ) -> Self {
128+ let mut properties = indexmap:: IndexMap :: new ( ) ;
129+ properties. insert ( "val" . to_owned ( ) , config:: Value :: from ( i. val ) ) ;
130+
131+ Self :: Table ( properties)
132+ }
133+ }
134+
135+ let num = U128 { val : u128:: MAX } ;
136+ let container = Container { inner : num } ;
137+ let built = Config :: builder ( )
138+ . set_default ( "inner" , num)
139+ . unwrap ( )
140+ . build ( )
141+ . unwrap ( ) ;
142+
143+ let deserialized = built. clone ( ) . try_deserialize :: < Container < U128 > > ( ) . unwrap ( ) ;
144+ assert_eq ! ( deserialized, container) ;
145+
146+ let serialized = Config :: try_from ( & container) . unwrap ( ) ;
147+ assert_eq ! ( serialized. cache, built. cache) ;
148+ }
0 commit comments