use crate::value_enum;
#[test]
fn correct_values() {
{
value_enum! {
enum Fruit: &'static str {
Apple = "red",
Banana = "yellow",
Blueberry = "blue"
}
}
let apple: Fruit = Fruit::Apple;
assert_eq!(apple.value(), "red");
let banana: Fruit = Fruit::Banana;
assert_eq!(banana.value(), "yellow");
let blueberry: Fruit = Fruit::Blueberry;
assert_eq!(blueberry.value(), "blue");
}
for_each!(
{
let apple: Fruit = Fruit::Apple;
assert_eq!(apple.value(), -42_i16);
let banana: Fruit = Fruit::Banana;
assert_eq!(banana.value(), 7_i16);
let blueberry: Fruit = Fruit::Blueberry;
assert_eq!(blueberry.value(), 13_i16);
};
1 2 3 4 5 6 7
);
}
macro_rules! for_each {
( $code:block ; $n:tt $( $rest:tt )* ) => (
{
make_test_enum!($n);
$code
}
for_each!( $code; $( $rest )* );
);
( $_:block ; ) => ()
}
use for_each;
macro_rules! make_test_enum {
(1) => {
value_enum! {
enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
(2) => {
value_enum! {
pub enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
(3) => {
value_enum! {
enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
(4) => {
value_enum! {
enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
(5) => {
value_enum! {
enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
(6) => {
value_enum! {
enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
(7) => {
value_enum! {
enum Fruit: i16 {
Apple = -42,
Banana = 7,
Blueberry = 13
}
}
};
}
use make_test_enum;