swc/crates/string_enum/tests/simple.rs

29 lines
456 B
Rust
Raw Normal View History

2018-03-02 08:50:50 +03:00
use std::fmt::{Debug, Display};
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`
#[string_enum(alias("foo"))]
2018-03-02 08:50:50 +03:00
A,
/// `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");
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");
}