mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-15 00:26:33 +00:00
vector of ip networks
This commit is contained in:
@ -12,7 +12,7 @@ extern crate ipnetwork;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use ipnetwork::{Ipv4Network, Ipv6Network};
|
||||
use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network};
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
#[cfg(feature = "with-serde")]
|
||||
@ -50,4 +50,24 @@ mod tests {
|
||||
|
||||
assert_eq!(::serde_json::to_string(&mystruct).unwrap(), json_string);
|
||||
}
|
||||
|
||||
#[cfg(feature = "with-serde")]
|
||||
#[test]
|
||||
fn test_ipnetwork_json() {
|
||||
let json_string = r#"{"ipnetwork":[{"V4":{"addr":"127.1.0.0","prefix":24}},{"V6":{"addr":"::1","prefix":0}}]}"#;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct MyStruct {
|
||||
ipnetwork: Vec<IpNetwork>,
|
||||
}
|
||||
|
||||
let mystruct: MyStruct = ::serde_json::from_str(json_string).unwrap();
|
||||
|
||||
assert_eq!(mystruct.ipnetwork[0].ip(), Ipv4Addr::new(127, 1, 0, 0));
|
||||
assert_eq!(mystruct.ipnetwork[0].prefix(), 24);
|
||||
assert_eq!(mystruct.ipnetwork[1].ip(), Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
|
||||
assert_eq!(mystruct.ipnetwork[1].prefix(), 0);
|
||||
|
||||
assert_eq!(::serde_json::to_string(&mystruct).unwrap(), json_string);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user