Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up incorrect sub assign behavior and other cleanups #366

Merged
merged 15 commits into from
Jun 27, 2023
Prev Previous commit
Next Next commit
test aginst specific bits values
  • Loading branch information
KodrAus committed Jun 26, 2023
commit 16667c7db7dd601f1e2f172289f2e87af39abcc2
15 changes: 9 additions & 6 deletions src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ use super::*;
use crate::Flags;

#[track_caller]
fn case<T: Flags + std::fmt::Debug + PartialEq>(expected: T, inherent: impl FnOnce() -> T) {
assert_eq!(expected, inherent(), "T::all()");
assert_eq!(expected, T::all(), "Flags::all()");
fn case<T: Flags>(expected: T::Bits, inherent: impl FnOnce() -> T)
where
<T as Flags>::Bits: std::fmt::Debug + PartialEq,
{
assert_eq!(expected, inherent().bits(), "T::all()");
assert_eq!(expected, T::all().bits(), "Flags::all()");
}

#[test]
fn cases() {
case(TestFlags::A | TestFlags::B | TestFlags::C, TestFlags::all);
case(1 | 1 << 1 | 1 << 2, TestFlags::all);

case(TestZero::empty(), TestZero::all);
case(0, TestZero::all);

case(TestEmpty::empty(), TestEmpty::all);
case(0, TestEmpty::all);
}
2 changes: 1 addition & 1 deletion src/tests/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ fn cases() {
case(0, TestFlags::empty(), TestFlags::bits);

case(1, TestFlags::A, TestFlags::bits);

case(1 | 1 << 1 | 1 << 2, TestFlags::ABC, TestFlags::bits);

case(!0, TestFlags::from_bits_retain(u8::MAX), TestFlags::bits);
case(1 << 3, TestFlags::from_bits_retain(1 << 3), TestFlags::bits);

case(1 << 3, TestZero::from_bits_retain(1 << 3), TestZero::bits);
Expand Down
23 changes: 18 additions & 5 deletions src/tests/empty.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
/*
Unknown bits:
- Any unknown bits should make `empty` return `false`: specify as `== Zero`
*/
use super::*;

use crate::Flags;

#[track_caller]
fn case<T: Flags>(expected: T::Bits, inherent: impl FnOnce() -> T)
where
<T as Flags>::Bits: std::fmt::Debug + PartialEq,
{
assert_eq!(expected, inherent().bits(), "T::empty()");
assert_eq!(expected, T::empty().bits(), "Flags::empty()");
}

#[test]
fn cases() {
todo!()
case(0, TestFlags::empty);

case(0, TestZero::empty);

case(0, TestEmpty::empty);
}