use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ErrorCode {
E001,
E002,
E003,
E004,
E005,
E006,
E100,
E101,
E200,
E201,
E202,
E203,
E300,
E301,
E302,
E303,
E304,
E305,
E306,
E307,
E308,
E309,
}
impl ErrorCode {
pub fn as_str(&self) -> &'static str {
match self {
ErrorCode::E001 => "E001",
ErrorCode::E002 => "E002",
ErrorCode::E003 => "E003",
ErrorCode::E004 => "E004",
ErrorCode::E005 => "E005",
ErrorCode::E006 => "E006",
ErrorCode::E100 => "E100",
ErrorCode::E101 => "E101",
ErrorCode::E200 => "E200",
ErrorCode::E201 => "E201",
ErrorCode::E202 => "E202",
ErrorCode::E203 => "E203",
ErrorCode::E300 => "E300",
ErrorCode::E301 => "E301",
ErrorCode::E302 => "E302",
ErrorCode::E303 => "E303",
ErrorCode::E304 => "E304",
ErrorCode::E305 => "E305",
ErrorCode::E306 => "E306",
ErrorCode::E307 => "E307",
ErrorCode::E308 => "E308",
ErrorCode::E309 => "E309",
}
}
pub fn description(&self) -> &'static str {
match self {
ErrorCode::E001 => "unterminated string literal",
ErrorCode::E002 => "unexpected character",
ErrorCode::E003 => "invalid escape sequence",
ErrorCode::E004 => "invalid unicode escape",
ErrorCode::E005 => "invalid unicode codepoint",
ErrorCode::E006 => "empty unicode escape",
ErrorCode::E100 => "unexpected token",
ErrorCode::E101 => "incomplete input",
ErrorCode::E200 => "undefined component",
ErrorCode::E201 => "unpaired activate",
ErrorCode::E202 => "unpaired deactivate",
ErrorCode::E203 => "invalid align value",
ErrorCode::E300 => "undefined type",
ErrorCode::E301 => "duplicate type definition",
ErrorCode::E302 => "invalid attribute value",
ErrorCode::E303 => "unknown attribute",
ErrorCode::E304 => "unsupported attribute",
ErrorCode::E305 => "nested diagram not allowed",
ErrorCode::E306 => "invalid diagram structure",
ErrorCode::E307 => "type mismatch",
ErrorCode::E308 => "shape does not support nested content",
ErrorCode::E309 => "diagram cannot share scope",
}
}
}
impl fmt::Display for ErrorCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_code_display() {
assert_eq!(ErrorCode::E001.to_string(), "E001");
assert_eq!(ErrorCode::E100.to_string(), "E100");
assert_eq!(ErrorCode::E200.to_string(), "E200");
assert_eq!(ErrorCode::E300.to_string(), "E300");
}
#[test]
fn test_error_code_as_str() {
assert_eq!(ErrorCode::E001.as_str(), "E001");
assert_eq!(ErrorCode::E306.as_str(), "E306");
}
#[test]
fn test_error_code_description() {
assert_eq!(ErrorCode::E001.description(), "unterminated string literal");
assert_eq!(ErrorCode::E200.description(), "undefined component");
assert_eq!(ErrorCode::E301.description(), "duplicate type definition");
}
}