mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Make Ipv4Addr
and Ipv6Addr
const tests unit tests under library
These tests are about the standard library, not the compiler itself, thus should live in `library`, see #76268.
This commit is contained in:
parent
3edf11cf81
commit
a2e077e405
@ -809,3 +809,112 @@ fn is_v6() {
|
||||
assert!(!ip.is_ipv4());
|
||||
assert!(ip.is_ipv6());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ipv4_const() {
|
||||
// test that the methods of `Ipv4Addr` are usable in a const context
|
||||
|
||||
const IP_ADDRESS: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||
assert_eq!(IP_ADDRESS, Ipv4Addr::LOCALHOST);
|
||||
|
||||
const OCTETS: [u8; 4] = IP_ADDRESS.octets();
|
||||
assert_eq!(OCTETS, [127, 0, 0, 1]);
|
||||
|
||||
const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified();
|
||||
assert!(!IS_UNSPECIFIED);
|
||||
|
||||
const IS_LOOPBACK: bool = IP_ADDRESS.is_loopback();
|
||||
assert!(IS_LOOPBACK);
|
||||
|
||||
const IS_PRIVATE: bool = IP_ADDRESS.is_private();
|
||||
assert!(!IS_PRIVATE);
|
||||
|
||||
const IS_LINK_LOCAL: bool = IP_ADDRESS.is_link_local();
|
||||
assert!(!IS_LINK_LOCAL);
|
||||
|
||||
const IS_GLOBAL: bool = IP_ADDRESS.is_global();
|
||||
assert!(!IS_GLOBAL);
|
||||
|
||||
const IS_SHARED: bool = IP_ADDRESS.is_shared();
|
||||
assert!(!IS_SHARED);
|
||||
|
||||
const IS_IETF_PROTOCOL_ASSIGNMENT: bool = IP_ADDRESS.is_ietf_protocol_assignment();
|
||||
assert!(!IS_IETF_PROTOCOL_ASSIGNMENT);
|
||||
|
||||
const IS_BENCHMARKING: bool = IP_ADDRESS.is_benchmarking();
|
||||
assert!(!IS_BENCHMARKING);
|
||||
|
||||
const IS_RESERVED: bool = IP_ADDRESS.is_reserved();
|
||||
assert!(!IS_RESERVED);
|
||||
|
||||
const IS_MULTICAST: bool = IP_ADDRESS.is_multicast();
|
||||
assert!(!IS_MULTICAST);
|
||||
|
||||
const IS_BROADCAST: bool = IP_ADDRESS.is_broadcast();
|
||||
assert!(!IS_BROADCAST);
|
||||
|
||||
const IS_DOCUMENTATION: bool = IP_ADDRESS.is_documentation();
|
||||
assert!(!IS_DOCUMENTATION);
|
||||
|
||||
const IP_V6_COMPATIBLE: Ipv6Addr = IP_ADDRESS.to_ipv6_compatible();
|
||||
assert_eq!(
|
||||
IP_V6_COMPATIBLE,
|
||||
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1])
|
||||
);
|
||||
|
||||
const IP_V6_MAPPED: Ipv6Addr = IP_ADDRESS.to_ipv6_mapped();
|
||||
assert_eq!(
|
||||
IP_V6_MAPPED,
|
||||
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ipv6_const() {
|
||||
// test that the methods of `Ipv6Addr` are usable in a const context
|
||||
|
||||
const IP_ADDRESS: Ipv6Addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
|
||||
assert_eq!(IP_ADDRESS, Ipv6Addr::LOCALHOST);
|
||||
|
||||
const SEGMENTS: [u16; 8] = IP_ADDRESS.segments();
|
||||
assert_eq!(SEGMENTS, [0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
|
||||
const OCTETS: [u8; 16] = IP_ADDRESS.octets();
|
||||
assert_eq!(OCTETS, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
|
||||
const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified();
|
||||
assert!(!IS_UNSPECIFIED);
|
||||
|
||||
const IS_LOOPBACK: bool = IP_ADDRESS.is_loopback();
|
||||
assert!(IS_LOOPBACK);
|
||||
|
||||
const IS_GLOBAL: bool = IP_ADDRESS.is_global();
|
||||
assert!(!IS_GLOBAL);
|
||||
|
||||
const IS_UNIQUE_LOCAL: bool = IP_ADDRESS.is_unique_local();
|
||||
assert!(!IS_UNIQUE_LOCAL);
|
||||
|
||||
const IS_UNICAST_LINK_LOCAL_STRICT: bool = IP_ADDRESS.is_unicast_link_local_strict();
|
||||
assert!(!IS_UNICAST_LINK_LOCAL_STRICT);
|
||||
|
||||
const IS_UNICAST_LINK_LOCAL: bool = IP_ADDRESS.is_unicast_link_local();
|
||||
assert!(!IS_UNICAST_LINK_LOCAL);
|
||||
|
||||
const IS_UNICAST_SITE_LOCAL: bool = IP_ADDRESS.is_unicast_site_local();
|
||||
assert!(!IS_UNICAST_SITE_LOCAL);
|
||||
|
||||
const IS_DOCUMENTATION: bool = IP_ADDRESS.is_documentation();
|
||||
assert!(!IS_DOCUMENTATION);
|
||||
|
||||
const IS_UNICAST_GLOBAL: bool = IP_ADDRESS.is_unicast_global();
|
||||
assert!(!IS_UNICAST_GLOBAL);
|
||||
|
||||
const MULTICAST_SCOPE: Option<Ipv6MulticastScope> = IP_ADDRESS.multicast_scope();
|
||||
assert_eq!(MULTICAST_SCOPE, None);
|
||||
|
||||
const IS_MULTICAST: bool = IP_ADDRESS.is_multicast();
|
||||
assert!(!IS_MULTICAST);
|
||||
|
||||
const IP_V4: Option<Ipv4Addr> = IP_ADDRESS.to_ipv4();
|
||||
assert_eq!(IP_V4.unwrap(), Ipv4Addr::new(0, 0, 0, 1));
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(ip)]
|
||||
#![feature(const_ipv4)]
|
||||
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
fn main() {
|
||||
const IP_ADDRESS: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||
assert_eq!(IP_ADDRESS, Ipv4Addr::LOCALHOST);
|
||||
|
||||
const OCTETS: [u8; 4] = IP_ADDRESS.octets();
|
||||
assert_eq!(OCTETS, [127, 0, 0, 1]);
|
||||
|
||||
const IS_UNSPECIFIED : bool = IP_ADDRESS.is_unspecified();
|
||||
assert!(!IS_UNSPECIFIED);
|
||||
|
||||
const IS_LOOPBACK : bool = IP_ADDRESS.is_loopback();
|
||||
assert!(IS_LOOPBACK);
|
||||
|
||||
const IS_PRIVATE : bool = IP_ADDRESS.is_private();
|
||||
assert!(!IS_PRIVATE);
|
||||
|
||||
const IS_LINK_LOCAL : bool = IP_ADDRESS.is_link_local();
|
||||
assert!(!IS_LINK_LOCAL);
|
||||
|
||||
const IS_GLOBAL : bool = IP_ADDRESS.is_global();
|
||||
assert!(!IS_GLOBAL);
|
||||
|
||||
const IS_SHARED : bool = IP_ADDRESS.is_shared();
|
||||
assert!(!IS_SHARED);
|
||||
|
||||
const IS_IETF_PROTOCOL_ASSIGNMENT : bool = IP_ADDRESS.is_ietf_protocol_assignment();
|
||||
assert!(!IS_IETF_PROTOCOL_ASSIGNMENT);
|
||||
|
||||
const IS_BENCHMARKING : bool = IP_ADDRESS.is_benchmarking();
|
||||
assert!(!IS_BENCHMARKING);
|
||||
|
||||
const IS_RESERVED : bool = IP_ADDRESS.is_reserved();
|
||||
assert!(!IS_RESERVED);
|
||||
|
||||
const IS_MULTICAST : bool = IP_ADDRESS.is_multicast();
|
||||
assert!(!IS_MULTICAST);
|
||||
|
||||
const IS_BROADCAST : bool = IP_ADDRESS.is_broadcast();
|
||||
assert!(!IS_BROADCAST);
|
||||
|
||||
const IS_DOCUMENTATION : bool = IP_ADDRESS.is_documentation();
|
||||
assert!(!IS_DOCUMENTATION);
|
||||
|
||||
const IP_V6_COMPATIBLE : Ipv6Addr = IP_ADDRESS.to_ipv6_compatible();
|
||||
assert_eq!(IP_V6_COMPATIBLE,
|
||||
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 0, 1]));
|
||||
|
||||
const IP_V6_MAPPED : Ipv6Addr = IP_ADDRESS.to_ipv6_mapped();
|
||||
assert_eq!(IP_V6_MAPPED,
|
||||
Ipv6Addr::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1]));
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(ip)]
|
||||
#![feature(const_ipv6)]
|
||||
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
|
||||
|
||||
fn main() {
|
||||
const IP_ADDRESS : Ipv6Addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
|
||||
assert_eq!(IP_ADDRESS, Ipv6Addr::LOCALHOST);
|
||||
|
||||
const SEGMENTS : [u16; 8] = IP_ADDRESS.segments();
|
||||
assert_eq!(SEGMENTS, [0 ,0 ,0 ,0 ,0 ,0 ,0, 1]);
|
||||
|
||||
const OCTETS : [u8; 16] = IP_ADDRESS.octets();
|
||||
assert_eq!(OCTETS, [0 ,0 ,0 ,0 ,0 ,0 ,0, 0 ,0 ,0 ,0 ,0 ,0 ,0, 0, 1]);
|
||||
|
||||
const IS_UNSPECIFIED : bool = IP_ADDRESS.is_unspecified();
|
||||
assert!(!IS_UNSPECIFIED);
|
||||
|
||||
const IS_LOOPBACK : bool = IP_ADDRESS.is_loopback();
|
||||
assert!(IS_LOOPBACK);
|
||||
|
||||
const IS_GLOBAL : bool = IP_ADDRESS.is_global();
|
||||
assert!(!IS_GLOBAL);
|
||||
|
||||
const IS_UNIQUE_LOCAL : bool = IP_ADDRESS.is_unique_local();
|
||||
assert!(!IS_UNIQUE_LOCAL);
|
||||
|
||||
const IS_UNICAST_LINK_LOCAL_STRICT : bool = IP_ADDRESS.is_unicast_link_local_strict();
|
||||
assert!(!IS_UNICAST_LINK_LOCAL_STRICT);
|
||||
|
||||
const IS_UNICAST_LINK_LOCAL : bool = IP_ADDRESS.is_unicast_link_local();
|
||||
assert!(!IS_UNICAST_LINK_LOCAL);
|
||||
|
||||
const IS_UNICAST_SITE_LOCAL : bool = IP_ADDRESS.is_unicast_site_local();
|
||||
assert!(!IS_UNICAST_SITE_LOCAL);
|
||||
|
||||
const IS_DOCUMENTATION : bool = IP_ADDRESS.is_documentation();
|
||||
assert!(!IS_DOCUMENTATION);
|
||||
|
||||
const IS_UNICAST_GLOBAL : bool = IP_ADDRESS.is_unicast_global();
|
||||
assert!(!IS_UNICAST_GLOBAL);
|
||||
|
||||
const MULTICAST_SCOPE : Option<Ipv6MulticastScope> = IP_ADDRESS.multicast_scope();
|
||||
assert_eq!(MULTICAST_SCOPE, None);
|
||||
|
||||
const IS_MULTICAST : bool = IP_ADDRESS.is_multicast();
|
||||
assert!(!IS_MULTICAST);
|
||||
|
||||
const IP_V4 : Option<Ipv4Addr> = IP_ADDRESS.to_ipv4();
|
||||
assert_eq!(IP_V4.unwrap(), Ipv4Addr::new(0, 0, 0, 1));
|
||||
}
|
Loading…
Reference in New Issue
Block a user