Ensure that context::novel_lines handles NovelLinePart

Fixes #129
html_output
Wilfred Hughes 2022-02-07 21:11:58 +07:00
parent ab8e8e4485
commit ecb9e90d0a
1 changed files with 62 additions and 2 deletions

@ -37,10 +37,12 @@ fn novel_lines(mps: &[MatchedPos]) -> Vec<LineNumber> {
let mut lines = HashSet::new();
for mp in mps {
match mp.kind {
MatchKind::Novel { .. } | MatchKind::NovelWord { .. } => {
MatchKind::Novel { .. }
| MatchKind::NovelWord { .. }
| MatchKind::NovelLinePart { .. } => {
lines.insert(mp.pos.line);
}
MatchKind::UnchangedToken { .. } | MatchKind::NovelLinePart { .. } => {}
MatchKind::UnchangedToken { .. } => {}
}
}
@ -455,6 +457,64 @@ mod tests {
);
}
#[test]
fn test_novel_lines() {
let mps = [
MatchedPos {
kind: MatchKind::NovelLinePart {
highlight: TokenKind::Delimiter,
self_pos: SingleLineSpan {
line: 0.into(),
start_col: 2,
end_col: 3,
},
opposite_pos: vec![SingleLineSpan {
line: 0.into(),
start_col: 2,
end_col: 3,
}],
},
pos: SingleLineSpan {
line: 0.into(),
start_col: 2,
end_col: 3,
},
},
MatchedPos {
kind: MatchKind::UnchangedToken {
highlight: TokenKind::Delimiter,
self_pos: vec![SingleLineSpan {
line: 1.into(),
start_col: 2,
end_col: 3,
}],
opposite_pos: vec![SingleLineSpan {
line: 1.into(),
start_col: 2,
end_col: 3,
}],
},
pos: SingleLineSpan {
line: 1.into(),
start_col: 2,
end_col: 3,
},
},
MatchedPos {
kind: MatchKind::Novel {
highlight: TokenKind::Delimiter,
},
pos: SingleLineSpan {
line: 2.into(),
start_col: 1,
end_col: 2,
},
},
];
assert_eq!(novel_lines(&mps), vec![0.into(), 2.into()]);
}
#[test]
fn test_merge_in_opposite_lines() {
let matched_lines = [(Some(1.into()), Some(1.into()))];