summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2019-07-17 23:03:04 -0400
committerDan Davison <dandavison7@gmail.com>2019-07-18 00:12:45 -0400
commit62fb930313675f83a010b8a20a4f48cf7a05615b (patch)
tree0b3ea324e222bf4d010265d0f662863a848a7b43 /src
parente9af9c85d5c2633023bb98253f5b8bb36a8f041b (diff)
Clean up: move tests, change variable name
Diffstat (limited to 'src')
-rw-r--r--src/delta.rs95
-rw-r--r--src/main.rs101
-rw-r--r--src/paint.rs6
3 files changed, 101 insertions, 101 deletions
diff --git a/src/delta.rs b/src/delta.rs
index dc3ac461..4f3552e7 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -253,3 +253,98 @@ fn prepare(_line: &str, config: &Config) -> String {
_ => format!("{}\n", line),
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use console::strip_ansi_codes;
+ use structopt::StructOpt;
+
+ #[test]
+ fn test_added_file() {
+ let input = "\
+commit d28dc1ac57e53432567ec5bf19ad49ff90f0f7a5
+Author: Dan Davison <dandavison7@gmail.com>
+Date: Thu Jul 11 10:41:11 2019 -0400
+
+ .
+
+diff --git a/a.py b/a.py
+new file mode 100644
+index 0000000..8c55b7d
+--- /dev/null
++++ b/a.py
+@@ -0,0 +1,3 @@
++# hello
++class X:
++ pass";
+
+ let expected_output = "\
+commit d28dc1ac57e53432567ec5bf19ad49ff90f0f7a5
+Author: Dan Davison <dandavison7@gmail.com>
+Date: Thu Jul 11 10:41:11 2019 -0400
+
+ .
+
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+added: a.py
+━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+────────────────────────────────────────────────────────────────────────────────
+
+────────────────────────────────────────────────────────────────────────────────
+ # hello
+ class X:
+ pass
+";
+
+ let mut opt = cli::Opt::from_args();
+ opt.width = Some("variable".to_string());
+ let assets = HighlightingAssets::new();
+ let config = cli::process_command_line_arguments(&assets, &opt);
+ let mut writer: Vec<u8> = Vec::new();
+ delta(
+ input.split("\n").map(String::from),
+ &config,
+ &assets,
+ &mut writer,
+ )
+ .unwrap();
+ let output = strip_ansi_codes(&String::from_utf8(writer).unwrap()).to_string();
+ assert!(output.contains("\nadded: a.py\n"));
+ if false {
+ // TODO: hline width
+ assert_eq!(output, expected_output);
+ }
+ }
+
+ #[test]
+ fn test_renamed_file() {
+ let input = "\
+commit 1281650789680f1009dfff2497d5ccfbe7b96526
+Author: Dan Davison <dandavison7@gmail.com>
+Date: Wed Jul 17 20:40:23 2019 -0400
+
+ rename
+
+diff --git a/a.py b/b.py
+similarity index 100%
+rename from a.py
+rename to b.py
+";
+
+ let mut opt = cli::Opt::from_args();
+ opt.width = Some("variable".to_string());
+ let assets = HighlightingAssets::new();
+ let config = cli::process_command_line_arguments(&assets, &opt);
+ let mut writer: Vec<u8> = Vec::new();
+ delta(
+ input.split("\n").map(String::from),
+ &config,
+ &assets,
+ &mut writer,
+ )
+ .unwrap();
+ let output = strip_ansi_codes(&String::from_utf8(writer).unwrap()).to_string();
+ assert!(output.contains("\nrenamed: a.py ⟶ b.py\n"));
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 7a29808b..acf4e7bd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -48,15 +48,15 @@ fn main() -> std::io::Result<()> {
process::exit(0);
}
- let paint_config = cli::process_command_line_arguments(&assets, &opt);
+ let config = cli::process_command_line_arguments(&assets, &opt);
let mut output_type =
- OutputType::from_mode(PagingMode::QuitIfOneScreen, Some(paint_config.pager)).unwrap();
+ OutputType::from_mode(PagingMode::QuitIfOneScreen, Some(config.pager)).unwrap();
let mut writer = output_type.handle().unwrap();
match delta(
io::stdin().lock().lines().map(|l| l.unwrap()),
- &paint_config,
+ &config,
&assets,
&mut writer,
) {
@@ -138,98 +138,3 @@ pub fn list_themes() -> std::io::Result<()> {
}
Ok(())
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- use console::strip_ansi_codes;
-
- #[test]
- fn test_added_file() {
- let input = "\
-commit d28dc1ac57e53432567ec5bf19ad49ff90f0f7a5
-Author: Dan Davison <dandavison7@gmail.com>
-Date: Thu Jul 11 10:41:11 2019 -0400
-
- .
-
-diff --git a/a.py b/a.py
-new file mode 100644
-index 0000000..8c55b7d
---- /dev/null
-+++ b/a.py
-@@ -0,0 +1,3 @@
-+# hello
-+class X:
-+ pass";
-
- let expected_output = "\
-commit d28dc1ac57e53432567ec5bf19ad49ff90f0f7a5
-Author: Dan Davison <dandavison7@gmail.com>
-Date: Thu Jul 11 10:41:11 2019 -0400
-
- .
-
-━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-added: a.py
-━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-────────────────────────────────────────────────────────────────────────────────
-
-────────────────────────────────────────────────────────────────────────────────
- # hello
- class X:
- pass
-";
-
- let mut opt = cli::Opt::from_args();
- opt.width = Some("variable".to_string());
- let assets = HighlightingAssets::new();
- let paint_config = cli::process_command_line_arguments(&assets, &opt);
- let mut writer: Vec<u8> = Vec::new();
- delta(
- input.split("\n").map(String::from),
- &paint_config,
- &assets,
- &mut writer,
- )
- .unwrap();
- let output = strip_ansi_codes(&String::from_utf8(writer).unwrap()).to_string();
- assert!(output.contains("\nadded: a.py\n"));
- if false {
- // TODO: hline width
- assert_eq!(output, expected_output);
- }
- }
-
- #[test]
- fn test_renamed_file() {
- let input = "\
-commit 1281650789680f1009dfff2497d5ccfbe7b96526
-Author: Dan Davison <dandavison7@gmail.com>
-Date: Wed Jul 17 20:40:23 2019 -0400
-
- rename
-
-diff --git a/a.py b/b.py
-similarity index 100%
-rename from a.py
-rename to b.py
-";
-
- let mut opt = cli::Opt::from_args();
- opt.width = Some("variable".to_string());
- let assets = HighlightingAssets::new();
- let paint_config = cli::process_command_line_arguments(&assets, &opt);
- let mut writer: Vec<u8> = Vec::new();
- delta(
- input.split("\n").map(String::from),
- &paint_config,
- &assets,
- &mut writer,
- )
- .unwrap();
- let output = strip_ansi_codes(&String::from_utf8(writer).unwrap()).to_string();
- assert!(output.contains("\nrenamed: a.py ⟶ b.py\n"));
- }
-}
diff --git a/src/paint.rs b/src/paint.rs
index 249ed98f..8fc4c011 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -59,7 +59,7 @@ impl<'a> Painter<'a> {
syntax_style_sections.iter().zip(diff_style_sections)
{
for (style, text) in superimpose_style_sections(syntax_sections, diff_sections) {
- paint_section(&text, style, output_buffer).unwrap();
+ paint_text(&text, style, output_buffer).unwrap();
}
}
}
@@ -152,8 +152,8 @@ impl<'a> Painter<'a> {
}
}
-/// Write section text to buffer with color escape codes.
-fn paint_section(text: &str, style: Style, output_buffer: &mut String) -> std::fmt::Result {
+/// Write text to buffer with color escape codes.
+fn paint_text(text: &str, style: Style, output_buffer: &mut String) -> std::fmt::Result {
use std::fmt::Write;
match style.background {
style::NO_COLOR => (),