1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-10-20 18:53:53 +01:00

feat(pipe-style): make output pipeable (any style)

This commit is contained in:
Louis Maddox
2025-10-16 13:27:11 +01:00
parent f1a0d8b3f7
commit 7eedc0f854
3 changed files with 81 additions and 1 deletions

View File

@@ -378,6 +378,83 @@ fn line_range_context_very_large() {
);
}
#[test]
fn piped_output_with_implicit_auto_style() {
bat()
.write_stdin("hello\nworld\n")
.assert()
.success()
.stdout("hello\nworld\n");
}
#[test]
fn piped_output_with_line_number_flag() {
bat()
.arg("--number")
.write_stdin("hello\nworld\n")
.assert()
.success()
.stdout(" 1 hello\n 2 world\n");
}
#[test]
fn piped_output_with_line_numbers_style_flag() {
bat()
.arg("--style=numbers")
.write_stdin("hello\nworld\n")
.assert()
.success()
.stdout(" 1 hello\n 2 world\n");
}
#[test]
#[cfg(not(target_os = "windows"))]
fn piped_output_with_line_numbers_with_header_grid_style_flag() {
bat()
.arg("--style=header,grid,numbers")
.write_stdin("hello\nworld\n")
.assert()
.success()
.stdout(
"─────┬──────────────────────────────────────────────────────────────────────────
│ STDIN
─────┼──────────────────────────────────────────────────────────────────────────
1 │ hello
2 │ world
─────┴──────────────────────────────────────────────────────────────────────────
",
);
}
#[test]
fn piped_output_with_auto_style() {
bat()
.arg("--style=auto")
.write_stdin("hello\nworld\n")
.assert()
.success()
.stdout("hello\nworld\n"); // Should be plain when piped
}
#[test]
#[cfg(not(target_os = "windows"))]
fn piped_output_with_default_style_flag() {
bat()
.arg("--style=default")
.write_stdin("hello\nworld\n")
.assert()
.success()
.stdout(
"─────┬──────────────────────────────────────────────────────────────────────────
│ STDIN
─────┼──────────────────────────────────────────────────────────────────────────
1 │ hello
2 │ world
─────┴──────────────────────────────────────────────────────────────────────────
",
);
}
#[test]
fn squeeze_blank() {
bat()