1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

Merge pull request #3481 from cakebaker/refactor_tests_in_table_rs

df: implement Default for Row for unit tests
This commit is contained in:
Terts Diepraam 2022-05-06 00:15:33 +02:00 committed by GitHub
commit a711597619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -449,6 +449,30 @@ mod tests {
Column::Target, Column::Target,
]; ];
impl Default for Row {
fn default() -> Self {
Self {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(),
bytes: 100,
bytes_used: 25,
bytes_avail: 75,
bytes_usage: Some(0.25),
#[cfg(target_os = "macos")]
bytes_capacity: Some(0.5),
inodes: 10,
inodes_used: 2,
inodes_free: 8,
inodes_usage: Some(0.2),
}
}
}
#[test] #[test]
fn test_default_header() { fn test_default_header() {
let options = Default::default(); let options = Default::default();
@ -568,9 +592,7 @@ mod tests {
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(), fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(), fs_mount: "my_mount".to_string(),
bytes: 100, bytes: 100,
@ -578,13 +600,7 @@ mod tests {
bytes_avail: 75, bytes_avail: 75,
bytes_usage: Some(0.25), bytes_usage: Some(0.25),
#[cfg(target_os = "macos")] ..Default::default()
bytes_capacity: Some(0.5),
inodes: 10,
inodes_used: 2,
inodes_free: 8,
inodes_usage: Some(0.2),
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!( assert_eq!(
@ -601,7 +617,6 @@ mod tests {
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(), fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(), fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(), fs_mount: "my_mount".to_string(),
@ -611,13 +626,7 @@ mod tests {
bytes_avail: 75, bytes_avail: 75,
bytes_usage: Some(0.25), bytes_usage: Some(0.25),
#[cfg(target_os = "macos")] ..Default::default()
bytes_capacity: Some(0.5),
inodes: 10,
inodes_used: 2,
inodes_free: 8,
inodes_usage: Some(0.2),
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!( assert_eq!(
@ -634,23 +643,15 @@ mod tests {
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(), fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(), fs_mount: "my_mount".to_string(),
bytes: 100,
bytes_used: 25,
bytes_avail: 75,
bytes_usage: Some(0.25),
#[cfg(target_os = "macos")]
bytes_capacity: Some(0.5),
inodes: 10, inodes: 10,
inodes_used: 2, inodes_used: 2,
inodes_free: 8, inodes_free: 8,
inodes_usage: Some(0.2), inodes_usage: Some(0.2),
..Default::default()
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!( assert_eq!(
@ -667,23 +668,9 @@ mod tests {
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(),
bytes: 100, bytes: 100,
bytes_used: 25,
bytes_avail: 75,
bytes_usage: Some(0.25),
#[cfg(target_os = "macos")]
bytes_capacity: Some(0.5),
inodes: 10, inodes: 10,
inodes_used: 2, ..Default::default()
inodes_free: 8,
inodes_usage: Some(0.2),
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!(fmt.get_values(), vec!("1", "10")); assert_eq!(fmt.get_values(), vec!("1", "10"));
@ -697,7 +684,6 @@ mod tests {
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(), fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(), fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(), fs_mount: "my_mount".to_string(),
@ -707,13 +693,7 @@ mod tests {
bytes_avail: 3000, bytes_avail: 3000,
bytes_usage: Some(0.25), bytes_usage: Some(0.25),
#[cfg(target_os = "macos")] ..Default::default()
bytes_capacity: Some(0.5),
inodes: 10,
inodes_used: 2,
inodes_free: 8,
inodes_usage: Some(0.2),
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!( assert_eq!(
@ -738,7 +718,6 @@ mod tests {
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(), fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(), fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(), fs_mount: "my_mount".to_string(),
@ -748,13 +727,7 @@ mod tests {
bytes_avail: 3072, bytes_avail: 3072,
bytes_usage: Some(0.25), bytes_usage: Some(0.25),
#[cfg(target_os = "macos")] ..Default::default()
bytes_capacity: Some(0.5),
inodes: 10,
inodes_used: 2,
inodes_free: 8,
inodes_usage: Some(0.2),
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!( assert_eq!(
@ -774,32 +747,14 @@ mod tests {
#[test] #[test]
fn test_row_formatter_with_round_up_usage() { fn test_row_formatter_with_round_up_usage() {
let options = Options { let options = Options {
block_size: BlockSize::Bytes(1), columns: vec![Column::Pcent],
..Default::default() ..Default::default()
}; };
let row = Row { let row = Row {
file: Some("/path/to/file".to_string()),
fs_device: "my_device".to_string(),
fs_type: "my_type".to_string(),
fs_mount: "my_mount".to_string(),
bytes: 100,
bytes_used: 25,
bytes_avail: 75,
bytes_usage: Some(0.251), bytes_usage: Some(0.251),
..Default::default()
#[cfg(target_os = "macos")]
bytes_capacity: Some(0.5),
inodes: 10,
inodes_used: 2,
inodes_free: 8,
inodes_usage: Some(0.2),
}; };
let fmt = RowFormatter::new(&row, &options); let fmt = RowFormatter::new(&row, &options);
assert_eq!( assert_eq!(fmt.get_values(), vec!("26%"));
fmt.get_values(),
vec!("my_device", "100", "25", "75", "26%", "my_mount")
);
} }
} }