Add new --style called header-filesize and display it by default (#1988)

Also rename `header` to `header-filename`.

Related to #1701
This commit is contained in:
Mahdi Dibaiee
2022-02-07 19:48:57 +00:00
committed by GitHub
parent f3f8194932
commit 312c8ef01f
111 changed files with 302 additions and 42 deletions

View File

@@ -919,7 +919,7 @@ fn empty_file_leads_to_empty_output_with_rule_enabled() {
}
#[test]
fn filename_basic() {
fn header_basic() {
bat()
.arg("test.txt")
.arg("--decorations=always")
@@ -933,7 +933,21 @@ fn filename_basic() {
}
#[test]
fn filename_binary() {
fn header_full_basic() {
bat()
.arg("test.txt")
.arg("--decorations=always")
.arg("--style=header-filename,header-filesize")
.arg("-r=0:0")
.arg("--file-name=foo")
.assert()
.success()
.stdout("File: foo\nSize: 12 B\n")
.stderr("");
}
#[test]
fn header_binary() {
bat()
.arg("test.binary")
.arg("--decorations=always")
@@ -946,6 +960,20 @@ fn filename_binary() {
.stderr("");
}
#[test]
fn header_full_binary() {
bat()
.arg("test.binary")
.arg("--decorations=always")
.arg("--style=header-filename,header-filesize")
.arg("-r=0:0")
.arg("--file-name=foo")
.assert()
.success()
.stdout("File: foo <BINARY>\nSize: 4 B\n")
.stderr("");
}
#[test]
fn filename_stdin() {
bat()
@@ -1016,6 +1044,18 @@ fn header_padding() {
.stderr("");
}
#[test]
fn header_full_padding() {
bat()
.arg("--decorations=always")
.arg("--style=header-filename,header-filesize")
.arg("test.txt")
.arg("single-line.txt")
.assert()
.stdout("File: test.txt\nSize: 12 B\nhello world\n\nFile: single-line.txt\nSize: 11 B\nSingle Line\n")
.stderr("");
}
#[test]
fn header_padding_rule() {
bat()
@@ -1036,6 +1076,28 @@ Single Line
.stderr("");
}
#[test]
fn header_full_padding_rule() {
bat()
.arg("--decorations=always")
.arg("--style=header-filename,header-filesize,rule")
.arg("--terminal-width=80")
.arg("test.txt")
.arg("single-line.txt")
.assert()
.stdout(
"File: test.txt
Size: 12 B
hello world
────────────────────────────────────────────────────────────────────────────────
File: single-line.txt
Size: 11 B
Single Line
",
)
.stderr("");
}
#[test]
fn grid_overrides_rule() {
bat()
@@ -1219,6 +1281,7 @@ fn grid_for_file_without_newline() {
"\
───────┬────────────────────────────────────────────────────────────────────────
│ File: single-line.txt
│ Size: 11 B
───────┼────────────────────────────────────────────────────────────────────────
1 │ Single Line
───────┴────────────────────────────────────────────────────────────────────────