pub mod internal;
pub mod node;
pub mod pred;
pub mod ast;
pub use internal::compiled_schema_error::*;
use iri_s::IriS;
pub use ast::*;
pub use node::*;
pub use pred::*;
use rbe::MatchCond;
pub use schema::*;
pub use internal::shape_label::*;
pub use internal::shape_label_idx::*;
pub use internal::value_set::*;
pub use internal::value_set_value::*;
use srdf::Object;
type CResult<T> = Result<T, CompiledSchemaError>;
type Cond = MatchCond<Pred, Node, ShapeLabelIdx>;
#[cfg(test)]
mod tests {
#[derive(PartialEq, Debug)]
enum SE {
And { es: Vec<SE> },
Not { e: Box<SE> },
S { v: String },
}
#[derive(PartialEq, Debug)]
enum SE1 {
And { es: Vec<SE1> },
Not { e: Box<SE1> },
S { v: i32 },
}
#[derive(PartialEq, Debug)]
enum SErr {
Cnv { msg: String },
}
fn cnv(se: &SE) -> Result<SE1, SErr> {
match se {
SE::And { es } => {
let vs: Vec<Result<SE1, SErr>> = es
.iter()
.map(|se| {
let r = cnv(se);
r
})
.collect();
let r: Result<Vec<SE1>, SErr> = vs.into_iter().collect();
let es = r?;
Ok(SE1::And { es: es })
}
SE::Not { e } => {
let e = cnv(e)?;
Ok(SE1::Not { e: Box::new(e) })
}
SE::S { v } => match v.parse::<i32>() {
Ok(n) => Ok(SE1::S { v: n }),
Err(e) => Err(SErr::Cnv {
msg: format!("Error converting {v} to i32: {e}"),
}),
},
}
}
#[test]
fn test_se_conversion() {
let se = SE::And {
es: vec![
SE::Not {
e: Box::new(SE::S {
v: "23".to_string(),
}),
},
SE::S {
v: "43".to_string(),
},
],
};
let expected = SE1::And {
es: vec![
SE1::Not {
e: Box::new(SE1::S { v: 23 }),
},
SE1::S { v: 43 },
],
};
assert_eq!(cnv(&se), Ok(expected))
}
#[test]
fn test_se_conversion_err() {
let se = SE::And {
es: vec![
SE::Not {
e: Box::new(SE::S {
v: "foo".to_string(),
}),
},
SE::S {
v: "43".to_string(),
},
],
};
assert!(cnv(&se).is_err())
}
}