From 03f51738a656b8db55d299efcc104b2b20f16055 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Jul 2020 23:33:45 +0200 Subject: Suggestion: Remove unused `patch` method The newer `Suggestion.diff()` method fulfills the same need. --- src/suggestion.rs | 65 ------------------------------------------------------- 1 file changed, 65 deletions(-) (limited to 'src') diff --git a/src/suggestion.rs b/src/suggestion.rs index 68a2430..531f4b1 100644 --- a/src/suggestion.rs +++ b/src/suggestion.rs @@ -37,28 +37,6 @@ pub struct Suggestion { } impl Suggestion { - // TODO: Rename to `diff` - pub fn patch(&self) -> String { - let mut diff: Vec<_> = self.diff.lines() - .filter(|l| !l.starts_with("-")) - .map(|l| { - if l.starts_with("+") { - return l.replacen("+", " ", 1); - } - - l.to_owned() - }) - .collect(); - - let last = diff.len() - 1; - diff[last] = diff.last().unwrap() - .replacen(" ", "-", 1); - - diff.push(self.suggestion_patch()); - - diff.join("\n") - } - pub fn diff(&self) -> String { let repo = Repository::open(".").unwrap(); @@ -192,49 +170,6 @@ fn is_line_crlf(line: &str) -> bool { mod tests { use super::*; - #[test] - fn suggestion_patch_generates_patch() { - // Diff from gabgodBB (https://github.com/gabgodBB) and suggestion from - // probablycorey (https://github.com/probablycorey) in this pull - // request: https://github.com/cli/cli/pull/1123 - - let suggestion = Suggestion { - diff: r#"@@ -1, 9 +1, 11 @@ - package command - - import ( -+ "bufio" // used to input comment - "errors" - "fmt" - "io" -+ "os" // used to input comment"#.to_owned(), - comment: r#"It's ok to leave these uncommented - -```suggestion - "os" -```"#.to_owned(), - commit: "".to_owned(), - path: "".to_owned(), - original_start_line: Some(8), - original_end_line: 8, - }; - - assert_eq!( - suggestion.patch(), - r#"@@ -1, 9 +1, 11 @@ - package command - - import ( - "bufio" // used to input comment - "errors" - "fmt" - "io" -- "os" // used to input comment -+ "os" -"#, - ); - } - #[test] fn unified_diff() { use unidiff::PatchSet; -- cgit v1.2.3