2017-02-16 04:16:40 +01:00
|
|
|
extern crate strum;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate strum_macros;
|
|
|
|
|
|
|
|
use strum::IntoEnumIterator;
|
|
|
|
|
|
|
|
#[derive(Debug,Eq,PartialEq,EnumIter)]
|
|
|
|
enum Week {
|
|
|
|
Sunday,
|
|
|
|
Monday,
|
|
|
|
Tuesday,
|
|
|
|
Wednesday,
|
|
|
|
Thursday,
|
|
|
|
Friday,
|
|
|
|
Saturday,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn simple_test() {
|
|
|
|
let results = Week::iter().collect::<Vec<_>>();
|
|
|
|
let expected = vec![Week::Sunday,
|
|
|
|
Week::Monday,
|
|
|
|
Week::Tuesday,
|
|
|
|
Week::Wednesday,
|
|
|
|
Week::Thursday,
|
|
|
|
Week::Friday,
|
|
|
|
Week::Saturday];
|
|
|
|
|
|
|
|
assert_eq!(expected, results);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug,Eq,PartialEq,EnumIter)]
|
|
|
|
enum Complicated<U: Default, V: Default> {
|
|
|
|
A(U),
|
|
|
|
B { v: V },
|
|
|
|
C,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn complicated_test() {
|
|
|
|
let results = Complicated::iter().collect::<Vec<_>>();
|
2017-04-16 03:08:49 +02:00
|
|
|
let expected = vec![Complicated::A(0),
|
|
|
|
Complicated::B { v: String::new() },
|
|
|
|
Complicated::C];
|
2017-02-16 04:16:40 +01:00
|
|
|
|
|
|
|
assert_eq!(expected, results);
|
|
|
|
}
|
2018-03-10 22:06:17 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn len_test() {
|
|
|
|
let mut i = Complicated::<(),()>::iter();
|
|
|
|
assert_eq!(3, i.len());
|
|
|
|
i.next();
|
|
|
|
|
|
|
|
assert_eq!(2, i.len());
|
|
|
|
i.next();
|
|
|
|
|
|
|
|
assert_eq!(1, i.len());
|
|
|
|
i.next();
|
|
|
|
|
|
|
|
assert_eq!(0, i.len());
|
|
|
|
}
|