| 1 |
use arg_enum_proc_macro::ArgEnum; |
| 2 |
|
| 3 |
#[derive(ArgEnum, PartialEq, Debug)] |
| 4 |
pub enum Foo { |
| 5 |
Bar, |
| 6 |
/// Foo |
| 7 |
Baz, |
| 8 |
} |
| 9 |
|
| 10 |
#[test] |
| 11 |
fn parse() { |
| 12 |
let v: Foo = "Baz".parse().unwrap(); |
| 13 |
|
| 14 |
assert_eq!(v, Foo::Baz); |
| 15 |
} |
| 16 |
|
| 17 |
#[test] |
| 18 |
fn variants() { |
| 19 |
assert_eq!(&Foo::variants(), &["Bar", "Baz"]); |
| 20 |
} |
| 21 |
|
| 22 |
mod alias { |
| 23 |
use arg_enum_proc_macro::ArgEnum; |
| 24 |
|
| 25 |
#[derive(ArgEnum, PartialEq, Debug)] |
| 26 |
pub enum Bar { |
| 27 |
A, |
| 28 |
B, |
| 29 |
#[arg_enum(alias = "Cat")] |
| 30 |
C, |
| 31 |
} |
| 32 |
|
| 33 |
#[test] |
| 34 |
fn parse() { |
| 35 |
let v: Bar = "Cat".parse().unwrap(); |
| 36 |
|
| 37 |
assert_eq!(v, Bar::C); |
| 38 |
} |
| 39 |
|
| 40 |
#[test] |
| 41 |
fn variants() { |
| 42 |
assert_eq!(&Bar::variants(), &["A", "B", "C", "Cat"]); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
mod name { |
| 47 |
use arg_enum_proc_macro::ArgEnum; |
| 48 |
|
| 49 |
#[derive(ArgEnum, PartialEq, Debug)] |
| 50 |
pub enum Bar { |
| 51 |
A, |
| 52 |
B, |
| 53 |
#[arg_enum(name = "Cat", alias = "Feline")] |
| 54 |
C, |
| 55 |
} |
| 56 |
|
| 57 |
#[test] |
| 58 |
fn parse() { |
| 59 |
let v: Bar = "Cat".parse().unwrap(); |
| 60 |
|
| 61 |
assert_eq!(v, Bar::C); |
| 62 |
} |
| 63 |
|
| 64 |
#[test] |
| 65 |
fn variants() { |
| 66 |
assert_eq!(&Bar::variants(), &["A", "B", "Cat", "Feline"]); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
mod description { |
| 71 |
use arg_enum_proc_macro::ArgEnum; |
| 72 |
|
| 73 |
#[derive(ArgEnum, PartialEq, Debug)] |
| 74 |
pub enum Bar { |
| 75 |
/// This is A and it's description is a single line |
| 76 |
A, |
| 77 |
/// This is B and it's description contains " for no specific reason |
| 78 |
/// and is in two lines. |
| 79 |
B, |
| 80 |
/// This is C, normally known as "Cat" or "Feline" |
| 81 |
#[arg_enum(name = "Cat", alias = "Feline")] |
| 82 |
C, |
| 83 |
} |
| 84 |
|
| 85 |
#[test] |
| 86 |
fn descriptions() { |
| 87 |
let expected: [(&'static [&'static str], &'static [&'static str]); 3usize] = [ |
| 88 |
( |
| 89 |
&["A"], |
| 90 |
&[" This is A and it's description is a single line"], |
| 91 |
), |
| 92 |
( |
| 93 |
&["B"], |
| 94 |
&[ |
| 95 |
" This is B and it's description contains \" for no specific reason", |
| 96 |
" and is in two lines.", |
| 97 |
], |
| 98 |
), |
| 99 |
( |
| 100 |
&["Cat", "Feline"], |
| 101 |
&[" This is C, normally known as \"Cat\" or \"Feline\""], |
| 102 |
), |
| 103 |
]; |
| 104 |
assert_eq!(&Bar::descriptions(), &expected); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
mod ui { |
| 109 |
#[test] |
| 110 |
fn invalid_applications() { |
| 111 |
let t = trybuild::TestCases::new(); |
| 112 |
t.compile_fail("tests/ui/complex-enum.rs"); |
| 113 |
t.compile_fail("tests/ui/derive-not-on-enum.rs"); |
| 114 |
} |
| 115 |
} |