mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
add thiserror to edn module; 38.57% total cov
This commit is contained in:
parent
77d617f9a0
commit
3837dbd47b
7 changed files with 66 additions and 36 deletions
|
|
@ -7,6 +7,7 @@ version = "0.1.0"
|
|||
clojure-reader = "0.3.0"
|
||||
konst = { version = "0.3.16", features = [ "rust_1_83" ] }
|
||||
itertools = "0.14.0"
|
||||
thiserror = "2.0"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue