mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
parent
346902e30b
commit
9de407b1f0
4 changed files with 20 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2206,6 +2206,7 @@ version = "0.0.13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap 3.1.8",
|
"clap 3.1.8",
|
||||||
"number_prefix",
|
"number_prefix",
|
||||||
|
"unicode-width",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ path = "src/df.rs"
|
||||||
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
|
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
|
||||||
number_prefix = "0.4"
|
number_prefix = "0.4"
|
||||||
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "fsext"] }
|
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "fsext"] }
|
||||||
|
unicode-width = "0.1.9"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "df"
|
name = "df"
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
//! A table ([`Table`]) comprises a header row ([`Header`]) and a
|
//! A table ([`Table`]) comprises a header row ([`Header`]) and a
|
||||||
//! collection of data rows ([`Row`]), one per filesystem.
|
//! collection of data rows ([`Row`]), one per filesystem.
|
||||||
use number_prefix::NumberPrefix;
|
use number_prefix::NumberPrefix;
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use crate::columns::{Alignment, Column};
|
use crate::columns::{Alignment, Column};
|
||||||
use crate::filesystem::Filesystem;
|
use crate::filesystem::Filesystem;
|
||||||
|
@ -362,8 +363,8 @@ impl Table {
|
||||||
total += row;
|
total += row;
|
||||||
|
|
||||||
for (i, value) in values.iter().enumerate() {
|
for (i, value) in values.iter().enumerate() {
|
||||||
if value.len() > widths[i] {
|
if UnicodeWidthStr::width(value.as_str()) > widths[i] {
|
||||||
widths[i] = value.len();
|
widths[i] = UnicodeWidthStr::width(value.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,7 @@ fn test_output_mp_repeat() {
|
||||||
assert_eq!(3, output1.len());
|
assert_eq!(3, output1.len());
|
||||||
assert_eq!(output1[1], output1[2]);
|
assert_eq!(output1[1], output1[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output_conflict_options() {
|
fn test_output_conflict_options() {
|
||||||
for option in ["-i", "-T", "-P"] {
|
for option in ["-i", "-T", "-P"] {
|
||||||
|
@ -430,6 +431,20 @@ fn test_output_file_specific_files() {
|
||||||
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
|
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_file_column_width_if_filename_contains_unicode_chars() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.touch("äöü.txt");
|
||||||
|
|
||||||
|
let output = ucmd
|
||||||
|
.args(&["--output=file,target", "äöü.txt"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_move_str();
|
||||||
|
let actual = output.lines().next().unwrap();
|
||||||
|
// expected width: 7 chars (length of äöü.txt) + 1 char (column separator)
|
||||||
|
assert_eq!(actual, "File Mounted on");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output_field_no_more_than_once() {
|
fn test_output_field_no_more_than_once() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Reference in a new issue