From c1e1f753cfdae56dc3777e6e512bdb0b56ef3750 Mon Sep 17 00:00:00 2001 From: eth-p <32112321+eth-p@users.noreply.github.com> Date: Tue, 11 Sep 2018 13:47:01 -0700 Subject: [PATCH] Added three new snapshot tests for --tabs and --wrap. --- tests/snapshots/generate_snapshots.py | 9 ++-- .../output/tabs_4_wrapped.snapshot.txt | 40 ++++++++++++++++ .../output/tabs_8_wrapped.snapshot.txt | 40 ++++++++++++++++ .../tabs_passthrough_wrapped.snapshot.txt | 40 ++++++++++++++++ tests/tester.rs | 3 +- tests/tests.rs | 47 ++++++++++--------- 6 files changed, 153 insertions(+), 26 deletions(-) create mode 100644 tests/snapshots/output/tabs_4_wrapped.snapshot.txt create mode 100644 tests/snapshots/output/tabs_8_wrapped.snapshot.txt create mode 100644 tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt diff --git a/tests/snapshots/generate_snapshots.py b/tests/snapshots/generate_snapshots.py index ea130a4f..7a4798ff 100755 --- a/tests/snapshots/generate_snapshots.py +++ b/tests/snapshots/generate_snapshots.py @@ -15,9 +15,12 @@ def generate_snapshots(): for style in collective_styles: generate_style_snapshot(style) - generate_snapshot("tabs_passthrough", "--tabs=0 --style=full") - generate_snapshot("tabs_4", "--tabs=4 --style=full") - generate_snapshot("tabs_8", "--tabs=8 --style=full") + generate_snapshot("tabs_passthrough", "--tabs=0 --style=full --wrap=never") + generate_snapshot("tabs_passthrough_wrapped", "--tabs=0 --style=full --wrap=character") + generate_snapshot("tabs_4", "--tabs=4 --style=full --wrap=never") + generate_snapshot("tabs_4_wrapped", "--tabs=4 --style=full --wrap=character") + generate_snapshot("tabs_8", "--tabs=8 --style=full --wrap=never") + generate_snapshot("tabs_8_wrapped", "--tabs=8 --style=full --wrap=character") def generate_style_snapshot(style): generate_snapshot(style.replace(",","_"), "--style={}".format(style)) diff --git a/tests/snapshots/output/tabs_4_wrapped.snapshot.txt b/tests/snapshots/output/tabs_4_wrapped.snapshot.txt new file mode 100644 index 00000000..87689c7b --- /dev/null +++ b/tests/snapshots/output/tabs_4_wrapped.snapshot.txt @@ -0,0 +1,40 @@ +───────┬──────────────────────────────────────────────────────────────────────── + │ 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 + │ } + 23 + │ + 24 │ // Tab alignment: + 25 │ /* + 26 │ Indent + 27 │ 1 2 3 4 + 28 │ 1 ? + 29 │ 22 ? + 30 │ 333 ? + 31 │ 4444 ? + 32 │ 55555 ? + 33 │ 666666 ? + 34 │ 7777777 ? + 35 │ 88888888 ? + 36 ~ │ */ +───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_8_wrapped.snapshot.txt b/tests/snapshots/output/tabs_8_wrapped.snapshot.txt new file mode 100644 index 00000000..221306da --- /dev/null +++ b/tests/snapshots/output/tabs_8_wrapped.snapshot.txt @@ -0,0 +1,40 @@ +───────┬──────────────────────────────────────────────────────────────────────── + │ 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 + │ } + 23 + │ + 24 │ // Tab alignment: + 25 │ /* + 26 │ Indent + 27 │ 1 2 3 4 + 28 │ 1 ? + 29 │ 22 ? + 30 │ 333 ? + 31 │ 4444 ? + 32 │ 55555 ? + 33 │ 666666 ? + 34 │ 7777777 ? + 35 │ 88888888 ? + 36 ~ │ */ +───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt b/tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt new file mode 100644 index 00000000..3ad018a1 --- /dev/null +++ b/tests/snapshots/output/tabs_passthrough_wrapped.snapshot.txt @@ -0,0 +1,40 @@ +───────┬──────────────────────────────────────────────────────────────────────── + │ 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 + │ } + 23 + │ + 24 │ // Tab alignment: + 25 │ /* + 26 │ Indent + 27 │ 1 2 3 4 + 28 │ 1 ? + 29 │ 22 ? + 30 │ 333 ? + 31 │ 4444 ? + 32 │ 55555 ? + 33 │ 666666 ? + 34 │ 7777777 ? + 35 │ 88888888 ? + 36 ~ │ */ +───────┴──────────────────────────────────────────────────────────────────────── diff --git a/tests/tester.rs b/tests/tester.rs index c7f46c03..2c8de48d 100644 --- a/tests/tester.rs +++ b/tests/tester.rs @@ -38,13 +38,14 @@ impl BatTester { BatTester { temp_dir, exe } } - pub fn test_snapshot(&self, name: &str, style: &str, tab_width: u32) { + pub fn test_snapshot(&self, name: &str, style: &str, tab_width: u32, wrap: bool) { let output = Command::new(&self.exe) .current_dir(self.temp_dir.path()) .args(&[ "sample.rs", "--decorations=always", "--terminal-width=80", + &format!("--wrap={}", if wrap { "character" } else { "never" }), &format!("--tabs={}", tab_width), &format!("--style={}", style), ]).output() diff --git a/tests/tests.rs b/tests/tests.rs index 906bad4a..5c9967a2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -3,36 +3,39 @@ mod tester; use tester::BatTester; macro_rules! snapshot_tests { - ($($test_name: ident: $style: expr => [tabs: $tabs:expr],)*) => { + ($($test_name: ident: $style: expr => [wrap: $wrap:expr, tabs: $tabs:expr],)*) => { $( #[test] fn $test_name() { let bat_tester = BatTester::new(); - bat_tester.test_snapshot(stringify!($test_name), $style, $tabs); + bat_tester.test_snapshot(stringify!($test_name), $style, $tabs, $wrap); } )* }; } snapshot_tests! { - changes: "changes" => [tabs: 8], - grid: "grid" => [tabs: 8], - header: "header" => [tabs: 8], - numbers: "numbers" => [tabs: 8], - changes_grid: "changes,grid" => [tabs: 8], - changes_header: "changes,header" => [tabs: 8], - changes_numbers: "changes,numbers" => [tabs: 8], - grid_header: "grid,header" => [tabs: 8], - grid_numbers: "grid,numbers" => [tabs: 8], - header_numbers: "header,numbers" => [tabs: 8], - changes_grid_header: "changes,grid,header" => [tabs: 8], - changes_grid_numbers: "changes,grid,numbers" => [tabs: 8], - changes_header_numbers: "changes,header,numbers" => [tabs: 8], - grid_header_numbers: "grid,header,numbers" => [tabs: 8], - changes_grid_header_numbers: "changes,grid,header,numbers" => [tabs: 8], - full: "full" => [tabs: 8], - plain: "plain" => [tabs: 8], - tabs_passthrough: "full" => [tabs: 0], - tabs_4: "full" => [tabs: 4], - tabs_8: "full" => [tabs: 8], + changes: "changes" => [wrap: false, tabs: 8], + grid: "grid" => [wrap: false, tabs: 8], + header: "header" => [wrap: false, tabs: 8], + numbers: "numbers" => [wrap: false, tabs: 8], + changes_grid: "changes,grid" => [wrap: false, tabs: 8], + changes_header: "changes,header" => [wrap: false, tabs: 8], + changes_numbers: "changes,numbers" => [wrap: false, tabs: 8], + grid_header: "grid,header" => [wrap: false, tabs: 8], + grid_numbers: "grid,numbers" => [wrap: false, tabs: 8], + header_numbers: "header,numbers" => [wrap: false, tabs: 8], + changes_grid_header: "changes,grid,header" => [wrap: false, tabs: 8], + changes_grid_numbers: "changes,grid,numbers" => [wrap: false, tabs: 8], + changes_header_numbers: "changes,header,numbers" => [wrap: false, tabs: 8], + grid_header_numbers: "grid,header,numbers" => [wrap: false, tabs: 8], + changes_grid_header_numbers: "changes,grid,header,numbers" => [wrap: false, tabs: 8], + full: "full" => [wrap: false, tabs: 8], + plain: "plain" => [wrap: false, tabs: 8], + tabs_passthrough_wrapped: "full" => [wrap: true, tabs: 0], + tabs_4_wrapped: "full" => [wrap: true, tabs: 4], + tabs_8_wrapped: "full" => [wrap: true, tabs: 8], + tabs_passthrough: "full" => [wrap: false, tabs: 0], + tabs_4: "full" => [wrap: false, tabs: 4], + tabs_8: "full" => [wrap: false, tabs: 8], }