From aa4000cb0de7db2ad5fcf642e53627c4f53d46f9 Mon Sep 17 00:00:00 2001 From: Tom Milligan Date: Tue, 6 Oct 2020 16:57:47 +0100 Subject: [PATCH] style: add component 'rule' for horizontal file delimiter --- src/bin/bat/clap_app.rs | 5 ++-- src/pretty_printer.rs | 10 +++++++ src/printer.rs | 24 ++++++++++++----- src/style.rs | 7 +++++ tests/integration_tests.rs | 12 +++++++++ tests/snapshot_tests.rs | 10 +++++++ tests/snapshots/generate_snapshots.py | 2 +- ...nges_grid_header_numbers_rule.snapshot.txt | 26 +++++++++++++++++++ .../changes_grid_header_rule.snapshot.txt | 26 +++++++++++++++++++ .../changes_grid_numbers_rule.snapshot.txt | 24 +++++++++++++++++ .../output/changes_grid_rule.snapshot.txt | 24 +++++++++++++++++ .../changes_header_numbers_rule.snapshot.txt | 23 ++++++++++++++++ .../output/changes_header_rule.snapshot.txt | 23 ++++++++++++++++ .../output/changes_numbers_rule.snapshot.txt | 22 ++++++++++++++++ .../output/changes_rule.snapshot.txt | 22 ++++++++++++++++ .../grid_header_numbers_rule.snapshot.txt | 26 +++++++++++++++++++ .../output/grid_header_rule.snapshot.txt | 26 +++++++++++++++++++ .../output/grid_numbers_rule.snapshot.txt | 24 +++++++++++++++++ tests/snapshots/output/grid_rule.snapshot.txt | 24 +++++++++++++++++ .../output/header_numbers_rule.snapshot.txt | 23 ++++++++++++++++ .../snapshots/output/header_rule.snapshot.txt | 23 ++++++++++++++++ .../output/numbers_rule.snapshot.txt | 22 ++++++++++++++++ tests/snapshots/output/rule.snapshot.txt | 22 ++++++++++++++++ 23 files changed, 441 insertions(+), 9 deletions(-) create mode 100644 tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_grid_header_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_grid_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_grid_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_header_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_header_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/changes_rule.snapshot.txt create mode 100644 tests/snapshots/output/grid_header_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/grid_header_rule.snapshot.txt create mode 100644 tests/snapshots/output/grid_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/grid_rule.snapshot.txt create mode 100644 tests/snapshots/output/header_numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/header_rule.snapshot.txt create mode 100644 tests/snapshots/output/numbers_rule.snapshot.txt create mode 100644 tests/snapshots/output/rule.snapshot.txt diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index d04abd8a..4e642760 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -367,7 +367,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { .validator(|val| { let mut invalid_vals = val.split(',').filter(|style| { !&[ - "auto", "full", "plain", "header", "grid", "numbers", "snip", + "auto", "full", "plain", "header", "grid", "rule", "numbers", "snip", #[cfg(feature = "git")] "changes", ] @@ -382,7 +382,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { }) .help( "Comma-separated list of style elements to display \ - (*auto*, full, plain, changes, header, grid, numbers, snip).", + (*auto*, full, plain, changes, header, grid, rule, numbers, snip).", ) .long_help( "Configure which elements (line numbers, file headers, grid \ @@ -400,6 +400,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { * header: show filenames before the content.\n \ * grid: vertical/horizontal lines to separate side bar\n \ and the header from the content.\n \ + * rule: horizontal lines to delimit files.\n \ * numbers: show line numbers in the side bar.\n \ * snip: draw separation lines between distinct line ranges.", ), diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index c9530bf4..89745eec 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -23,6 +23,7 @@ struct ActiveStyleComponents { header: bool, vcs_modification_markers: bool, grid: bool, + rule: bool, line_numbers: bool, snip: bool, } @@ -179,6 +180,12 @@ impl<'a> PrettyPrinter<'a> { self } + /// Whether to paint a horizontal rule to delimit files + pub fn rule(&mut self, yes: bool) -> &mut Self { + self.active_style_components.rule = yes; + self + } + /// Whether to show modification markers for VCS changes. This has no effect if /// the `git` feature is not activated. #[cfg_attr( @@ -285,6 +292,9 @@ impl<'a> PrettyPrinter<'a> { if self.active_style_components.grid { style_components.push(StyleComponent::Grid); } + if self.active_style_components.rule { + style_components.push(StyleComponent::Rule); + } if self.active_style_components.header { style_components.push(StyleComponent::Header); } diff --git a/src/printer.rs b/src/printer.rs index 71bf78ee..e0829874 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -200,13 +200,18 @@ impl<'a> InteractivePrinter<'a> { }) } + fn print_horizontal_line_term(&mut self, handle: &mut dyn Write, style: Style) -> Result<()> { + writeln!( + handle, + "{}", + style.paint("─".repeat(self.config.term_width)) + )?; + Ok(()) + } + fn print_horizontal_line(&mut self, handle: &mut dyn Write, grid_char: char) -> Result<()> { if self.panel_width == 0 { - writeln!( - handle, - "{}", - self.colors.grid.paint("─".repeat(self.config.term_width)) - )?; + self.print_horizontal_line_term(handle, self.colors.grid)?; } else { let hline = "─".repeat(self.config.term_width - (self.panel_width + 1)); let hline = format!("{}{}{}", "─".repeat(self.panel_width), grid_char, hline); @@ -251,6 +256,10 @@ impl<'a> Printer for InteractivePrinter<'a> { input: &OpenedInput, add_header_padding: bool, ) -> Result<()> { + if add_header_padding && self.config.style_components.rule() { + self.print_horizontal_line_term(handle, self.colors.rule)?; + } + if !self.config.style_components.header() { if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable { writeln!( @@ -279,7 +288,8 @@ impl<'a> Printer for InteractivePrinter<'a> { .paint(if self.panel_width > 0 { "│ " } else { "" }), )?; } else { - if add_header_padding { + // Only pad space between files, if we haven't already drawn a horizontal rule + if add_header_padding && !self.config.style_components.rule() { writeln!(handle)?; } write!(handle, "{}", " ".repeat(self.panel_width))?; @@ -603,6 +613,7 @@ const DEFAULT_GUTTER_COLOR: u8 = 238; #[derive(Debug, Default)] pub struct Colors { pub grid: Style, + pub rule: Style, pub filename: Style, pub git_added: Style, pub git_removed: Style, @@ -624,6 +635,7 @@ impl Colors { Colors { grid: gutter_color.normal(), + rule: gutter_color.normal(), filename: Style::new().bold(), git_added: Green.normal(), git_removed: Red.normal(), diff --git a/src/style.rs b/src/style.rs index 8d51cbde..65414206 100644 --- a/src/style.rs +++ b/src/style.rs @@ -9,6 +9,7 @@ pub enum StyleComponent { #[cfg(feature = "git")] Changes, Grid, + Rule, Header, LineNumbers, Snip, @@ -29,6 +30,7 @@ impl StyleComponent { #[cfg(feature = "git")] StyleComponent::Changes => &[StyleComponent::Changes], StyleComponent::Grid => &[StyleComponent::Grid], + StyleComponent::Rule => &[StyleComponent::Rule], StyleComponent::Header => &[StyleComponent::Header], StyleComponent::LineNumbers => &[StyleComponent::LineNumbers], StyleComponent::Snip => &[StyleComponent::Snip], @@ -54,6 +56,7 @@ impl FromStr for StyleComponent { #[cfg(feature = "git")] "changes" => Ok(StyleComponent::Changes), "grid" => Ok(StyleComponent::Grid), + "rule" => Ok(StyleComponent::Rule), "header" => Ok(StyleComponent::Header), "numbers" => Ok(StyleComponent::LineNumbers), "snip" => Ok(StyleComponent::Snip), @@ -81,6 +84,10 @@ impl StyleComponents { self.0.contains(&StyleComponent::Grid) } + pub fn rule(&self) -> bool { + self.0.contains(&StyleComponent::Rule) + } + pub fn header(&self) -> bool { self.0.contains(&StyleComponent::Header) } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index da0690ef..9dfa8067 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -570,6 +570,18 @@ fn empty_file_leads_to_empty_output_with_grid_enabled() { .stdout(""); } +#[test] +fn empty_file_leads_to_empty_output_with_rule_enabled() { + bat() + .arg("empty.txt") + .arg("--style=rule") + .arg("--decorations=always") + .arg("--terminal-width=80") + .assert() + .success() + .stdout(""); +} + #[test] fn filename_basic() { bat() diff --git a/tests/snapshot_tests.rs b/tests/snapshot_tests.rs index ad41edb2..8abb8414 100644 --- a/tests/snapshot_tests.rs +++ b/tests/snapshot_tests.rs @@ -19,17 +19,27 @@ snapshot_tests! { grid: "grid", header: "header", numbers: "numbers", + rule: "rule", changes_grid: "changes,grid", changes_header: "changes,header", changes_numbers: "changes,numbers", + changes_rule: "changes,rule", grid_header: "grid,header", grid_numbers: "grid,numbers", + grid_rule: "grid,rule", header_numbers: "header,numbers", + header_rule: "header,rule", changes_grid_header: "changes,grid,header", changes_grid_numbers: "changes,grid,numbers", + changes_grid_rule: "changes,grid,rule", changes_header_numbers: "changes,header,numbers", + changes_header_rule: "changes,header,rule", grid_header_numbers: "grid,header,numbers", + grid_header_rule: "grid,header,rule", + header_numbers_rule: "header,numbers,rule", changes_grid_header_numbers: "changes,grid,header,numbers", + changes_grid_header_rule: "changes,grid,header,rule", + changes_grid_header_numbers_rule: "changes,grid,header,numbers,rule", full: "full", plain: "plain", } diff --git a/tests/snapshots/generate_snapshots.py b/tests/snapshots/generate_snapshots.py index fd17b285..bb7d69ba 100755 --- a/tests/snapshots/generate_snapshots.py +++ b/tests/snapshots/generate_snapshots.py @@ -7,7 +7,7 @@ import shutil def generate_snapshots(): - single_styles = ["changes", "grid", "header", "numbers"] + single_styles = ["changes", "grid", "header", "numbers", "rule"] collective_styles = ["full", "plain"] for num in range(len(single_styles)): diff --git a/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt b/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt new file mode 100644 index 00000000..cee4737f --- /dev/null +++ b/tests/snapshots/output/changes_grid_header_numbers_rule.snapshot.txt @@ -0,0 +1,26 @@ +───────┬──────────────────────────────────────────────────────────────────────── + │ File: sample.rs +───────┼──────────────────────────────────────────────────────────────────────── + 1 │ struct Rectangle { + 2 │ width: u32, + 3 │ height: u32, + 4 │ } + 5 │ + 6 _ │ fn main() { + 7 │ let rect1 = Rectangle { width: 30, height: 50 }; + 8 │ + 9 │ println!( + 10 ~ │ "The perimeter of the rectangle is {} pixels.", + 11 ~ │ perimeter(&rect1) + 12 │ ); + 13 + │ println!(r#"This line contains invalid utf8: "�����"#; + 14 │ } + 15 │ + 16 │ fn area(rectangle: &Rectangle) -> u32 { + 17 │ rectangle.width * rectangle.height + 18 │ } + 19 + │ + 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { + 21 + │ (rectangle.width + rectangle.height) * 2 + 22 + │ } +───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/changes_grid_header_rule.snapshot.txt b/tests/snapshots/output/changes_grid_header_rule.snapshot.txt new file mode 100644 index 00000000..655b6e24 --- /dev/null +++ b/tests/snapshots/output/changes_grid_header_rule.snapshot.txt @@ -0,0 +1,26 @@ +──┬───────────────────────────────────────────────────────────────────────────── + │ File: sample.rs +──┼───────────────────────────────────────────────────────────────────────────── + │ struct Rectangle { + │ width: u32, + │ height: u32, + │ } + │ +_ │ fn main() { + │ let rect1 = Rectangle { width: 30, height: 50 }; + │ + │ println!( +~ │ "The perimeter of the rectangle is {} pixels.", +~ │ perimeter(&rect1) + │ ); ++ │ println!(r#"This line contains invalid utf8: "�����"#; + │ } + │ + │ fn area(rectangle: &Rectangle) -> u32 { + │ rectangle.width * rectangle.height + │ } ++ │ ++ │ fn perimeter(rectangle: &Rectangle) -> u32 { ++ │ (rectangle.width + rectangle.height) * 2 ++ │ } +──┴───────────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/changes_grid_numbers_rule.snapshot.txt b/tests/snapshots/output/changes_grid_numbers_rule.snapshot.txt new file mode 100644 index 00000000..7fe7cccf --- /dev/null +++ b/tests/snapshots/output/changes_grid_numbers_rule.snapshot.txt @@ -0,0 +1,24 @@ +───────┬──────────────────────────────────────────────────────────────────────── + 1 │ struct Rectangle { + 2 │ width: u32, + 3 │ height: u32, + 4 │ } + 5 │ + 6 _ │ fn main() { + 7 │ let rect1 = Rectangle { width: 30, height: 50 }; + 8 │ + 9 │ println!( + 10 ~ │ "The perimeter of the rectangle is {} pixels.", + 11 ~ │ perimeter(&rect1) + 12 │ ); + 13 + │ println!(r#"This line contains invalid utf8: "�����"#; + 14 │ } + 15 │ + 16 │ fn area(rectangle: &Rectangle) -> u32 { + 17 │ rectangle.width * rectangle.height + 18 │ } + 19 + │ + 20 + │ fn perimeter(rectangle: &Rectangle) -> u32 { + 21 + │ (rectangle.width + rectangle.height) * 2 + 22 + │ } +───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/changes_grid_rule.snapshot.txt b/tests/snapshots/output/changes_grid_rule.snapshot.txt new file mode 100644 index 00000000..04767b8b --- /dev/null +++ b/tests/snapshots/output/changes_grid_rule.snapshot.txt @@ -0,0 +1,24 @@ +──┬───────────────────────────────────────────────────────────────────────────── + │ struct Rectangle { + │ width: u32, + │ height: u32, + │ } + │ +_ │ fn main() { + │ let rect1 = Rectangle { width: 30, height: 50 }; + │ + │ println!( +~ │ "The perimeter of the rectangle is {} pixels.", +~ │ perimeter(&rect1) + │ ); ++ │ println!(r#"This line contains invalid utf8: "�����"#; + │ } + │ + │ fn area(rectangle: &Rectangle) -> u32 { + │ rectangle.width * rectangle.height + │ } ++ │ ++ │ fn perimeter(rectangle: &Rectangle) -> u32 { ++ │ (rectangle.width + rectangle.height) * 2 ++ │ } +──┴───────────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt b/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt new file mode 100644 index 00000000..77145eb9 --- /dev/null +++ b/tests/snapshots/output/changes_header_numbers_rule.snapshot.txt @@ -0,0 +1,23 @@ + File: sample.rs + 1 struct Rectangle { + 2 width: u32, + 3 height: u32, + 4 } + 5 + 6 _ fn main() { + 7 let rect1 = Rectangle { width: 30, height: 50 }; + 8 + 9 println!( + 10 ~ "The perimeter of the rectangle is {} pixels.", + 11 ~ perimeter(&rect1) + 12 ); + 13 + println!(r#"This line contains invalid utf8: "�����"#; + 14 } + 15 + 16 fn area(rectangle: &Rectangle) -> u32 { + 17 rectangle.width * rectangle.height + 18 } + 19 + + 20 + fn perimeter(rectangle: &Rectangle) -> u32 { + 21 + (rectangle.width + rectangle.height) * 2 + 22 + } diff --git a/tests/snapshots/output/changes_header_rule.snapshot.txt b/tests/snapshots/output/changes_header_rule.snapshot.txt new file mode 100644 index 00000000..82fe8c47 --- /dev/null +++ b/tests/snapshots/output/changes_header_rule.snapshot.txt @@ -0,0 +1,23 @@ + File: sample.rs + struct Rectangle { + width: u32, + height: u32, + } + +_ fn main() { + let rect1 = Rectangle { width: 30, height: 50 }; + + println!( +~ "The perimeter of the rectangle is {} pixels.", +~ perimeter(&rect1) + ); ++ println!(r#"This line contains invalid utf8: "�����"#; + } + + fn area(rectangle: &Rectangle) -> u32 { + rectangle.width * rectangle.height + } ++ ++ fn perimeter(rectangle: &Rectangle) -> u32 { ++ (rectangle.width + rectangle.height) * 2 ++ } diff --git a/tests/snapshots/output/changes_numbers_rule.snapshot.txt b/tests/snapshots/output/changes_numbers_rule.snapshot.txt new file mode 100644 index 00000000..bdfe745b --- /dev/null +++ b/tests/snapshots/output/changes_numbers_rule.snapshot.txt @@ -0,0 +1,22 @@ + 1 struct Rectangle { + 2 width: u32, + 3 height: u32, + 4 } + 5 + 6 _ fn main() { + 7 let rect1 = Rectangle { width: 30, height: 50 }; + 8 + 9 println!( + 10 ~ "The perimeter of the rectangle is {} pixels.", + 11 ~ perimeter(&rect1) + 12 ); + 13 + println!(r#"This line contains invalid utf8: "�����"#; + 14 } + 15 + 16 fn area(rectangle: &Rectangle) -> u32 { + 17 rectangle.width * rectangle.height + 18 } + 19 + + 20 + fn perimeter(rectangle: &Rectangle) -> u32 { + 21 + (rectangle.width + rectangle.height) * 2 + 22 + } diff --git a/tests/snapshots/output/changes_rule.snapshot.txt b/tests/snapshots/output/changes_rule.snapshot.txt new file mode 100644 index 00000000..28d87201 --- /dev/null +++ b/tests/snapshots/output/changes_rule.snapshot.txt @@ -0,0 +1,22 @@ + struct Rectangle { + width: u32, + height: u32, + } + +_ fn main() { + let rect1 = Rectangle { width: 30, height: 50 }; + + println!( +~ "The perimeter of the rectangle is {} pixels.", +~ perimeter(&rect1) + ); ++ println!(r#"This line contains invalid utf8: "�����"#; + } + + fn area(rectangle: &Rectangle) -> u32 { + rectangle.width * rectangle.height + } ++ ++ fn perimeter(rectangle: &Rectangle) -> u32 { ++ (rectangle.width + rectangle.height) * 2 ++ } diff --git a/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt b/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt new file mode 100644 index 00000000..e9f1a9cf --- /dev/null +++ b/tests/snapshots/output/grid_header_numbers_rule.snapshot.txt @@ -0,0 +1,26 @@ +─────┬────────────────────────────────────────────────────────────────────────── + │ File: sample.rs +─────┼────────────────────────────────────────────────────────────────────────── + 1 │ struct Rectangle { + 2 │ width: u32, + 3 │ height: u32, + 4 │ } + 5 │ + 6 │ fn main() { + 7 │ let rect1 = Rectangle { width: 30, height: 50 }; + 8 │ + 9 │ println!( + 10 │ "The perimeter of the rectangle is {} pixels.", + 11 │ perimeter(&rect1) + 12 │ ); + 13 │ println!(r#"This line contains invalid utf8: "�����"#; + 14 │ } + 15 │ + 16 │ fn area(rectangle: &Rectangle) -> u32 { + 17 │ rectangle.width * rectangle.height + 18 │ } + 19 │ + 20 │ fn perimeter(rectangle: &Rectangle) -> u32 { + 21 │ (rectangle.width + rectangle.height) * 2 + 22 │ } +─────┴────────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/grid_header_rule.snapshot.txt b/tests/snapshots/output/grid_header_rule.snapshot.txt new file mode 100644 index 00000000..50c16941 --- /dev/null +++ b/tests/snapshots/output/grid_header_rule.snapshot.txt @@ -0,0 +1,26 @@ +──────────────────────────────────────────────────────────────────────────────── +File: sample.rs +──────────────────────────────────────────────────────────────────────────────── +struct Rectangle { + width: u32, + height: u32, +} + +fn main() { + let rect1 = Rectangle { width: 30, height: 50 }; + + println!( + "The perimeter of the rectangle is {} pixels.", + perimeter(&rect1) + ); + println!(r#"This line contains invalid utf8: "�����"#; +} + +fn area(rectangle: &Rectangle) -> u32 { + rectangle.width * rectangle.height +} + +fn perimeter(rectangle: &Rectangle) -> u32 { + (rectangle.width + rectangle.height) * 2 +} +──────────────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/grid_numbers_rule.snapshot.txt b/tests/snapshots/output/grid_numbers_rule.snapshot.txt new file mode 100644 index 00000000..09614667 --- /dev/null +++ b/tests/snapshots/output/grid_numbers_rule.snapshot.txt @@ -0,0 +1,24 @@ +─────┬────────────────────────────────────────────────────────────────────────── + 1 │ struct Rectangle { + 2 │ width: u32, + 3 │ height: u32, + 4 │ } + 5 │ + 6 │ fn main() { + 7 │ let rect1 = Rectangle { width: 30, height: 50 }; + 8 │ + 9 │ println!( + 10 │ "The perimeter of the rectangle is {} pixels.", + 11 │ perimeter(&rect1) + 12 │ ); + 13 │ println!(r#"This line contains invalid utf8: "�����"#; + 14 │ } + 15 │ + 16 │ fn area(rectangle: &Rectangle) -> u32 { + 17 │ rectangle.width * rectangle.height + 18 │ } + 19 │ + 20 │ fn perimeter(rectangle: &Rectangle) -> u32 { + 21 │ (rectangle.width + rectangle.height) * 2 + 22 │ } +─────┴────────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/grid_rule.snapshot.txt b/tests/snapshots/output/grid_rule.snapshot.txt new file mode 100644 index 00000000..5b970581 --- /dev/null +++ b/tests/snapshots/output/grid_rule.snapshot.txt @@ -0,0 +1,24 @@ +──────────────────────────────────────────────────────────────────────────────── +struct Rectangle { + width: u32, + height: u32, +} + +fn main() { + let rect1 = Rectangle { width: 30, height: 50 }; + + println!( + "The perimeter of the rectangle is {} pixels.", + perimeter(&rect1) + ); + println!(r#"This line contains invalid utf8: "�����"#; +} + +fn area(rectangle: &Rectangle) -> u32 { + rectangle.width * rectangle.height +} + +fn perimeter(rectangle: &Rectangle) -> u32 { + (rectangle.width + rectangle.height) * 2 +} +──────────────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/header_numbers_rule.snapshot.txt b/tests/snapshots/output/header_numbers_rule.snapshot.txt new file mode 100644 index 00000000..a681e6b4 --- /dev/null +++ b/tests/snapshots/output/header_numbers_rule.snapshot.txt @@ -0,0 +1,23 @@ + File: sample.rs + 1 struct Rectangle { + 2 width: u32, + 3 height: u32, + 4 } + 5 + 6 fn main() { + 7 let rect1 = Rectangle { width: 30, height: 50 }; + 8 + 9 println!( + 10 "The perimeter of the rectangle is {} pixels.", + 11 perimeter(&rect1) + 12 ); + 13 println!(r#"This line contains invalid utf8: "�����"#; + 14 } + 15 + 16 fn area(rectangle: &Rectangle) -> u32 { + 17 rectangle.width * rectangle.height + 18 } + 19 + 20 fn perimeter(rectangle: &Rectangle) -> u32 { + 21 (rectangle.width + rectangle.height) * 2 + 22 } diff --git a/tests/snapshots/output/header_rule.snapshot.txt b/tests/snapshots/output/header_rule.snapshot.txt new file mode 100644 index 00000000..0889edfd --- /dev/null +++ b/tests/snapshots/output/header_rule.snapshot.txt @@ -0,0 +1,23 @@ +File: sample.rs +struct Rectangle { + width: u32, + height: u32, +} + +fn main() { + let rect1 = Rectangle { width: 30, height: 50 }; + + println!( + "The perimeter of the rectangle is {} pixels.", + perimeter(&rect1) + ); + println!(r#"This line contains invalid utf8: "�����"#; +} + +fn area(rectangle: &Rectangle) -> u32 { + rectangle.width * rectangle.height +} + +fn perimeter(rectangle: &Rectangle) -> u32 { + (rectangle.width + rectangle.height) * 2 +} diff --git a/tests/snapshots/output/numbers_rule.snapshot.txt b/tests/snapshots/output/numbers_rule.snapshot.txt new file mode 100644 index 00000000..c1341d29 --- /dev/null +++ b/tests/snapshots/output/numbers_rule.snapshot.txt @@ -0,0 +1,22 @@ + 1 struct Rectangle { + 2 width: u32, + 3 height: u32, + 4 } + 5 + 6 fn main() { + 7 let rect1 = Rectangle { width: 30, height: 50 }; + 8 + 9 println!( + 10 "The perimeter of the rectangle is {} pixels.", + 11 perimeter(&rect1) + 12 ); + 13 println!(r#"This line contains invalid utf8: "�����"#; + 14 } + 15 + 16 fn area(rectangle: &Rectangle) -> u32 { + 17 rectangle.width * rectangle.height + 18 } + 19 + 20 fn perimeter(rectangle: &Rectangle) -> u32 { + 21 (rectangle.width + rectangle.height) * 2 + 22 } diff --git a/tests/snapshots/output/rule.snapshot.txt b/tests/snapshots/output/rule.snapshot.txt new file mode 100644 index 00000000..dbc49f9f --- /dev/null +++ b/tests/snapshots/output/rule.snapshot.txt @@ -0,0 +1,22 @@ +struct Rectangle { + width: u32, + height: u32, +} + +fn main() { + let rect1 = Rectangle { width: 30, height: 50 }; + + println!( + "The perimeter of the rectangle is {} pixels.", + perimeter(&rect1) + ); + println!(r#"This line contains invalid utf8: "�����"#; +} + +fn area(rectangle: &Rectangle) -> u32 { + rectangle.width * rectangle.height +} + +fn perimeter(rectangle: &Rectangle) -> u32 { + (rectangle.width + rectangle.height) * 2 +}