Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from KodrAus/chore/test-organization
Test organization
- Loading branch information
Showing
22 changed files
with
774 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,6 @@ bitflags! { | |
} | ||
|
||
#[test] | ||
fn smoke() { | ||
fn basic() { | ||
assert_eq!(Flags::ABC, Flags::A | Flags::B | Flags::C); | ||
} |
8 changes: 1 addition & 7 deletions
8
tests/conflicting_trait_impls.rs → tests/compile-fail/derive/copy.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use core::fmt::Display; | ||
|
||
use bitflags::bitflags; | ||
|
||
bitflags! { | ||
/// baz | ||
#[derive(Clone, Copy)] | ||
struct Flags: u32 { | ||
const A = 0b00000001; | ||
} | ||
} | ||
|
||
#[test] | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0119]: conflicting implementations of trait `std::clone::Clone` for type `Flags` | ||
--> $DIR/copy.rs:3:1 | ||
| | ||
3 | / bitflags! { | ||
4 | | #[derive(Clone, Copy)] | ||
| | ----- first implementation here | ||
5 | | struct Flags: u32 { | ||
6 | | const A = 0b00000001; | ||
7 | | } | ||
8 | | } | ||
| |_^ conflicting implementation for `Flags` | ||
| | ||
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `Flags` | ||
--> $DIR/copy.rs:3:1 | ||
| | ||
3 | / bitflags! { | ||
4 | | #[derive(Clone, Copy)] | ||
| | ---- first implementation here | ||
5 | | struct Flags: u32 { | ||
6 | | const A = 0b00000001; | ||
7 | | } | ||
8 | | } | ||
| |_^ conflicting implementation for `Flags` | ||
| | ||
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use bitflags::bitflags; | ||
|
||
bitflags! { | ||
#[derive(PartialEq, Eq)] | ||
struct Flags: u32 { | ||
const A = 0b00000001; | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
error[E0119]: conflicting implementations of trait `std::cmp::PartialEq` for type `Flags` | ||
--> $DIR/eq.rs:3:1 | ||
| | ||
3 | / bitflags! { | ||
4 | | #[derive(PartialEq, Eq)] | ||
| | --------- first implementation here | ||
5 | | struct Flags: u32 { | ||
6 | | const A = 0b00000001; | ||
7 | | } | ||
8 | | } | ||
| |_^ conflicting implementation for `Flags` | ||
| | ||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `std::cmp::Eq` for type `Flags` | ||
--> $DIR/eq.rs:3:1 | ||
| | ||
3 | / bitflags! { | ||
4 | | #[derive(PartialEq, Eq)] | ||
| | -- first implementation here | ||
5 | | struct Flags: u32 { | ||
6 | | const A = 0b00000001; | ||
7 | | } | ||
8 | | } | ||
| |_^ conflicting implementation for `Flags` | ||
| | ||
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `std::marker::StructuralPartialEq` for type `Flags` | ||
--> $DIR/eq.rs:3:1 | ||
| | ||
3 | / bitflags! { | ||
4 | | #[derive(PartialEq, Eq)] | ||
| | --------- first implementation here | ||
5 | | struct Flags: u32 { | ||
6 | | const A = 0b00000001; | ||
7 | | } | ||
8 | | } | ||
| |_^ conflicting implementation for `Flags` | ||
| | ||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0119]: conflicting implementations of trait `std::marker::StructuralEq` for type `Flags` | ||
--> $DIR/eq.rs:3:1 | ||
| | ||
3 | / bitflags! { | ||
4 | | #[derive(PartialEq, Eq)] | ||
| | -- first implementation here | ||
5 | | struct Flags: u32 { | ||
6 | | const A = 0b00000001; | ||
7 | | } | ||
8 | | } | ||
| |_^ conflicting implementation for `Flags` | ||
| | ||
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use std::{ | ||
fmt::{ | ||
self, | ||
Debug, | ||
Display, | ||
LowerHex, | ||
UpperHex, | ||
Octal, | ||
Binary, | ||
}, | ||
ops::{ | ||
BitAnd, | ||
BitOr, | ||
BitXor, | ||
BitAndAssign, | ||
BitOrAssign, | ||
BitXorAssign, | ||
Not, | ||
}, | ||
}; | ||
|
||
use bitflags::bitflags; | ||
|
||
// Ideally we'd actually want this to work, but currently need something like `num`'s `Zero` | ||
// With some design work it could be made possible | ||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
struct MyInt(u8); | ||
|
||
impl BitAnd for MyInt { | ||
type Output = Self; | ||
|
||
fn bitand(self, other: Self) -> Self { | ||
MyInt(self.0 & other.0) | ||
} | ||
} | ||
|
||
impl BitOr for MyInt { | ||
type Output = Self; | ||
|
||
fn bitor(self, other: Self) -> Self { | ||
MyInt(self.0 | other.0) | ||
} | ||
} | ||
|
||
impl BitXor for MyInt { | ||
type Output = Self; | ||
|
||
fn bitxor(self, other: Self) -> Self { | ||
MyInt(self.0 ^ other.0) | ||
} | ||
} | ||
|
||
impl BitAndAssign for MyInt { | ||
fn bitand_assign(&mut self, other: Self) { | ||
self.0 &= other.0 | ||
} | ||
} | ||
|
||
impl BitOrAssign for MyInt { | ||
fn bitor_assign(&mut self, other: Self) { | ||
self.0 |= other.0 | ||
} | ||
} | ||
|
||
impl BitXorAssign for MyInt { | ||
fn bitxor_assign(&mut self, other: Self) { | ||
self.0 ^= other.0 | ||
} | ||
} | ||
|
||
impl Debug for MyInt { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
Debug::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl Display for MyInt { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
Display::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl LowerHex for MyInt { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
LowerHex::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl UpperHex for MyInt { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
UpperHex::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl Octal for MyInt { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
Octal::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl Binary for MyInt { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
Binary::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl Not for MyInt { | ||
type Output = MyInt; | ||
|
||
fn not(self) -> Self { | ||
MyInt(!self.0) | ||
} | ||
} | ||
|
||
bitflags! { | ||
struct Flags128: MyInt { | ||
const A = MyInt(0b0000_0001u8); | ||
const B = MyInt(0b0000_0010u8); | ||
const C = MyInt(0b0000_0100u8); | ||
} | ||
} | ||
|
||
fn main() {} |
27 changes: 27 additions & 0 deletions
27
tests/compile-fail/non_integer_base/all_defined.stderr.beta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/all_defined.rs:115:1 | ||
| | ||
115 | / bitflags! { | ||
116 | | struct Flags128: MyInt { | ||
117 | | const A = MyInt(0b0000_0001u8); | ||
118 | | const B = MyInt(0b0000_0010u8); | ||
119 | | const C = MyInt(0b0000_0100u8); | ||
120 | | } | ||
121 | | } | ||
| |_^ expected struct `MyInt`, found integer | ||
| | ||
= note: this error originates in the macro `__impl_all_bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/all_defined.rs:115:1 | ||
| | ||
115 | / bitflags! { | ||
116 | | struct Flags128: MyInt { | ||
117 | | const A = MyInt(0b0000_0001u8); | ||
118 | | const B = MyInt(0b0000_0010u8); | ||
119 | | const C = MyInt(0b0000_0100u8); | ||
120 | | } | ||
121 | | } | ||
| |_^ expected struct `MyInt`, found integer | ||
| | ||
= note: this error originates in the macro `__impl_bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use bitflags::bitflags; | ||
|
||
#[derive(Clone, Copy)] | ||
struct MyInt(u8); | ||
|
||
bitflags! { | ||
struct Flags128: MyInt { | ||
const A = MyInt(0b0000_0001); | ||
const B = MyInt(0b0000_0010); | ||
const C = MyInt(0b0000_0100); | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.