fluidattacks_blends_domain/syntax/
error.rs1#[derive(Clone, Copy, PartialEq, Eq, Debug)]
4pub enum SyntaxGraphError {
5 EmptyAstGraph,
6 MissingRootNode,
7 MissingAstNode,
8 UnexpectedAstShape,
9 UnsupportedLanguage,
10}
11
12impl core::fmt::Display for SyntaxGraphError {
13 fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14 formatter.write_str(match *self {
15 Self::EmptyAstGraph => "ast graph has no nodes",
16 Self::MissingRootNode => "ast graph has no root node at id 1",
17 Self::MissingAstNode => "a reader reached an id absent from the ast graph",
18 Self::UnexpectedAstShape => "a reader found an ast shape its grammar cannot produce",
19 Self::UnsupportedLanguage => "no syntax dispatcher is implemented for this language",
20 })
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use super::SyntaxGraphError;
27 use alloc::string::ToString;
28
29 #[test]
30 fn every_error_renders_its_failure_mode() {
31 assert_eq!(
32 SyntaxGraphError::EmptyAstGraph.to_string(),
33 "ast graph has no nodes"
34 );
35 assert_eq!(
36 SyntaxGraphError::MissingRootNode.to_string(),
37 "ast graph has no root node at id 1"
38 );
39 assert_eq!(
40 SyntaxGraphError::MissingAstNode.to_string(),
41 "a reader reached an id absent from the ast graph"
42 );
43 assert_eq!(
44 SyntaxGraphError::UnexpectedAstShape.to_string(),
45 "a reader found an ast shape its grammar cannot produce"
46 );
47 assert_eq!(
48 SyntaxGraphError::UnsupportedLanguage.to_string(),
49 "no syntax dispatcher is implemented for this language"
50 );
51 }
52}