summaryrefslogtreecommitdiffstats
path: root/library/core/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /library/core/tests
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/tests')
-rw-r--r--library/core/tests/array.rs1
-rw-r--r--library/core/tests/cell.rs2
-rw-r--r--library/core/tests/char.rs1
-rw-r--r--library/core/tests/fmt/num.rs23
-rw-r--r--library/core/tests/hash/mod.rs3
-rw-r--r--library/core/tests/iter/adapters/array_chunks.rs3
-rw-r--r--library/core/tests/iter/mod.rs1
-rw-r--r--library/core/tests/lib.rs4
-rw-r--r--library/core/tests/nonzero.rs3
-rw-r--r--library/core/tests/num/mod.rs5
-rw-r--r--library/core/tests/option.rs9
-rw-r--r--library/core/tests/simd.rs3
-rw-r--r--library/core/tests/slice.rs1
-rw-r--r--library/core/tests/time.rs13
14 files changed, 47 insertions, 25 deletions
diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs
index 81da75d32..3656eecca 100644
--- a/library/core/tests/array.rs
+++ b/library/core/tests/array.rs
@@ -1,5 +1,4 @@
use core::{array, assert_eq};
-use core::convert::TryFrom;
use core::num::NonZeroUsize;
use core::sync::atomic::{AtomicUsize, Ordering};
diff --git a/library/core/tests/cell.rs b/library/core/tests/cell.rs
index e084f8679..71b8eb296 100644
--- a/library/core/tests/cell.rs
+++ b/library/core/tests/cell.rs
@@ -1,6 +1,4 @@
use core::cell::*;
-use core::default::Default;
-use std::mem::drop;
#[test]
fn smoketest_unsafe_cell() {
diff --git a/library/core/tests/char.rs b/library/core/tests/char.rs
index 85ba51c92..6422387e9 100644
--- a/library/core/tests/char.rs
+++ b/library/core/tests/char.rs
@@ -1,4 +1,3 @@
-use std::convert::TryFrom;
use std::str::FromStr;
use std::{char, str};
diff --git a/library/core/tests/fmt/num.rs b/library/core/tests/fmt/num.rs
index b9ede65c9..bc387a46e 100644
--- a/library/core/tests/fmt/num.rs
+++ b/library/core/tests/fmt/num.rs
@@ -128,28 +128,43 @@ fn test_format_int_exp_precision() {
let big_int: u32 = 314_159_265;
assert_eq!(format!("{big_int:.1e}"), format!("{:.1e}", f64::from(big_int)));
- //test adding precision
+ // test adding precision
assert_eq!(format!("{:.10e}", i8::MIN), "-1.2800000000e2");
assert_eq!(format!("{:.10e}", i16::MIN), "-3.2768000000e4");
assert_eq!(format!("{:.10e}", i32::MIN), "-2.1474836480e9");
assert_eq!(format!("{:.20e}", i64::MIN), "-9.22337203685477580800e18");
assert_eq!(format!("{:.40e}", i128::MIN), "-1.7014118346046923173168730371588410572800e38");
- //test rounding
+ // test rounding
assert_eq!(format!("{:.1e}", i8::MIN), "-1.3e2");
assert_eq!(format!("{:.1e}", i16::MIN), "-3.3e4");
assert_eq!(format!("{:.1e}", i32::MIN), "-2.1e9");
assert_eq!(format!("{:.1e}", i64::MIN), "-9.2e18");
assert_eq!(format!("{:.1e}", i128::MIN), "-1.7e38");
- //test huge precision
+ // test huge precision
assert_eq!(format!("{:.1000e}", 1), format!("1.{}e0", "0".repeat(1000)));
//test zero precision
assert_eq!(format!("{:.0e}", 1), format!("1e0",));
assert_eq!(format!("{:.0e}", 35), format!("4e1",));
- //test padding with precision (and sign)
+ // test padding with precision (and sign)
assert_eq!(format!("{:+10.3e}", 1), " +1.000e0");
+
+ // test precision remains correct when rounding to next power
+ #[cfg(miri)] // can't cover all of `i16` in Miri
+ let range = [i16::MIN, -1, 1, i16::MAX];
+ #[cfg(not(miri))]
+ let range = i16::MIN..=i16::MAX;
+ for i in range {
+ for p in 0..=5 {
+ assert_eq!(
+ format!("{i:.p$e}"),
+ format!("{:.p$e}", f32::from(i)),
+ "integer {i} at precision {p}"
+ );
+ }
+ }
}
#[test]
diff --git a/library/core/tests/hash/mod.rs b/library/core/tests/hash/mod.rs
index 033bd1ed6..addc255de 100644
--- a/library/core/tests/hash/mod.rs
+++ b/library/core/tests/hash/mod.rs
@@ -1,6 +1,5 @@
mod sip;
-use std::default::Default;
use std::hash::{BuildHasher, Hash, Hasher};
use std::ptr;
use std::rc::Rc;
@@ -167,7 +166,7 @@ fn test_indirect_hasher() {
#[test]
fn test_build_hasher_object_safe() {
- use std::collections::hash_map::{DefaultHasher, RandomState};
+ use std::hash::{DefaultHasher, RandomState};
let _: &dyn BuildHasher<Hasher = DefaultHasher> = &RandomState::new();
}
diff --git a/library/core/tests/iter/adapters/array_chunks.rs b/library/core/tests/iter/adapters/array_chunks.rs
index ef4a7e53b..fb19a519f 100644
--- a/library/core/tests/iter/adapters/array_chunks.rs
+++ b/library/core/tests/iter/adapters/array_chunks.rs
@@ -1,5 +1,4 @@
-use core::cell::Cell;
-use core::iter::{self, Iterator};
+use core::iter::{self};
use super::*;
diff --git a/library/core/tests/iter/mod.rs b/library/core/tests/iter/mod.rs
index 770b6f760..5b2769d04 100644
--- a/library/core/tests/iter/mod.rs
+++ b/library/core/tests/iter/mod.rs
@@ -21,7 +21,6 @@ mod sources;
mod traits;
use core::cell::Cell;
-use core::convert::TryFrom;
use core::iter::*;
pub fn is_trusted_len<I: TrustedLen>(_: I) {}
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 168b47dc9..ac8b6f6b5 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -28,6 +28,7 @@
#![feature(core_private_diy_float)]
#![feature(dec2flt)]
#![feature(div_duration)]
+#![feature(duration_abs_diff)]
#![feature(duration_consts_float)]
#![feature(duration_constants)]
#![feature(exact_size_is_empty)]
@@ -116,6 +117,7 @@
#![feature(get_many_mut)]
#![feature(offset_of)]
#![feature(iter_map_windows)]
+#![allow(internal_features)]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(fuzzy_provenance_casts)]
@@ -169,7 +171,7 @@ mod waker;
#[allow(dead_code)] // Not used in all configurations.
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
use core::hash::{BuildHasher, Hash, Hasher};
- let mut hasher = std::collections::hash_map::RandomState::new().build_hasher();
+ let mut hasher = std::hash::RandomState::new().build_hasher();
core::panic::Location::caller().hash(&mut hasher);
let hc64 = hasher.finish();
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();
diff --git a/library/core/tests/nonzero.rs b/library/core/tests/nonzero.rs
index 007f84425..8873d2688 100644
--- a/library/core/tests/nonzero.rs
+++ b/library/core/tests/nonzero.rs
@@ -1,9 +1,8 @@
-use core::convert::TryFrom;
use core::num::{
IntErrorKind, NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize,
NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
};
-use core::option::Option::{self, None, Some};
+use core::option::Option::None;
use std::mem::size_of;
#[test]
diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs
index 3f3659ba8..863da9b18 100644
--- a/library/core/tests/num/mod.rs
+++ b/library/core/tests/num/mod.rs
@@ -1,11 +1,6 @@
-use core::cmp::PartialEq;
-use core::convert::{TryFrom, TryInto};
use core::fmt::Debug;
-use core::marker::Copy;
use core::num::{can_not_overflow, IntErrorKind, ParseIntError, TryFromIntError};
use core::ops::{Add, Div, Mul, Rem, Sub};
-use core::option::Option;
-use core::option::Option::None;
use core::str::FromStr;
#[macro_use]
diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs
index 5defeb50d..00a308b29 100644
--- a/library/core/tests/option.rs
+++ b/library/core/tests/option.rs
@@ -1,5 +1,4 @@
use core::cell::Cell;
-use core::clone::Clone;
use core::mem;
use core::ops::DerefMut;
use core::option::*;
@@ -568,3 +567,11 @@ fn zip_unzip_roundtrip() {
let a = z.unzip();
assert_eq!(a, (x, y));
}
+
+#[test]
+fn as_slice() {
+ assert_eq!(Some(42).as_slice(), &[42]);
+ assert_eq!(Some(43).as_mut_slice(), &[43]);
+ assert_eq!(None::<i32>.as_slice(), &[]);
+ assert_eq!(None::<i32>.as_mut_slice(), &[]);
+}
diff --git a/library/core/tests/simd.rs b/library/core/tests/simd.rs
index 565c8975e..b8b5f26ca 100644
--- a/library/core/tests/simd.rs
+++ b/library/core/tests/simd.rs
@@ -1,5 +1,4 @@
-use core::simd::f32x4;
-use core::simd::SimdFloat;
+use core::simd::prelude::*;
#[test]
fn testing() {
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
index 666452ead..33a303398 100644
--- a/library/core/tests/slice.rs
+++ b/library/core/tests/slice.rs
@@ -2,7 +2,6 @@ use core::cell::Cell;
use core::cmp::Ordering;
use core::mem::MaybeUninit;
use core::num::NonZeroUsize;
-use core::result::Result::{Err, Ok};
use core::slice;
#[test]
diff --git a/library/core/tests/time.rs b/library/core/tests/time.rs
index bd6e63edb..24ab4be9d 100644
--- a/library/core/tests/time.rs
+++ b/library/core/tests/time.rs
@@ -74,6 +74,19 @@ fn nanos() {
}
#[test]
+fn abs_diff() {
+ assert_eq!(Duration::new(2, 0).abs_diff(Duration::new(1, 0)), Duration::new(1, 0));
+ assert_eq!(Duration::new(1, 0).abs_diff(Duration::new(2, 0)), Duration::new(1, 0));
+ assert_eq!(Duration::new(1, 0).abs_diff(Duration::new(1, 0)), Duration::new(0, 0));
+ assert_eq!(Duration::new(1, 1).abs_diff(Duration::new(0, 2)), Duration::new(0, 999_999_999));
+ assert_eq!(Duration::new(1, 1).abs_diff(Duration::new(2, 1)), Duration::new(1, 0));
+ assert_eq!(Duration::MAX.abs_diff(Duration::MAX), Duration::ZERO);
+ assert_eq!(Duration::ZERO.abs_diff(Duration::ZERO), Duration::ZERO);
+ assert_eq!(Duration::MAX.abs_diff(Duration::ZERO), Duration::MAX);
+ assert_eq!(Duration::ZERO.abs_diff(Duration::MAX), Duration::MAX);
+}
+
+#[test]
fn add() {
assert_eq!(Duration::new(0, 0) + Duration::new(0, 1), Duration::new(0, 1));
assert_eq!(Duration::new(0, 500_000_000) + Duration::new(0, 500_000_001), Duration::new(1, 1));