diff options
author | Dan Davison <dandavison7@gmail.com> | 2019-07-19 10:17:02 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2019-07-20 18:09:35 -0400 |
commit | 6563c30a5721197af17ebd2a75fcc2b50f42b9b2 (patch) | |
tree | b8d1e72c8a6cddfddba62d1cb3f1b1d2300e4d6d /src | |
parent | 49f9932f98839ef5341360e94469a2795bb1d620 (diff) |
Parameterize Edits::appears_genuine method
Diffstat (limited to 'src')
-rw-r--r-- | src/edits.rs | 12 | ||||
-rw-r--r-- | src/paint.rs | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/edits.rs b/src/edits.rs index fc38a85c..b183a6e1 100644 --- a/src/edits.rs +++ b/src/edits.rs @@ -39,6 +39,7 @@ pub fn get_diff_style_sections( minus_emph_style_modifier: StyleModifier, plus_style_modifier: StyleModifier, plus_emph_style_modifier: StyleModifier, + similarity_threshold: f64, ) -> ( Vec<Vec<(StyleModifier, String)>>, Vec<Vec<(StyleModifier, String)>>, @@ -81,7 +82,9 @@ pub fn get_diff_style_sections( string_length: plus_length, }; - if minus_edit.appears_genuine() && plus_edit.appears_genuine() { + if minus_edit.appears_genuine(similarity_threshold) + && plus_edit.appears_genuine(similarity_threshold) + { minus_line_sections.push(vec![ (minus_style_modifier, minus[0..change_begin].to_string()), ( @@ -114,8 +117,9 @@ struct Edit { impl Edit { // TODO: exclude leading whitespace in this calculation - fn appears_genuine(&self) -> bool { - ((self.change_end - self.change_begin) as f64 / self.string_length as f64) < 0.66 + fn appears_genuine(&self, similarity_threshold: f64) -> bool { + ((self.change_end - self.change_begin) as f64 / self.string_length as f64) + < similarity_threshold } } @@ -133,6 +137,7 @@ mod tests { MINUS_EMPH, PLUS, PLUS_EMPH, + 1.0, ); let expected_edits = ( vec![as_strings(vec![ @@ -161,6 +166,7 @@ mod tests { MINUS_EMPH, PLUS, PLUS_EMPH, + 1.0, ); let expected_edits = ( vec![as_strings(vec![ diff --git a/src/paint.rs b/src/paint.rs index feb2efa7..68ca79c6 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -128,6 +128,7 @@ impl<'a> Painter<'a> { self.config.minus_emph_style_modifier, self.config.plus_style_modifier, self.config.plus_emph_style_modifier, + 0.66, ) } else { self.get_diff_style_sections_plain() |