mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Add first test for date parser
This commit is contained in:
parent
e92d038750
commit
f678261856
1 changed files with 26 additions and 0 deletions
26
src/date.rs
26
src/date.rs
|
@ -474,3 +474,29 @@ impl Context {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn match_literal(s: &str, expected: &str) -> (Result<(), String>, Parsed) {
|
||||
let mut parsed = Parsed::new();
|
||||
let mut tz = None;
|
||||
let mut date = vec![DateToken::Literal(s.into())].into_iter().peekable();
|
||||
let pat = &[DatePattern::Literal(expected.into())];
|
||||
let res = parse_date(&mut parsed, &mut tz, &mut date, pat);
|
||||
|
||||
(res, parsed)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_literal() {
|
||||
let (res, parsed) = match_literal("abc", "abc");
|
||||
assert_eq!(parsed, Parsed::new());
|
||||
assert!(res.is_ok());
|
||||
|
||||
let (res, parsed) = match_literal("abc", "def");
|
||||
assert_eq!(parsed, Parsed::new());
|
||||
assert_eq!(res, Err("Expected `def`, got `abc`".into()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue