mirror of
https://github.com/sharkdp/bat
synced 2024-11-26 22:00:30 +00:00
--file-name for normal files. integration tests.
This commit is contained in:
parent
517be5c7bc
commit
cfa2cb6ec7
3 changed files with 70 additions and 4 deletions
|
@ -228,9 +228,10 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||
if !self.config.output_components.header() {
|
||||
if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
|
||||
let input = match file {
|
||||
InputFile::Ordinary(filename) => {
|
||||
format!("file '{}'", filename.to_string_lossy())
|
||||
}
|
||||
InputFile::Ordinary(filename) => format!(
|
||||
"file '{}'",
|
||||
self.config.filename.unwrap_or(&filename.to_string_lossy())
|
||||
),
|
||||
_ => self.config.filename.unwrap_or("STDIN").to_owned(),
|
||||
};
|
||||
|
||||
|
@ -266,7 +267,15 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||
}
|
||||
|
||||
let (prefix, name) = match file {
|
||||
InputFile::Ordinary(filename) => ("File: ", filename.to_string_lossy()),
|
||||
InputFile::Ordinary(filename) => (
|
||||
"File: ",
|
||||
Cow::from(
|
||||
self.config
|
||||
.filename
|
||||
.unwrap_or(&filename.to_string_lossy())
|
||||
.to_owned(),
|
||||
),
|
||||
),
|
||||
_ => (
|
||||
"File: ",
|
||||
Cow::from(self.config.filename.unwrap_or("STDIN").to_owned()),
|
||||
|
|
BIN
tests/examples/test.binary
vendored
Normal file
BIN
tests/examples/test.binary
vendored
Normal file
Binary file not shown.
|
@ -541,3 +541,60 @@ fn empty_file_leads_to_empty_output_with_grid_enabled() {
|
|||
.success()
|
||||
.stdout("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filename_basic() {
|
||||
bat()
|
||||
.arg("test.txt")
|
||||
.arg("--decorations=always")
|
||||
.arg("--style=header")
|
||||
.arg("-r=0:0")
|
||||
.arg("--file-name=foo")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("File: foo\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filename_binary() {
|
||||
bat()
|
||||
.arg("test.binary")
|
||||
.arg("--decorations=always")
|
||||
.arg("--style=header")
|
||||
.arg("-r=0:0")
|
||||
.arg("--file-name=foo")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("File: foo <BINARY>\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filename_stdin() {
|
||||
bat()
|
||||
.arg("--decorations=always")
|
||||
.arg("--style=header")
|
||||
.arg("-r=0:0")
|
||||
.arg("-")
|
||||
.write_stdin("stdin\n")
|
||||
.arg("--file-name=foo")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("File: foo\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filename_stdin_binary() {
|
||||
let vec = vec![0; 1];
|
||||
bat_with_config()
|
||||
.arg("--decorations=always")
|
||||
.arg("--style=header")
|
||||
.write_stdin(vec)
|
||||
.arg("--file-name=foo")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout("File: foo <BINARY>\n")
|
||||
.stderr("");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue