Skip to content

Commit

Permalink
docs/polish ~ improve (including removal of unneeded) comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Feb 14, 2020
1 parent 3def56b commit 1c43e82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 65 deletions.
44 changes: 1 addition & 43 deletions src/comparison.rs
Expand Up @@ -80,10 +80,9 @@ pub fn format_changeset(
)
)?;
for i in 0..diffs.len() {
// note: Difference::Changeset batches differences of the same type (Same, Add, or Rem) together within `diffs`, requiring splitting for processing
match diffs[i] {
Difference::Same(ref same) => {
// Have to split line by line in order to have the extra whitespace
// at the beginning.
for line in same.split('\n') {
writeln!(
f,
Expand All @@ -101,33 +100,6 @@ pub fn format_changeset(
//
// Let's highlight the character-differences in this replaced
// chunk. Note that this chunk can span over multiple lines.
// let mut removed_lines = removed.split('\n');
// let removed_line = removed_lines.next_back().unwrap();
// let mut added_lines = added.split('\n');
// let added_line = added_lines.next().unwrap();

// for line in removed_lines {
// paint!(
// f,
// config.style_left,
// "{}{}\n",
// config.prefix_left,
// line
// )?;
// }

// format_replacement(f, added_line, removed_line, &config)?;

// for line in added_lines {
// paint!(
// f,
// config.style_right,
// "{}{}\n",
// config.prefix_right,
// line
// )?;
// }

format_replacement(f, added, removed, &config)?;
}
_ => {
Expand Down Expand Up @@ -190,24 +162,11 @@ pub fn format_replacement(
let added_line = added_lines.next().unwrap();

let Changeset { diffs, .. } = Changeset::new(removed_line, added_line, "");
// let Changeset { diffs, distance, .. } = Changeset::new(removed_line, added_line, "");
// let max_edit_distance = std::cmp::max(removed_line.trim_start().len(), added_line.trim_start().len()) / 2; // ignoring leading whitespace since lines are debug pretty-printed
// let max_edit_distance = 0; // ignoring leading whitespace since lines are debug pretty-printed

// eprintln!("removed_line={}", removed_line);
// eprintln!("added_line={}", added_line);

// eprintln!("max_edit_distance={}", max_edit_distance);
// eprintln!("edit_distance={}", distance);

for line in removed_lines {
paint!(f, config.style_left, "{}{}\n", config.prefix_left, line)?;
}

// if distance > max_edit_distance.try_into().unwrap() {
// writeln!(f, "{}{}", painted!(config.style_left, config.prefix_left), painted!(config.style_left, removed_line))?;
// writeln!(f, "{}{}", painted!(config.style_right, config.prefix_right), painted!(config.style_right, added_line))?;
// } else {
// LEFT side (==what's been)
paint!(f, config.style_left, "{}", config.prefix_left)?;
for c in &diffs {
Expand Down Expand Up @@ -256,7 +215,6 @@ pub fn format_replacement(
}
}
writeln!(f, "{}", painted!(config.style, ""))?;
// }

for line in added_lines {
paint!(f, config.style_right, "{}{}\n", config.prefix_right, line)?;
Expand Down
29 changes: 8 additions & 21 deletions src/config.rs
Expand Up @@ -7,28 +7,21 @@ pub struct AssertConfig {
pub default_left_label: &'static str, // default label for "left"
pub default_right_label: &'static str, // default label for "right"

// pub left_color: u8, // baseline foreground color of text displayed "left" changes
// pub left_color_diff_fg: u8, // foreground color for baseline "left" text
// pub left_color_diff_bg: u8, // background color for any "left" differences

// pub right_color: u8, // foreground color for baseline "right" text
// pub right_color_diff_fg: u8, // foreground color for any "right" differences
// pub right_color_diff_bg: u8, // background color for any "right" differences
pub prefix: &'static str, // prefix for lines which don't differ between the assert arguments
pub prefix_left: &'static str, // prefix text for left/first (aka prior) argument differences
pub prefix_right: &'static str, // prefix text for right/second (aka after) argument differences

pub style: Style,
pub style_left: Style,
pub style_right: Style,
pub style_left_diff: Style,
pub style_right_diff: Style,
pub style: Style, // style for baseline assertion output
pub style_left: Style, // style for left/first (aka prior) argument (line-by-line) differences
pub style_right: Style, // style for right/second (aka after) argument (line-by-line) differences
pub style_left_diff: Style, // style for left/first (aka prior) argument intra-line differences
pub style_right_diff: Style, // style for right/second (aka after) argument intra-line differences

// private use; but must be pub accessible for use in macros
// "private"; but must be pub accessible for use in exported macros
#[doc(hidden)]
pub _maybe_left_label: Option<&'static str>, // left label, if available
pub _maybe_left_label: Option<&'static str>, // left/first (aka prior) label, if available
#[doc(hidden)]
pub _maybe_right_label: Option<&'static str>, // right label, if available
pub _maybe_right_label: Option<&'static str>, // right/second (aka after) label, if available
}

const PREFIX: &str = " ";
Expand All @@ -49,12 +42,6 @@ impl Default for AssertConfig {
auto_label: std::cfg!(feature = "labels"),
default_left_label: "left",
default_right_label: "right",
// left_color: 1, // (dark) red
// left_color_diff_fg: 9, // bright red
// left_color_diff_bg: 52,
// right_color: 2, // (dark) green
// right_color_diff_fg: 10, // bright green
// right_color_diff_bg: 22,
//
prefix: PREFIX,
prefix_left: PREFIX_LEFT,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -77,7 +77,7 @@ mod comparison;
mod config;

pub use crate::config::AssertConfig;
pub use ansi_term::{Color, Colour, Style};
pub use ansi_term::{Color, Colour, Style}; // re-exported for easier/direct usage when customizing AssertConfig

pub use crate::comparison::Comparison; // private use; but required to be public for use in exported macros

Expand Down

0 comments on commit 1c43e82

Please sign in to comment.