From ecb9e90d0ad3a38e58f8ed35d283d01af570035f Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Mon, 7 Feb 2022 21:11:58 -0800 Subject: [PATCH] Ensure that context::novel_lines handles NovelLinePart Fixes #129 --- src/context.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index e3e7de759..7e3dd6b2e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -37,10 +37,12 @@ fn novel_lines(mps: &[MatchedPos]) -> Vec { 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()))];