mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 05:34:14 +00:00
Simplify tests in date.rs
This commit is contained in:
parent
4437500941
commit
00dcdd4f52
1 changed files with 10 additions and 9 deletions
19
src/date.rs
19
src/date.rs
|
@ -479,10 +479,15 @@ impl Context {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn parse(date: Vec<DateToken>, pat: &[DatePattern]) -> (Result<(), String>, Parsed) {
|
||||
fn pattern(s: &str) -> Vec<DatePattern> {
|
||||
parse_datepattern(&mut s.chars().peekable()).unwrap()
|
||||
}
|
||||
|
||||
fn parse(date: Vec<DateToken>, pat: &str) -> (Result<(), String>, Parsed) {
|
||||
let mut parsed = Parsed::new();
|
||||
let mut tz = None;
|
||||
let res = parse_date(&mut parsed, &mut tz, &mut date.into_iter().peekable(), pat);
|
||||
let pat = pattern(pat);
|
||||
let res = parse_date(&mut parsed, &mut tz, &mut date.into_iter().peekable(), &pat);
|
||||
|
||||
(res, parsed)
|
||||
}
|
||||
|
@ -490,13 +495,11 @@ mod tests {
|
|||
#[test]
|
||||
fn test_literal() {
|
||||
let date = vec![DateToken::Literal("abc".into())];
|
||||
let pat = &[DatePattern::Literal("abc".into())];
|
||||
let (res, parsed) = parse(date.clone(), pat);
|
||||
let (res, parsed) = parse(date.clone(), "'abc'");
|
||||
assert_eq!(parsed, Parsed::new());
|
||||
assert!(res.is_ok());
|
||||
|
||||
let pat = &[DatePattern::Literal("def".into())];
|
||||
let (res, parsed) = parse(date, pat);
|
||||
let (res, parsed) = parse(date, "'def'");
|
||||
assert_eq!(parsed, Parsed::new());
|
||||
assert_eq!(res, Err("Expected `def`, got `abc`".into()));
|
||||
}
|
||||
|
@ -510,9 +513,7 @@ mod tests {
|
|||
DateToken::Plus,
|
||||
DateToken::Number(format!("{}", expected.year.unwrap()), None),
|
||||
];
|
||||
let pat = &[DatePattern::Match("year".into())];
|
||||
let (res, parsed) = parse(date.clone(), pat);
|
||||
|
||||
let (res, parsed) = parse(date.clone(), "year");
|
||||
assert_eq!(parsed, expected);
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue