mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-16 08:48:51 +00:00
Add Ipv6 test case
This commit is contained in:
@ -12,13 +12,13 @@ extern crate ipnetwork;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use ipnetwork::Ipv4Network;
|
use ipnetwork::{Ipv4Network, Ipv6Network};
|
||||||
use std::net::Ipv4Addr;
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
|
|
||||||
#[cfg(feature = "with-serde")]
|
#[cfg(feature = "with-serde")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ipv4_json() {
|
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)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
@ -32,4 +32,22 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(::serde_json::to_string(&mystruct).unwrap(), json_string);
|
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