@@ -102,19 +102,28 @@ fn longest_match() {
102102 assert_eq ! ( result, Some ( ( Ipv4Addr :: new( 100 , 64 , 0 , 0 ) , 10 , & 100004 ) ) ) ;
103103
104104 let result = tbm. longest_match_mut ( Ipv4Addr :: new ( 100 , 100 , 100 , 100 ) ) ;
105- assert_eq ! ( result, Some ( ( Ipv4Addr :: new( 100 , 64 , 0 , 0 ) , 10 , & mut 100004 ) ) ) ;
105+ assert_eq ! (
106+ result,
107+ Some ( ( Ipv4Addr :: new( 100 , 64 , 0 , 0 ) , 10 , & mut 100004 ) )
108+ ) ;
106109
107110 let result = tbm. longest_match ( Ipv4Addr :: new ( 100 , 64 , 0 , 100 ) ) ;
108111 assert_eq ! ( result, Some ( ( Ipv4Addr :: new( 100 , 64 , 0 , 0 ) , 24 , & 10064024 ) ) ) ;
109112
110113 let result = tbm. longest_match_mut ( Ipv4Addr :: new ( 100 , 64 , 0 , 100 ) ) ;
111- assert_eq ! ( result, Some ( ( Ipv4Addr :: new( 100 , 64 , 0 , 0 ) , 24 , & mut 10064024 ) ) ) ;
114+ assert_eq ! (
115+ result,
116+ Some ( ( Ipv4Addr :: new( 100 , 64 , 0 , 0 ) , 24 , & mut 10064024 ) )
117+ ) ;
112118
113119 let result = tbm. longest_match ( Ipv4Addr :: new ( 100 , 64 , 1 , 100 ) ) ;
114120 assert_eq ! ( result, Some ( ( Ipv4Addr :: new( 100 , 64 , 1 , 0 ) , 24 , & 10064124 ) ) ) ;
115121
116122 let result = tbm. longest_match_mut ( Ipv4Addr :: new ( 100 , 64 , 1 , 100 ) ) ;
117- assert_eq ! ( result, Some ( ( Ipv4Addr :: new( 100 , 64 , 1 , 0 ) , 24 , & mut 10064124 ) ) ) ;
123+ assert_eq ! (
124+ result,
125+ Some ( ( Ipv4Addr :: new( 100 , 64 , 1 , 0 ) , 24 , & mut 10064124 ) )
126+ ) ;
118127
119128 let result = tbm. longest_match ( Ipv4Addr :: new ( 200 , 200 , 200 , 200 ) ) ;
120129 assert_eq ! ( result, None ) ;
@@ -123,14 +132,6 @@ fn longest_match() {
123132 assert_eq ! ( result, None ) ;
124133}
125134
126- #[ test]
127- fn matches ( ) {
128- let mut tbm = IpLookupTable :: new ( ) ;
129- tbm. insert ( Ipv4Addr :: new ( 10 , 0 , 0 , 0 ) , 8 , 1 ) ;
130- tbm. insert ( Ipv4Addr :: new ( 10 , 1 , 0 , 0 ) , 16 , 2 ) ;
131- assert_eq ! ( 2 , tbm. matches( Ipv4Addr :: new( 10 , 1 , 0 , 30 ) ) . count( ) ) ;
132- }
133-
134135#[ test]
135136fn iter ( ) {
136137 let mut tbl = IpLookupTable :: new ( ) ;
@@ -191,10 +192,17 @@ fn into_iter() {
191192
192193#[ test]
193194fn send ( ) {
194- fn check_if_send < T : Send > ( ) { }
195+ fn check_if_send < T : Send > ( ) { }
195196 check_if_send :: < IpLookupTable < Ipv4Addr , ( ) > > ( ) ;
196197}
197198
199+ #[ test]
200+ fn matches ( ) {
201+ let mut tbm = IpLookupTable :: new ( ) ;
202+ tbm. insert ( Ipv4Addr :: new ( 10 , 0 , 0 , 0 ) , 8 , 1 ) ;
203+ tbm. insert ( Ipv4Addr :: new ( 10 , 1 , 0 , 0 ) , 16 , 2 ) ;
204+ assert_eq ! ( 2 , tbm. matches( Ipv4Addr :: new( 10 , 1 , 0 , 30 ) ) . count( ) ) ;
205+ }
198206
199207#[ test]
200208fn matches_all_zeros ( ) {
@@ -242,7 +250,10 @@ fn matches_ipv6() {
242250 table. insert ( more_specific, 48 , "bar" ) ;
243251 assert_eq ! ( table. matches( less_specific) . count( ) , 1 ) ;
244252 assert_eq ! ( table. matches( more_specific) . count( ) , 2 ) ;
245- assert_eq ! ( table. matches( Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) . count( ) , 0 ) ;
253+ assert_eq ! (
254+ table. matches( Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) . count( ) ,
255+ 0
256+ ) ;
246257}
247258
248259// https://github.com/hroi/treebitmap/issues/7
@@ -270,19 +281,21 @@ fn issue_13() {
270281 let mut table = IpLookupTable :: new ( ) ;
271282
272283 println ! ( "insert 28" ) ;
273- table. insert ( Ipv4Addr :: new ( 49 , 255 , 11 , 16 ) , 28 , ( ) ) ;
284+ table. insert ( Ipv4Addr :: new ( 49 , 255 , 11 , 16 ) , 28 , 28 ) ;
274285 assert_eq ! (
275286 table. exact_match( Ipv4Addr :: new( 49 , 255 , 11 , 16 ) , 28 ) ,
276- Some ( & ( ) )
287+ Some ( & 28 )
277288 ) ;
278289 println ! ( "insert 32" ) ;
279- table. insert ( ADDR , 32 , ( ) ) ;
290+ table. insert ( ADDR , 32 , 32 ) ;
280291
281292 println ! ( "match 32" ) ;
282- assert_eq ! ( table. exact_match( ADDR , 32 ) , Some ( & ( ) ) ) ;
293+ assert_eq ! ( table. exact_match( ADDR , 32 ) , Some ( & 32 ) ) ;
283294 assert ! ( table. longest_match( ADDR ) . is_some( ) ) ;
284295 assert ! ( table. longest_match_mut( ADDR ) . is_some( ) ) ;
285296
297+ assert_eq ! ( table. matches( ADDR ) . count( ) , 2 ) ;
298+
286299 let v = table. remove ( ADDR , 32 ) ;
287300 println ! ( "removed: {:?}" , v) ;
288301}
0 commit comments