fix some clippy lints in tests

This commit is contained in:
Damien Elmes 2021-03-27 20:44:31 +10:00
parent 1055acb9f2
commit 561d160590
6 changed files with 101 additions and 63 deletions

View File

@ -155,11 +155,12 @@ mod test {
#[test]
fn v2_card() {
let mut c = Card::default();
let mut c = Card {
ctype: CardType::Review,
queue: CardQueue::DayLearn,
..Default::default()
};
// relearning cards should be reclassified
c.ctype = CardType::Review;
c.queue = CardQueue::DayLearn;
c.upgrade_to_v2(None);
assert_eq!(c.ctype, CardType::Relearn);

View File

@ -857,7 +857,7 @@ mod test {
}
#[test]
fn errors() -> Result<()> {
fn errors() {
use crate::err::AnkiError;
use FailKind::*;
@ -939,28 +939,53 @@ mod test {
assert_err_kind("flag:1.1", InvalidFlag);
for term in &["added", "edited", "rated", "resched"] {
assert!(
matches!(failkind(&format!("{}:1.1", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(
matches!(failkind(&format!("{}:-1", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(
matches!(failkind(&format!("{}:", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(
matches!(failkind(&format!("{}:foo", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(matches!(
failkind(&format!("{}:1.1", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
assert!(matches!(
failkind(&format!("{}:-1", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
assert!(matches!(
failkind(&format!("{}:", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
assert!(matches!(
failkind(&format!("{}:foo", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
}
assert!(matches!(failkind("rated:1:"), SearchErrorKind::InvalidAnswerButton { .. }));
assert!(matches!(failkind("rated:2:-1"), SearchErrorKind::InvalidAnswerButton { .. }));
assert!(matches!(failkind("rated:3:1.1"), SearchErrorKind::InvalidAnswerButton { .. }));
assert!(matches!(failkind("rated:0:foo"), SearchErrorKind::InvalidAnswerButton { .. }));
assert!(matches!(
failkind("rated:1:"),
SearchErrorKind::InvalidAnswerButton { .. }
));
assert!(matches!(
failkind("rated:2:-1"),
SearchErrorKind::InvalidAnswerButton { .. }
));
assert!(matches!(
failkind("rated:3:1.1"),
SearchErrorKind::InvalidAnswerButton { .. }
));
assert!(matches!(
failkind("rated:0:foo"),
SearchErrorKind::InvalidAnswerButton { .. }
));
assert!(matches!(failkind("dupe:"), SearchErrorKind::InvalidWholeNumber { .. }));
assert!(matches!(failkind("dupe:1.1"), SearchErrorKind::InvalidWholeNumber { .. }));
assert!(matches!(failkind("dupe:foo"), SearchErrorKind::InvalidWholeNumber { .. }));
assert!(matches!(
failkind("dupe:"),
SearchErrorKind::InvalidWholeNumber { .. }
));
assert!(matches!(
failkind("dupe:1.1"),
SearchErrorKind::InvalidWholeNumber { .. }
));
assert!(matches!(
failkind("dupe:foo"),
SearchErrorKind::InvalidWholeNumber { .. }
));
assert_err_kind("prop:", InvalidPropProperty("".into()));
assert_err_kind("prop:=1", InvalidPropProperty("=1".into()));
@ -973,32 +998,49 @@ mod test {
// unsigned
for term in &["ivl", "reps", "lapses", "pos"] {
assert!(
matches!(failkind(&format!("prop:{}>", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(
matches!(failkind(&format!("prop:{}=0.5", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(
matches!(failkind(&format!("prop:{}!=-1", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(
matches!(failkind(&format!("prop:{}<foo", term)), SearchErrorKind::InvalidPositiveWholeNumber { .. })
);
assert!(matches!(
failkind(&format!("prop:{}>", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
assert!(matches!(
failkind(&format!("prop:{}=0.5", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
assert!(matches!(
failkind(&format!("prop:{}!=-1", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
assert!(matches!(
failkind(&format!("prop:{}<foo", term)),
SearchErrorKind::InvalidPositiveWholeNumber { .. }
));
}
// signed
assert!(matches!(failkind("prop:due>"), SearchErrorKind::InvalidWholeNumber { .. }));
assert!(matches!(failkind("prop:due=0.5"), SearchErrorKind::InvalidWholeNumber { .. }));
assert!(matches!(
failkind("prop:due>"),
SearchErrorKind::InvalidWholeNumber { .. }
));
assert!(matches!(
failkind("prop:due=0.5"),
SearchErrorKind::InvalidWholeNumber { .. }
));
// float
assert!(matches!(failkind("prop:ease>"), SearchErrorKind::InvalidNumber { .. }));
assert!(matches!(failkind("prop:ease!=one"), SearchErrorKind::InvalidNumber { .. }));
assert!(matches!(failkind("prop:ease<1,3"), SearchErrorKind::InvalidNumber { .. }));
Ok(())
assert!(matches!(
failkind("prop:ease>"),
SearchErrorKind::InvalidNumber { .. }
));
assert!(matches!(
failkind("prop:ease!=one"),
SearchErrorKind::InvalidNumber { .. }
));
assert!(matches!(
failkind("prop:ease<1,3"),
SearchErrorKind::InvalidNumber { .. }
));
}
#[test]

View File

@ -599,7 +599,7 @@ mod test {
}
#[test]
fn sql() -> Result<()> {
fn sql() {
// re-use the mediacheck .anki2 file for now
use crate::media::check::test::MEDIACHECK_ANKI2;
let dir = tempdir().unwrap();
@ -804,8 +804,6 @@ mod test {
s(ctx, r"w:*fo_o*"),
("(n.flds regexp ?)".into(), vec![r"(?i)\b.*fo.o.*\b".into()])
);
Ok(())
}
#[test]

View File

@ -191,7 +191,7 @@ mod test {
use crate::search::parse_search as parse;
#[test]
fn normalizing() -> Result<()> {
fn normalizing() {
assert_eq!(r#""(" AND "-""#, normalize_search(r"\( \-").unwrap());
assert_eq!(r#""deck::""#, normalize_search(r"deck:\:").unwrap());
assert_eq!(r#""\*" OR "\:""#, normalize_search(r"\* or \:").unwrap());
@ -203,12 +203,10 @@ mod test {
r#""prop:ease>1""#,
normalize_search("prop:ease>1.0").unwrap()
);
Ok(())
}
#[test]
fn concatenating() -> Result<()> {
fn concatenating() {
assert_eq!(
concatenate_searches(
BoolSeparator::And,
@ -241,8 +239,6 @@ mod test {
),
r#""bar""#,
);
Ok(())
}
#[test]

View File

@ -798,8 +798,7 @@ mod test {
i18n::I18n,
template::{field_is_empty, nonempty_fields, FieldRequirements, RenderContext},
};
use std::collections::{HashMap, HashSet};
use std::iter::FromIterator;
use std::collections::HashMap;
#[test]
fn field_empty() {
@ -873,7 +872,7 @@ mod test {
#[test]
fn nonempty() {
let fields = HashSet::from_iter(vec!["1", "3"].into_iter());
let fields = vec!["1", "3"].into_iter().collect();
let mut tmpl = PT::from_text("{{2}}{{1}}").unwrap();
assert_eq!(tmpl.renders_with_fields(&fields), true);
tmpl = PT::from_text("{{2}}").unwrap();
@ -899,13 +898,13 @@ mod test {
let mut tmpl = PT::from_text("{{a}}{{b}}").unwrap();
assert_eq!(
tmpl.requirements(&field_map),
FieldRequirements::Any(HashSet::from_iter(vec![0, 1].into_iter()))
FieldRequirements::Any(vec![0, 1].into_iter().collect())
);
tmpl = PT::from_text("{{#a}}{{b}}{{/a}}").unwrap();
assert_eq!(
tmpl.requirements(&field_map),
FieldRequirements::All(HashSet::from_iter(vec![0, 1].into_iter()))
FieldRequirements::All(vec![0, 1].into_iter().collect())
);
tmpl = PT::from_text("{{z}}").unwrap();
@ -914,19 +913,19 @@ mod test {
tmpl = PT::from_text("{{^a}}{{b}}{{/a}}").unwrap();
assert_eq!(
tmpl.requirements(&field_map),
FieldRequirements::Any(HashSet::from_iter(vec![1].into_iter()))
FieldRequirements::Any(vec![1].into_iter().collect())
);
tmpl = PT::from_text("{{^a}}{{#b}}{{c}}{{/b}}{{/a}}").unwrap();
assert_eq!(
tmpl.requirements(&field_map),
FieldRequirements::All(HashSet::from_iter(vec![1, 2].into_iter()))
FieldRequirements::All(vec![1, 2].into_iter().collect())
);
tmpl = PT::from_text("{{#a}}{{#b}}{{a}}{{/b}}{{/a}}").unwrap();
assert_eq!(
tmpl.requirements(&field_map),
FieldRequirements::All(HashSet::from_iter(vec![0, 1].into_iter()))
FieldRequirements::All(vec![0, 1].into_iter().collect())
);
tmpl = PT::from_text(
@ -945,7 +944,7 @@ mod test {
assert_eq!(
tmpl.requirements(&field_map),
FieldRequirements::Any(HashSet::from_iter(vec![0, 1].into_iter()))
FieldRequirements::Any(vec![0, 1].into_iter().collect())
);
}

View File

@ -242,8 +242,10 @@ mod test {
fn undo() {
let mut col = open_test_collection();
let mut card = Card::default();
card.interval = 1;
let mut card = Card {
interval: 1,
..Default::default()
};
col.add_card(&mut card).unwrap();
let cid = card.id;