diff --git a/rslib/src/scheduler/upgrade.rs b/rslib/src/scheduler/upgrade.rs index 9700d1dac..3f0a39f90 100644 --- a/rslib/src/scheduler/upgrade.rs +++ b/rslib/src/scheduler/upgrade.rs @@ -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); diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 06a748544..bcd8d833c 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -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:{}", 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:{}"), 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] diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 7d79cd3ad..ca1dda423 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -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] diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index e660cc6ab..e0fb4e4e0 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -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] diff --git a/rslib/src/template.rs b/rslib/src/template.rs index c4e03740a..21618e9d9 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -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()) ); } diff --git a/rslib/src/undo/mod.rs b/rslib/src/undo/mod.rs index 31ae2ce8f..a5757b1f6 100644 --- a/rslib/src/undo/mod.rs +++ b/rslib/src/undo/mod.rs @@ -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;