recall dispatch: cited scan without open loops; tie and dotted-slug tests
This commit is contained in:
parent
28412f0da6
commit
9295b4c348
2 changed files with 23 additions and 6 deletions
|
|
@ -198,11 +198,18 @@ fn cited(text: &str) -> Vec<String> {
|
|||
let word = |byte: u8| byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'-';
|
||||
let run = |from: usize| from + bytes[from..].iter().take_while(|byte| word(**byte)).count();
|
||||
let mut ids: Vec<String> = Vec::new();
|
||||
let mut at = 0;
|
||||
while at < bytes.len() {
|
||||
let mut skip = 0;
|
||||
for at in 0..bytes.len() {
|
||||
if at < skip {
|
||||
continue;
|
||||
}
|
||||
let standing = at == 0 || !(word(bytes[at - 1]) || matches!(bytes[at - 1], b'.' | b':'));
|
||||
let mut end = run(at);
|
||||
while standing && end > at && bytes.get(end) == Some(&b'.') && run(end + 1) > end + 1 {
|
||||
// Dotted campaign slugs: each pass takes a dot and the word after it.
|
||||
for _ in 0..bytes.len() {
|
||||
if !(standing && end > at && bytes.get(end) == Some(&b'.') && run(end + 1) > end + 1) {
|
||||
break;
|
||||
}
|
||||
end = run(end + 1);
|
||||
}
|
||||
let kind = ["ruling", "question", "follow_up"].into_iter().find(|kind| {
|
||||
|
|
@ -217,13 +224,11 @@ fn cited(text: &str) -> Vec<String> {
|
|||
if !ids.iter().any(|seen| seen == id) {
|
||||
ids.push(id.to_string());
|
||||
}
|
||||
at = stop;
|
||||
continue;
|
||||
skip = stop;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
at += 1;
|
||||
}
|
||||
ids
|
||||
}
|
||||
|
|
@ -319,6 +324,8 @@ mod tests {
|
|||
assert!(cited(text).is_empty(), "{text}: {:?}", cited(text));
|
||||
}
|
||||
assert_eq!(cited("日t:ruling:a"), ["t:ruling:a"]);
|
||||
assert!(cited(".a:ruling:b").is_empty() && cited("a.:ruling:b").is_empty());
|
||||
assert_eq!(cited("a.b.c:ruling:d t:ruling:e"), ["a.b.c:ruling:d", "t:ruling:e"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -2229,6 +2229,16 @@ fn d10_a_record_near_two_anchors_appears_once_at_its_best_score() {
|
|||
.serve();
|
||||
let ran = dispatch(server.addr, &brief_hook(brief), &[]);
|
||||
assert_eq!(recalled_ids(&ran, brief), ["t:ruling:n2", "t:ruling:n1", "t:ruling:n3"]);
|
||||
// At an equal score the first anchor's record stays.
|
||||
let tied = |title: &str| held("ruling", "t:ruling:n1", title, None);
|
||||
let (server, _) = scene()
|
||||
.anchor("ruling", "a", "Alpha")
|
||||
.anchor("ruling", "b", "Beta")
|
||||
.rank("Alpha", vec![(tied("first"), 0.5)])
|
||||
.rank("Beta", vec![(tied("second"), 0.5)])
|
||||
.serve();
|
||||
let ran = dispatch(server.addr, &brief_hook(brief), &[]);
|
||||
assert_eq!(recalled(&ran, brief), [json!({ "id": "t:ruling:n1", "title": "first" })]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue