File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -101,3 +101,54 @@ impl From<ExtendedId> for Id {
101101 Id :: Extended ( id)
102102 }
103103}
104+
105+ #[ cfg( test) ]
106+ mod tests {
107+ use super :: * ;
108+
109+ #[ test]
110+ fn standard_id_new ( ) {
111+ assert_eq ! (
112+ StandardId :: new( StandardId :: MAX . as_raw( ) ) ,
113+ Some ( StandardId :: MAX )
114+ ) ;
115+ }
116+
117+ #[ test]
118+ fn standard_id_new_out_of_range ( ) {
119+ assert_eq ! ( StandardId :: new( StandardId :: MAX . as_raw( ) + 1 ) , None ) ;
120+ }
121+
122+ #[ test]
123+ fn standard_id_new_unchecked_out_of_range ( ) {
124+ let id = StandardId :: MAX . as_raw ( ) + 1 ;
125+ assert_eq ! ( unsafe { StandardId :: new_unchecked( id) } , StandardId ( id) ) ;
126+ }
127+
128+ #[ test]
129+ fn extended_id_new ( ) {
130+ assert_eq ! (
131+ ExtendedId :: new( ExtendedId :: MAX . as_raw( ) ) ,
132+ Some ( ExtendedId :: MAX )
133+ ) ;
134+ }
135+
136+ #[ test]
137+ fn extended_id_new_out_of_range ( ) {
138+ assert_eq ! ( ExtendedId :: new( ExtendedId :: MAX . as_raw( ) + 1 ) , None ) ;
139+ }
140+
141+ #[ test]
142+ fn extended_id_new_unchecked_out_of_range ( ) {
143+ let id = ExtendedId :: MAX . as_raw ( ) + 1 ;
144+ assert_eq ! ( unsafe { ExtendedId :: new_unchecked( id) } , ExtendedId ( id) ) ;
145+ }
146+
147+ #[ test]
148+ fn get_standard_id_from_extended_id ( ) {
149+ assert_eq ! (
150+ Some ( ExtendedId :: MAX . standard_id( ) ) ,
151+ StandardId :: new( ( ExtendedId :: MAX . 0 >> 18 ) as u16 )
152+ ) ;
153+ }
154+ }
You can’t perform that action at this time.
0 commit comments