use super::*;
use crate::reads::test_support::task;
use crate::reads::Flags;
fn tagged(title: &str, body: &str, created: i64, tags: &[&str]) -> Task {
let mut t = task(title, created);
t.body = body.into();
t.tags = tags.iter().map(ToString::to_string).collect();
t
}
#[test]
fn an_unfiltered_list_passes_every_ball() {
assert!(matches(&task("Anything", 42), 99, &Flags::default()));
}
#[test]
fn tag_filter_demands_every_requested_tag() {
let t = tagged("T", "", 1, &["infra", "api"]);
let flags = |tags: &[&str]| Flags { tags: tags.iter().map(ToString::to_string).collect(), ..Default::default() };
assert!(matches(&t, 1, &flags(&["infra"])));
assert!(matches(&t, 1, &flags(&["infra", "api"]))); assert!(!matches(&t, 1, &flags(&["infra", "missing"]))); }
#[test]
fn date_window_matches_on_created_or_effective_updated() {
let t = task("Spanning", 100);
let win = |since, until| Flags { since, until, ..Default::default() };
assert!(matches(&t, 500, &win(Some(50), Some(150)))); assert!(matches(&t, 500, &win(Some(400), Some(600)))); assert!(!matches(&t, 500, &win(Some(200), Some(400)))); assert!(matches(&t, 500, &win(Some(50), None))); assert!(matches(&t, 500, &win(None, Some(600)))); }
#[test]
fn text_filter_is_a_case_insensitive_substring_of_title_or_body() {
let t = tagged("Refactor Auth", "fixes the TIMEOUT", 1, &[]);
let q = |needle: &str| Flags { target: Some(needle.into()), ..Default::default() };
assert!(matches(&t, 1, &q("auth"))); assert!(matches(&t, 1, &q("timeout"))); assert!(!matches(&t, 1, &q("database"))); }
#[test]
fn claimant_filter_is_an_exact_match_on_the_stored_field() {
let mut held = task("Held", 1);
held.claimant = Some("alice".into());
let q = |name: &str| Flags { claimant: Some(name.into()), ..Default::default() };
assert!(matches(&held, 1, &q("alice")));
assert!(!matches(&held, 1, &q("alic"))); assert!(!matches(&task("Unheld", 1), 1, &q("alice"))); }
#[test]
fn the_filters_compose_with_and() {
let t = tagged("Build the API", "with rate limiting", 100, &["api"]);
let all = Flags {
tags: vec!["api".into()],
since: Some(50),
until: Some(150),
target: Some("rate".into()),
..Default::default()
};
assert!(matches(&t, 100, &all));
let bad_tag = Flags { tags: vec!["infra".into()], ..all };
assert!(!matches(&t, 100, &bad_tag));
}