Skip to content

Commit d1f3861

Browse files
committed
Add tests
Co-Authored-By: folkertdev <[email protected]>
1 parent 2549e8a commit d1f3861

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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;

0 commit comments

Comments
 (0)