From 481434a271553ce5fea32bb1efe442a46611776b Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Fri, 6 Oct 2023 14:10:37 +0900 Subject: [PATCH] fix: set link for first uncovered line A link tag existed that should move to the first uncovered line in source view, but it never contained a proper working URL. Also, the link won't be generated anymore if there aren't any uncovered lines in the file. --- src/templates.rs | 5 +++++ templates/source.html | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/templates.rs b/src/templates.rs index 6175906..43bc7cd 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -68,6 +68,11 @@ pub struct Source<'a> { } impl<'a> Source<'a> { + fn get_first(&self) -> Option { + (1..=self.lines.len()) + .find(|line| matches!(self.get_coverage(line), Coverage::Uncovered(_))) + } + fn get_coverage(&self, index: &usize) -> Coverage { self.info .covered diff --git a/templates/source.html b/templates/source.html index ff43439..68122d2 100644 --- a/templates/source.html +++ b/templates/source.html @@ -36,7 +36,11 @@ Line Count - Source (jump to first uncovered line) + Source + {%- if let Some(line) = self.get_first() %} + (jump to first uncovered line) + {% endif -%} +