camel_case_token_with_comment/
errors.rs

1// ---------------- [ File: camel-case-token-with-comment/src/errors.rs ]
2crate::ix!();
3
4error_tree!{
5
6    #[derive(PartialEq)]
7    pub enum TokenParseError {
8        InvalidTokenName,
9        InvalidTokenLine(String),
10        MissingTokenNameField,
11
12        #[cmp_neq]
13        IoError(std::io::Error),
14    }
15}
16
17#[cfg(test)]
18mod test_token_parse_error {
19    use super::*;
20
21    #[traced_test]
22    fn test_token_parse_error_variants() {
23        tracing::info!("Testing TokenParseError variants");
24
25        let e1 = TokenParseError::InvalidTokenName;
26        let e2 = TokenParseError::InvalidTokenLine("some line".to_string());
27        let e3 = TokenParseError::MissingTokenNameField;
28        let io_err = std::io::Error::new(std::io::ErrorKind::Other, "oh no!");
29        let e4 = TokenParseError::IoError(io_err);
30
31        match e1 {
32            TokenParseError::InvalidTokenName => {
33                tracing::info!("Matched InvalidTokenName successfully");
34            }
35            _ => panic!("Should have matched InvalidTokenName"),
36        }
37
38        match e2 {
39            TokenParseError::InvalidTokenLine(ref s) if s == "some line" => {
40                tracing::info!("Matched InvalidTokenLine with expected content");
41            }
42            _ => panic!("Should have matched InvalidTokenLine"),
43        }
44
45        match e3 {
46            TokenParseError::MissingTokenNameField => {
47                tracing::info!("Matched MissingTokenNameField successfully");
48            }
49            _ => panic!("Should have matched MissingTokenNameField"),
50        }
51
52        match e4 {
53            TokenParseError::IoError(ref err) => {
54                pretty_assert_eq!(format!("{}", err), "oh no!");
55                tracing::info!("Matched IoError as expected");
56            }
57            _ => panic!("Should have matched IoError"),
58        }
59    }
60}