Skip to content

Commit c9bab92

Browse files
sayantnfolkertdev
andcommitted
Add tests
Co-Authored-By: folkertdev <folkert@folkertdev.nl>
1 parent badf1bf commit c9bab92

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#![feature(fmt_internals)]
5151
#![feature(formatting_options)]
5252
#![feature(freeze)]
53+
#![feature(funnel_shifts)]
5354
#![feature(future_join)]
5455
#![feature(generic_assert_internals)]
5556
#![feature(hasher_prefixfree_extras)]

library/coretests/tests/num/uint_macros.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ macro_rules! uint_module {
104104
assert_eq_const_safe!($T: C.rotate_left(128), C);
105105
}
106106

107+
fn test_funnel_shift() {
108+
// Shifting by 0 should have no effect
109+
assert_eq_const_safe!($T: <$T>::funnel_shl(A, B, 0), A);
110+
assert_eq_const_safe!($T: <$T>::funnel_shr(A, B, 0), B);
111+
112+
assert_eq_const_safe!($T: <$T>::funnel_shl(_0, _1, 4), 0b1111);
113+
assert_eq_const_safe!($T: <$T>::funnel_shr(_0, _1, 4), _1 >> 4);
114+
assert_eq_const_safe!($T: <$T>::funnel_shl(_1, _0, 4), _1 << 4);
115+
116+
assert_eq_const_safe!($T: <$T>::funnel_shl(_1, _1, 4), <$T>::rotate_left(_1, 4));
117+
assert_eq_const_safe!($T: <$T>::funnel_shr(_1, _1, 4), <$T>::rotate_right(_1, 4));
118+
}
119+
107120
fn test_swap_bytes() {
108121
assert_eq_const_safe!($T: A.swap_bytes().swap_bytes(), A);
109122
assert_eq_const_safe!($T: B.swap_bytes().swap_bytes(), B);
@@ -150,6 +163,12 @@ macro_rules! uint_module {
150163
}
151164
}
152165

166+
#[test]
167+
#[should_panic = "attempt to funnel shift left with overflow"]
168+
fn test_funnel_shift_overflow() {
169+
let _ = <$T>::funnel_shl(A, B, 150);
170+
}
171+
153172
#[test]
154173
fn test_isolate_highest_one() {
155174
const BITS: $T = <$T>::MAX;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(core_intrinsics, funnel_shifts)]
2+
3+
fn main() {
4+
unsafe {
5+
std::intrinsics::unchecked_funnel_shl(1_u32, 2, 5);
6+
std::intrinsics::unchecked_funnel_shl(1_u32, 2, 31);
7+
std::intrinsics::unchecked_funnel_shl(1_u32, 2, 32); //~ ERROR: Undefined Behavior
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/funnel_shl.rs:LL:CC
3+
|
4+
LL | std::intrinsics::unchecked_funnel_shl(1_u32, 2, 32);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/funnel_shl.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(core_intrinsics, funnel_shifts)]
2+
3+
fn main() {
4+
unsafe {
5+
std::intrinsics::unchecked_funnel_shr(1_u32, 2, 5);
6+
std::intrinsics::unchecked_funnel_shr(1_u32, 2, 31);
7+
std::intrinsics::unchecked_funnel_shr(1_u32, 2, 32); //~ ERROR: Undefined Behavior
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/funnel_shr.rs:LL:CC
3+
|
4+
LL | std::intrinsics::unchecked_funnel_shr(1_u32, 2, 32);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/funnel_shr.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)