Skip to content

Commit f9af783

Browse files
committed
df: table: Add test for non-Unicode printing
1 parent 6884e29 commit f9af783

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/uu/df/src/table.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,56 @@ mod tests {
10181018
);
10191019
}
10201020

1021+
#[cfg(unix)]
1022+
#[test]
1023+
fn test_table_column_width_non_unicode() {
1024+
init();
1025+
let bad_unicode_os_str = uucore::os_str_from_bytes(b"/usr/lib/w\xf3l/drivers")
1026+
.expect("Only unix platforms can test non-unicode names")
1027+
.to_os_string();
1028+
let d1 = crate::Filesystem {
1029+
file: None,
1030+
mount_info: crate::MountInfo {
1031+
dev_id: "28".to_string(),
1032+
dev_name: "none".to_string(),
1033+
fs_type: "9p".to_string(),
1034+
mount_dir: bad_unicode_os_str,
1035+
mount_option: "ro,nosuid,nodev,noatime".to_string(),
1036+
mount_root: "/".into(),
1037+
remote: false,
1038+
dummy: false,
1039+
},
1040+
usage: crate::table::FsUsage {
1041+
blocksize: 4096,
1042+
blocks: 244_029_695,
1043+
bfree: 125_085_030,
1044+
bavail: 125_085_030,
1045+
bavail_top_bit_set: false,
1046+
files: 99_999_999_999,
1047+
ffree: 999_999,
1048+
},
1049+
};
1050+
1051+
let filesystems = vec![d1];
1052+
1053+
let options = Options {
1054+
show_total: false,
1055+
columns: vec![Column::Source, Column::Target, Column::Itotal],
1056+
..Default::default()
1057+
};
1058+
1059+
let table = Table::new(&options, filesystems.clone());
1060+
let mut data: Vec<u8> = vec![];
1061+
table.write_to(&mut data).expect("Write error.");
1062+
assert_eq!(
1063+
data,
1064+
b"Filesystem Mounted on Inodes\n\
1065+
none /usr/lib/w\xf3l/drivers 99999999999\n",
1066+
"Comparison failed, lossy data for reference:\n{}\n",
1067+
String::from_utf8_lossy(&data)
1068+
);
1069+
}
1070+
10211071
#[test]
10221072
fn test_row_accumulation_u64_overflow() {
10231073
init();

0 commit comments

Comments
 (0)