2018-03-02 08:50:50 +03:00
|
|
|
use std::fmt::{Debug, Display};
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2019-12-02 11:10:06 +03:00
|
|
|
use string_enum::*;
|
2018-03-02 08:50:50 +03:00
|
|
|
|
|
|
|
pub trait Assert: Debug + Display {}
|
|
|
|
|
|
|
|
#[derive(StringEnum)]
|
|
|
|
pub enum Tokens {
|
|
|
|
///`a`
|
2022-10-10 16:07:25 +03:00
|
|
|
#[string_enum(alias("foo"))]
|
2018-03-02 08:50:50 +03:00
|
|
|
A,
|
2019-02-24 08:12:04 +03:00
|
|
|
/// `b`
|
|
|
|
B,
|
2018-03-02 08:50:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Assert for Tokens {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn as_str() {
|
|
|
|
assert_eq!(Tokens::A.as_str(), "a");
|
2019-02-24 08:12:04 +03:00
|
|
|
assert_eq!(Tokens::B.as_str(), "b");
|
2018-03-02 08:50:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fmt() {
|
|
|
|
assert_eq!(Tokens::A.to_string(), "a");
|
|
|
|
assert_eq!(format!("{}", Tokens::A), "a");
|
|
|
|
}
|