diff --git a/src/memory.rs b/src/memory.rs index cd0056b..54cab7e 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -213,6 +213,8 @@ fn plain_words(t: &str) -> String { /// the trail had the time (0), it is the latest turn started by the same words. `starts`: the /// turns' first lines (store::turn_starts). Ok: (that turn, the words the person typed). pub fn taught_turn(prompt: &str, at: Option, starts: &[crate::oplog::Record]) -> Result<(String, String), String> { + // A message from before times were kept says `at: 0`: that names no turn — go by its words. + let at = at.filter(|t| *t > 0); let key: String = plain_words(prompt).chars().take(40).collect(); let same_words = |p: &crate::oplog::Prompt| plain_words(crate::attach::typed_part(&p.text)).chars().take(40).collect::() == key; let latest = |ok: &dyn Fn(&crate::oplog::Prompt) -> bool| { @@ -1519,6 +1521,10 @@ mod tests { assert_eq!(taught_turn("看這張", None, &starts).map(|t| t.0), Ok("with-file".into()), "by its words too"); assert_eq!(taught_turn("以前的簽到", Some(400), &starts).map(|t| t.0), Ok("old".into()), "a turn from before the time was kept"); assert!(taught_turn("以前的", Some(400), &starts).is_err(), "…by all its words, not a part"); + // A message from before times were kept comes with `at: 0`: found by its words, never as + // whichever untimed turn is newest. + assert_eq!(taught_turn("以前的簽到", Some(0), &starts).map(|t| t.0), Ok("old".into())); + assert!(taught_turn("完全不同的一句話", Some(0), &starts).is_err(), "at 0 names no turn"); } #[test] fn remember_tells_the_same_thing_from_another_fact() {