68 lines · 2.5 KB · RustRaw
use super::*;use crate::transforms::zoned_clock::day_number;/// Thursday 22 October 2026.fn thursday() -> i64 { day_number(2026, 10, 22)}#[test]fn the_row_runs_today_tomorrow_a_week_of_days_two_weeks_two_months_then_pick() { let said = said_choices(thursday(), &[]); let labels: Vec<&str> = said.iter().map(|choice| choice.label.as_str()).collect(); assert_eq!( labels, [ "Today", "Tomorrow", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Next week", "In 2 weeks", "November", "December", "Pick a date" ] ); let days: Vec<Option<&str>> = said.iter().map(|choice| choice.day.as_deref()).collect(); assert_eq!(days[0], Some("2026-10-22")); assert_eq!(days[1], Some("2026-10-23")); assert_eq!(days[2], Some("2026-10-24")); assert_eq!(days[8], Some("2026-10-30")); assert_eq!(days[9], Some("2026-10-26"), "next week is the Monday after tomorrow"); assert_eq!(days[10], Some("2026-11-05")); assert_eq!(days[11], Some("2026-11-01")); assert_eq!(days[12], Some("2026-12-01")); assert_eq!(days[13], None); assert_eq!(said[0].detail.as_deref(), Some("Thu 22 Oct")); assert_eq!(said[2].detail.as_deref(), Some("24 Oct")); assert_eq!(said[9].detail, None);}#[test]fn the_months_cross_the_year_and_say_the_year_when_it_is_not_this_one() { let said = said_choices(day_number(2026, 11, 30), &[]); let months: Vec<(&str, &str)> = said .iter() .filter(|choice| choice.kind == "month") .map(|choice| (choice.label.as_str(), choice.day.as_deref().unwrap())) .collect(); assert_eq!(months, [("December", "2026-12-01"), ("January 2027", "2027-01-01")]);}#[test]fn next_week_on_a_sunday_is_the_monday_a_week_after_tomorrow() { // Sunday 25 Oct: tomorrow is Monday 26, so next week is Monday 2 Nov. let choices = date_choices(day_number(2026, 10, 25)); let next = choices.iter().find_map(|choice| match choice { DateChoice::NextWeek { day } => Some(*day), _ => None, }); assert_eq!(next, Some(day_number(2026, 11, 2)));}#[test]fn a_database_row_rewords_a_choice() { let rows = [LineRow { set: "editing".into(), line: "when.pick".into(), words: "Another day".into() }]; let said = said_choices(thursday(), &rows); assert_eq!(said.last().unwrap().label, "Another day");}#[test]fn keys_stay_the_same_from_day_to_day() { let keys = |today| said_choices(today, &[]).into_iter().map(|choice| choice.key).collect::<Vec<_>>(); assert_eq!(keys(thursday()), keys(thursday() + 3));}