about summary refs log tree commit diff
path: root/library/core/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-17 11:18:57 +0000
committerbors <bors@rust-lang.org>2024-10-17 11:18:57 +0000
commite09bf4c07af8a424f9022bfe8d42ec714a51f0be (patch)
tree0aa83217a4da4a550ed80601e35381bb06db1c33 /library/core/tests
parentecf6fc5336a7fe24607b8c394f34a4fcd20079c8 (diff)
parent6e4f8fea36cd04f623c46d99adc3c370b1879883 (diff)
downloadrust-e09bf4c07af8a424f9022bfe8d42ec714a51f0be.tar.gz
rust-e09bf4c07af8a424f9022bfe8d42ec714a51f0be.zip
Auto merge of #18317 - lnicola:sync-from-rust, r=Veykril
minor: sync from downstream
Diffstat (limited to 'library/core/tests')
-rw-r--r--library/core/tests/ascii.rs22
-rw-r--r--library/core/tests/atomic.rs2
-rw-r--r--library/core/tests/hash/mod.rs2
-rw-r--r--library/core/tests/lib.rs12
-rw-r--r--library/core/tests/net/ip_addr.rs24
-rw-r--r--library/core/tests/slice.rs51
6 files changed, 45 insertions, 68 deletions
diff --git a/library/core/tests/ascii.rs b/library/core/tests/ascii.rs
index 3d3f8ac10c6..ce09ee507f1 100644
--- a/library/core/tests/ascii.rs
+++ b/library/core/tests/ascii.rs
@@ -481,9 +481,25 @@ fn ascii_ctype_const() {
 }
 
 #[test]
-fn test_ascii_display() {
-    assert_eq!(b"foo'bar".escape_ascii().to_string(), r#"foo\'bar"#);
-    assert_eq!(b"\0\xff".escape_ascii().to_string(), r#"\x00\xff"#);
+fn test_escape_ascii() {
+    let mut buf = [0u8; 0x1F + 7]; // 0..=0x1F plus two quotes, slash, \x7F, \x80, \xFF
+    for idx in 0..=0x1F {
+        buf[idx] = idx as u8;
+    }
+    buf[0x20] = b'\'';
+    buf[0x21] = b'"';
+    buf[0x22] = b'\\';
+    buf[0x23] = 0x7F;
+    buf[0x24] = 0x80;
+    buf[0x25] = 0xff;
+    assert_eq!(
+        buf.escape_ascii().to_string(),
+        r#"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\'\"\\\x7f\x80\xff"#
+    );
+}
+
+#[test]
+fn test_escape_ascii_iter() {
     let mut it = b"\0fastpath\xffremainder\xff".escape_ascii();
     let _ = it.advance_by(4);
     let _ = it.advance_back_by(4);
diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs
index 2bdaeb3845a..0ffba538b20 100644
--- a/library/core/tests/atomic.rs
+++ b/library/core/tests/atomic.rs
@@ -229,7 +229,7 @@ fn static_init() {
 
 #[test]
 // FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
-#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
+#[allow(static_mut_refs)]
 fn atomic_access_bool() {
     static mut ATOMIC: AtomicBool = AtomicBool::new(false);
 
diff --git a/library/core/tests/hash/mod.rs b/library/core/tests/hash/mod.rs
index 03826fc4c92..bf91e9e5df0 100644
--- a/library/core/tests/hash/mod.rs
+++ b/library/core/tests/hash/mod.rs
@@ -164,7 +164,7 @@ fn test_indirect_hasher() {
 }
 
 #[test]
-fn test_build_hasher_object_safe() {
+fn test_build_hasher_dyn_compatible() {
     use std::hash::{DefaultHasher, RandomState};
 
     let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 196e91ee3e9..bfc0b638b7e 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -1,5 +1,4 @@
 // tidy-alphabetical-start
-#![cfg_attr(bootstrap, feature(const_mut_refs))]
 #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
 #![cfg_attr(test, feature(cfg_match))]
 #![feature(alloc_layout_extra)]
@@ -16,33 +15,23 @@
 #![feature(clone_to_uninit)]
 #![feature(const_align_of_val_raw)]
 #![feature(const_align_offset)]
-#![feature(const_array_from_ref)]
 #![feature(const_black_box)]
 #![feature(const_hash)]
 #![feature(const_heap)]
-#![feature(const_ip)]
-#![feature(const_ipv4)]
-#![feature(const_ipv6)]
 #![feature(const_likely)]
 #![feature(const_nonnull_new)]
-#![feature(const_option)]
 #![feature(const_option_ext)]
 #![feature(const_pin)]
 #![feature(const_pointer_is_aligned)]
-#![feature(const_ptr_write)]
-#![feature(const_result)]
-#![feature(const_slice_from_ref)]
 #![feature(const_three_way_compare)]
 #![feature(const_trait_impl)]
 #![feature(core_intrinsics)]
 #![feature(core_io_borrowed_buf)]
 #![feature(core_private_bignum)]
 #![feature(core_private_diy_float)]
-#![feature(debug_more_non_exhaustive)]
 #![feature(dec2flt)]
 #![feature(duration_constants)]
 #![feature(duration_constructors)]
-#![feature(duration_consts_float)]
 #![feature(error_generic_member_access)]
 #![feature(exact_size_is_empty)]
 #![feature(extern_types)]
@@ -57,6 +46,7 @@
 #![feature(hashmap_internals)]
 #![feature(int_roundings)]
 #![feature(ip)]
+#![feature(ip_from)]
 #![feature(is_ascii_octdigit)]
 #![feature(isqrt)]
 #![feature(iter_advance_by)]
diff --git a/library/core/tests/net/ip_addr.rs b/library/core/tests/net/ip_addr.rs
index a10b51c550d..707f9a160e1 100644
--- a/library/core/tests/net/ip_addr.rs
+++ b/library/core/tests/net/ip_addr.rs
@@ -494,6 +494,7 @@ fn ipv6_properties() {
             let octets = &[$($octet),*];
             assert_eq!(&ip!($s).octets(), octets);
             assert_eq!(Ipv6Addr::from(*octets), ip!($s));
+            assert_eq!(Ipv6Addr::from_octets(*octets), ip!($s));
 
             let unspecified: u32 = 1 << 0;
             let loopback: u32 = 1 << 1;
@@ -846,15 +847,19 @@ fn ipv6_from_constructors() {
 
 #[test]
 fn ipv4_from_octets() {
-    assert_eq!(Ipv4Addr::from([127, 0, 0, 1]), Ipv4Addr::new(127, 0, 0, 1))
+    assert_eq!(Ipv4Addr::from([127, 0, 0, 1]), Ipv4Addr::new(127, 0, 0, 1));
+    assert_eq!(Ipv4Addr::from_octets([127, 0, 0, 1]), Ipv4Addr::new(127, 0, 0, 1));
 }
 
 #[test]
 fn ipv6_from_segments() {
     let from_u16s =
         Ipv6Addr::from([0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff]);
+    let from_u16s_explicit =
+        Ipv6Addr::from_segments([0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff]);
     let new = Ipv6Addr::new(0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff);
     assert_eq!(new, from_u16s);
+    assert_eq!(new, from_u16s_explicit);
 }
 
 #[test]
@@ -865,7 +870,15 @@ fn ipv6_from_octets() {
         0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
         0xff,
     ]);
+    let from_u16s_explicit =
+        Ipv6Addr::from_segments([0x0011, 0x2233, 0x4455, 0x6677, 0x8899, 0xaabb, 0xccdd, 0xeeff]);
+    let from_u8s_explicit = Ipv6Addr::from_octets([
+        0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
+        0xff,
+    ]);
     assert_eq!(from_u16s, from_u8s);
+    assert_eq!(from_u16s, from_u16s_explicit);
+    assert_eq!(from_u16s_explicit, from_u8s_explicit);
 }
 
 #[test]
@@ -915,6 +928,9 @@ fn ipv4_const() {
     const OCTETS: [u8; 4] = IP_ADDRESS.octets();
     assert_eq!(OCTETS, [127, 0, 0, 1]);
 
+    const FROM_OCTETS: Ipv4Addr = Ipv4Addr::from_octets(OCTETS);
+    assert_eq!(IP_ADDRESS, FROM_OCTETS);
+
     const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified();
     assert!(!IS_UNSPECIFIED);
 
@@ -971,9 +987,15 @@ fn ipv6_const() {
     const SEGMENTS: [u16; 8] = IP_ADDRESS.segments();
     assert_eq!(SEGMENTS, [0, 0, 0, 0, 0, 0, 0, 1]);
 
+    const FROM_SEGMENTS: Ipv6Addr = Ipv6Addr::from_segments(SEGMENTS);
+    assert_eq!(IP_ADDRESS, FROM_SEGMENTS);
+
     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 FROM_OCTETS: Ipv6Addr = Ipv6Addr::from_octets(OCTETS);
+    assert_eq!(IP_ADDRESS, FROM_OCTETS);
+
     const IS_UNSPECIFIED: bool = IP_ADDRESS.is_unspecified();
     assert!(!IS_UNSPECIFIED);
 
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
index 7197f3812e5..9ae2bcc8526 100644
--- a/library/core/tests/slice.rs
+++ b/library/core/tests/slice.rs
@@ -1802,57 +1802,6 @@ fn brute_force_rotate_test_1() {
 
 #[test]
 #[cfg(not(target_arch = "wasm32"))]
-fn sort_unstable() {
-    use rand::Rng;
-
-    // Miri is too slow (but still need to `chain` to make the types match)
-    let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(500..510) };
-    let rounds = if cfg!(miri) { 1 } else { 100 };
-
-    let mut v = [0; 600];
-    let mut tmp = [0; 600];
-    let mut rng = crate::test_rng();
-
-    for len in lens {
-        let v = &mut v[0..len];
-        let tmp = &mut tmp[0..len];
-
-        for &modulus in &[5, 10, 100, 1000] {
-            for _ in 0..rounds {
-                for i in 0..len {
-                    v[i] = rng.gen::<i32>() % modulus;
-                }
-
-                // Sort in default order.
-                tmp.copy_from_slice(v);
-                tmp.sort_unstable();
-                assert!(tmp.windows(2).all(|w| w[0] <= w[1]));
-
-                // Sort in ascending order.
-                tmp.copy_from_slice(v);
-                tmp.sort_unstable_by(|a, b| a.cmp(b));
-                assert!(tmp.windows(2).all(|w| w[0] <= w[1]));
-
-                // Sort in descending order.
-                tmp.copy_from_slice(v);
-                tmp.sort_unstable_by(|a, b| b.cmp(a));
-                assert!(tmp.windows(2).all(|w| w[0] >= w[1]));
-            }
-        }
-    }
-
-    // Should not panic.
-    [0i32; 0].sort_unstable();
-    [(); 10].sort_unstable();
-    [(); 100].sort_unstable();
-
-    let mut v = [0xDEADBEEFu64];
-    v.sort_unstable();
-    assert!(v == [0xDEADBEEF]);
-}
-
-#[test]
-#[cfg(not(target_arch = "wasm32"))]
 #[cfg_attr(miri, ignore)] // Miri is too slow
 fn select_nth_unstable() {
     use core::cmp::Ordering::{Equal, Greater, Less};