From 2323aa0defe3f364bcd54ab662a12049141a322d Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Sun, 10 Sep 2023 14:33:48 +0200 Subject: [PATCH] Add tests for `--squeeze` --- tests/examples/empty_lines.txt | 30 ++++++++++++++++ tests/integration_tests.rs | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/examples/empty_lines.txt diff --git a/tests/examples/empty_lines.txt b/tests/examples/empty_lines.txt new file mode 100644 index 00000000..8ec1fae8 --- /dev/null +++ b/tests/examples/empty_lines.txt @@ -0,0 +1,30 @@ +line 1 + + + +line 5 + + + + + + + + + + + + + + +line 20 +line 21 + + +line 24 + +line 26 + + + +line 30 diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 3612654b..4d595031 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -208,6 +208,70 @@ fn line_range_multiple() { .stdout("line 1\nline 2\nline 4\n"); } +#[test] +fn squeeze() { + bat() + .arg("empty_lines.txt") + .arg("--squeeze") + .assert() + .success() + .stdout("line 1\n\nline 5\n\nline 20\nline 21\n\nline 24\n\nline 26\n\nline 30\n"); +} + +#[test] +fn squeeze_line_numbers() { + bat() + .arg("empty_lines.txt") + .arg("--squeeze") + .arg("--decorations=always") + .arg("--number") + .assert() + .success() + .stdout(" 1 line 1\n 2 \n 5 line 5\n 6 \n 20 line 20\n 21 line 21\n 22 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 30 line 30\n"); +} + +#[test] +fn squeeze_limit() { + bat() + .arg("empty_lines.txt") + .arg("--squeeze") + .arg("--squeeze-limit=2") + .assert() + .success() + .stdout("line 1\n\n\nline 5\n\n\nline 20\nline 21\n\n\nline 24\n\nline 26\n\n\nline 30\n"); + + bat() + .arg("empty_lines.txt") + .arg("--squeeze") + .arg("--squeeze-limit=5") + .assert() + .success() + .stdout("line 1\n\n\n\nline 5\n\n\n\n\n\nline 20\nline 21\n\n\nline 24\n\nline 26\n\n\n\nline 30\n"); +} + +#[test] +fn squeeze_limit_line_numbers() { + bat() + .arg("empty_lines.txt") + .arg("--squeeze") + .arg("--squeeze-limit=2") + .arg("--decorations=always") + .arg("--number") + .assert() + .success() + .stdout(" 1 line 1\n 2 \n 3 \n 5 line 5\n 6 \n 7 \n 20 line 20\n 21 line 21\n 22 \n 23 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 28 \n 30 line 30\n"); + + bat() + .arg("empty_lines.txt") + .arg("--squeeze") + .arg("--squeeze-limit=5") + .arg("--decorations=always") + .arg("--number") + .assert() + .success() + .stdout(" 1 line 1\n 2 \n 3 \n 4 \n 5 line 5\n 6 \n 7 \n 8 \n 9 \n 10 \n 20 line 20\n 21 line 21\n 22 \n 23 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 28 \n 29 \n 30 line 30\n"); +} + #[test] #[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)] fn short_help() {