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