1pub mod ast;
8pub mod ir;
9pub mod node;
10pub mod pred;
11pub mod shexr;
12
13pub use ast::*;
14pub use ir::schema_ir_error::*;
15pub use ir::shape_label_idx::*;
16
17pub use node::*;
18pub use pred::*;
19use rbe::MatchCond;
20
21type CResult<T> = Result<T, SchemaIRError>;
22type Cond = MatchCond<Pred, Node, ShapeLabelIdx>;
23
24#[cfg(test)]
25mod tests {
26
27 #[derive(PartialEq, Debug)]
28 enum SE {
29 And { es: Vec<SE> },
30 Not { e: Box<SE> },
31 S { v: String },
32 }
33
34 #[derive(PartialEq, Debug)]
35 enum SE1 {
36 And { es: Vec<SE1> },
37 Not { e: Box<SE1> },
38 S { v: i32 },
39 }
40
41 #[derive(PartialEq, Debug)]
42 enum SErr {
43 Cnv { msg: String },
44 }
45
46 fn cnv(se: &SE) -> Result<SE1, SErr> {
47 match se {
48 SE::And { es } => {
49 let es: Vec<SE1> = es.iter().map(cnv).collect::<Result<Vec<_>, SErr>>()?;
50
51 Ok(SE1::And { es })
52 }
53 SE::Not { e } => {
54 let e = cnv(e)?;
55 Ok(SE1::Not { e: Box::new(e) })
56 }
57 SE::S { v } => match v.parse::<i32>() {
58 Ok(n) => Ok(SE1::S { v: n }),
59 Err(e) => Err(SErr::Cnv {
60 msg: format!("Error converting {v} to i32: {e}"),
61 }),
62 },
63 }
64 }
65
66 #[test]
67 fn test_se_conversion() {
68 let se = SE::And {
69 es: vec![
70 SE::Not {
71 e: Box::new(SE::S {
72 v: "23".to_string(),
73 }),
74 },
75 SE::S {
76 v: "43".to_string(),
77 },
78 ],
79 };
80 let expected = SE1::And {
81 es: vec![
82 SE1::Not {
83 e: Box::new(SE1::S { v: 23 }),
84 },
85 SE1::S { v: 43 },
86 ],
87 };
88 assert_eq!(cnv(&se), Ok(expected))
89 }
90
91 #[test]
92 fn test_se_conversion_err() {
93 let se = SE::And {
94 es: vec![
95 SE::Not {
96 e: Box::new(SE::S {
97 v: "foo".to_string(),
98 }),
99 },
100 SE::S {
101 v: "43".to_string(),
102 },
103 ],
104 };
105 assert!(cnv(&se).is_err())
106 }
107
108 }