Skip to content

Commit

Permalink
Add DnsName trait tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Apr 22, 2021
1 parent b31b588 commit 650341c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/name_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,42 @@ fn test_dns_name_ref_traits() {
assert_eq!(format!("{:?}", &a), "DnsNameRef(\"example.com\")");
}
}

#[cfg(feature = "alloc")]
#[test]
fn test_dns_name_traits() {
use webpki::DnsName;

fn compile_time_assert_hash<T: core::hash::Hash>() {}

compile_time_assert_hash::<DnsName>();
compile_time_assert_send::<DnsName>();
compile_time_assert_sync::<DnsName>();

let a_ref = DnsNameRef::try_from_ascii(b"example.com").unwrap();

// `From<DnsNameRef>`
let a: DnsName = DnsName::from(a_ref);

// `Clone`, `Debug`, `PartialEq`.
assert_eq!(&a, &a.clone());

// `Debug`.
assert_eq!(format!("{:?}", &a), "DnsName(\"example.com\")");

// PartialEq is case-insensitive
assert_eq!(
a,
DnsName::from(DnsNameRef::try_from_ascii(b"Example.Com").unwrap())
);

// PartialEq isn't completely wrong.
assert_ne!(
a,
DnsName::from(DnsNameRef::try_from_ascii(b"fxample.com").unwrap())
);
assert_ne!(
a,
DnsName::from(DnsNameRef::try_from_ascii(b"example.co").unwrap())
);
}

0 comments on commit 650341c

Please sign in to comment.