add thiserror to edn module; 38.57% total cov

This commit is contained in:
🪞👃🪞 2025-02-26 15:09:44 +02:00
parent 77d617f9a0
commit 3837dbd47b
7 changed files with 66 additions and 36 deletions

View file

@ -115,3 +115,16 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
}
};
}
#[cfg(test)] #[test] fn test_edn_context () {
struct Test;
provide_bool!(bool: |self: Test|{
":provide-bool" => true
});
let test = Test;
assert_eq!(test.get(&Value::Sym(":false")), Some(false));
assert_eq!(test.get(&Value::Sym(":true")), Some(true));
assert_eq!(test.get(&Value::Sym(":provide-bool")), Some(true));
assert_eq!(test.get(&Value::Sym(":missing-bool")), None);
assert_eq!(test.get(&Value::Num(0)), Some(false));
assert_eq!(test.get(&Value::Num(1)), Some(true));
}

View file

@ -1,21 +1,15 @@
use crate::*;
use thiserror::Error;
pub type ParseResult<T> = Result<T, ParseError>;
#[derive(Debug, Copy, Clone, PartialEq)] pub enum ParseError {
#[derive(Error, Debug, Copy, Clone, PartialEq)] pub enum ParseError {
#[error("parse failed: not implemented")]
Unimplemented,
#[error("parse failed: empty")]
Empty,
#[error("parse failed: incomplete")]
Incomplete,
#[error("parse failed: unexpected character '{0}'")]
Unexpected(char),
#[error("parse failed: error #{0}")]
Code(u8),
}
impl Error for ParseError {}
impl Display for ParseError {
fn fmt (&self, f: &mut Formatter) -> FormatResult {
match self {
Unimplemented => write!(f, "unimplemented"),
Empty => write!(f, "empty"),
Incomplete => write!(f, "incomplete"),
Unexpected(c) => write!(f, "unexpected '{c}'"),
Code(i) => write!(f, "error #{i}"),
}
}
}