@@ -78,7 +78,7 @@ fn matches6() {
7878 assert_eq ! (
7979 2 ,
8080 tbm. matches( Ipv6Addr :: from_str( "2a00:0099::0" ) . unwrap( ) )
81- . len ( )
81+ . count ( )
8282 ) ;
8383}
8484
@@ -111,7 +111,7 @@ fn matches() {
111111 let mut tbm = IpLookupTable :: new ( ) ;
112112 tbm. insert ( Ipv4Addr :: new ( 10 , 0 , 0 , 0 ) , 8 , 1 ) ;
113113 tbm. insert ( Ipv4Addr :: new ( 10 , 1 , 0 , 0 ) , 16 , 2 ) ;
114- assert_eq ! ( 2 , tbm. matches( Ipv4Addr :: new( 10 , 1 , 0 , 30 ) ) . len ( ) ) ;
114+ assert_eq ! ( 2 , tbm. matches( Ipv4Addr :: new( 10 , 1 , 0 , 30 ) ) . count ( ) ) ;
115115}
116116
117117#[ test]
@@ -208,3 +208,52 @@ fn issue_7() {
208208
209209 println ! ( "len: {}" , table. len( ) ) ;
210210}
211+
212+ #[ test]
213+ fn matches_all_zeros ( ) {
214+ let mut table = IpLookupTable :: new ( ) ;
215+ for i in 0 ..=32 {
216+ table. insert ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) , i, i) ;
217+ }
218+
219+ for ( ip, matched, value) in table. matches ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) {
220+ assert_eq ! ( ip, Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) ;
221+ assert_eq ! ( matched, * value) ;
222+ }
223+
224+ assert_eq ! ( table. matches( Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) . count( ) , 33 ) ;
225+ assert_eq ! ( table. matches( Ipv4Addr :: new( 1 , 0 , 0 , 0 ) ) . count( ) , 8 ) ;
226+ assert_eq ! ( table. matches( Ipv4Addr :: new( 0 , 0 , 255 , 255 ) ) . count( ) , 17 ) ;
227+ assert_eq ! ( table. matches( Ipv4Addr :: new( 255 , 255 , 255 , 255 ) ) . count( ) , 1 ) ;
228+ assert_eq ! ( table. matches( Ipv4Addr :: new( 64 , 0 , 0 , 0 ) ) . count( ) , 2 ) ;
229+ }
230+
231+ #[ test]
232+ fn matches_10_range ( ) {
233+ let mut table = IpLookupTable :: new ( ) ;
234+ table. insert ( Ipv4Addr :: new ( 10 , 0 , 0 , 0 ) , 8 , 0 ) ;
235+ table. insert ( Ipv4Addr :: new ( 10 , 6 , 0 , 0 ) , 16 , 0 ) ;
236+ table. insert ( Ipv4Addr :: new ( 10 , 6 , 252 , 0 ) , 24 , 0 ) ;
237+
238+ assert_eq ! ( table. matches( Ipv4Addr :: new( 10 , 6 , 252 , 3 ) ) . count( ) , 3 ) ;
239+ assert_eq ! ( table. matches( Ipv4Addr :: new( 10 , 6 , 255 , 3 ) ) . count( ) , 2 ) ;
240+ assert_eq ! ( table. matches( Ipv4Addr :: new( 11 , 6 , 255 , 3 ) ) . count( ) , 0 ) ;
241+ }
242+
243+ #[ test]
244+ fn matches_empty ( ) {
245+ let table: IpLookupTable < Ipv4Addr , ( ) > = IpLookupTable :: new ( ) ;
246+ assert_eq ! ( table. matches( Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) . count( ) , 0 ) ;
247+ }
248+
249+ #[ test]
250+ fn matches_ipv6 ( ) {
251+ let mut table = IpLookupTable :: new ( ) ;
252+ let less_specific = Ipv6Addr :: new ( 0x2001 , 0xdb8 , 0 , 0 , 0 , 0 , 0 , 0 ) ;
253+ let more_specific = Ipv6Addr :: new ( 0x2001 , 0xdb8 , 0xdead , 0 , 0 , 0 , 0 , 0 ) ;
254+ table. insert ( less_specific, 32 , "foo" ) ;
255+ table. insert ( more_specific, 48 , "bar" ) ;
256+ assert_eq ! ( table. matches( less_specific) . count( ) , 1 ) ;
257+ assert_eq ! ( table. matches( more_specific) . count( ) , 2 ) ;
258+ assert_eq ! ( table. matches( Ipv6Addr :: new( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) . count( ) , 0 ) ;
259+ }
0 commit comments