Skip to content

Commit

Permalink
New tests added for new_unchecked functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelilys committed Dec 21, 2023
1 parent 3249a66 commit bd9232d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ mod test {
assert!(net.is_err());
}

#[test]
fn create_unchecked_v4() {
let cidr = unsafe { Ipv4Network::new_unchecked(Ipv4Addr::new(77, 88, 21, 11), 24) };
assert_eq!(cidr.prefix(), 24);
let cidr = unsafe { Ipv4Network::new_unchecked(Ipv4Addr::new(0, 0, 0, 0), 33) };
assert_eq!(cidr.prefix(), 33);
}

#[test]
fn parse_v4_24bit() {
let cidr: Ipv4Network = "127.1.0.0/24".parse().unwrap();
Expand Down
9 changes: 9 additions & 0 deletions src/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ mod test {
assert!(cidr.is_err());
}

#[test]
fn create_unchecked_v6() {
let cidr = unsafe { Ipv6Network::new_unchecked(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 24) };
assert_eq!(cidr.prefix(), 24);
let cidr =
unsafe { Ipv6Network::new_unchecked(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 129) };
assert_eq!(cidr.prefix(), 129);
}

#[test]
fn parse_v6() {
let cidr: Ipv6Network = "::1/0".parse().unwrap();
Expand Down

0 comments on commit bd9232d

Please sign in to comment.