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:
commit
a711597619
1 changed files with 34 additions and 79 deletions
|
@ -449,6 +449,30 @@ mod tests {
|
|||
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]
|
||||
fn test_default_header() {
|
||||
let options = Default::default();
|
||||
|
@ -568,9 +592,7 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
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,
|
||||
|
@ -578,13 +600,7 @@ mod tests {
|
|||
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),
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(
|
||||
|
@ -601,7 +617,6 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
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(),
|
||||
|
@ -611,13 +626,7 @@ mod tests {
|
|||
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),
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(
|
||||
|
@ -634,23 +643,15 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
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.25),
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
bytes_capacity: Some(0.5),
|
||||
|
||||
inodes: 10,
|
||||
inodes_used: 2,
|
||||
inodes_free: 8,
|
||||
inodes_usage: Some(0.2),
|
||||
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(
|
||||
|
@ -667,23 +668,9 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
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.25),
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
bytes_capacity: Some(0.5),
|
||||
|
||||
inodes: 10,
|
||||
inodes_used: 2,
|
||||
inodes_free: 8,
|
||||
inodes_usage: Some(0.2),
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(fmt.get_values(), vec!("1", "10"));
|
||||
|
@ -697,7 +684,6 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
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(),
|
||||
|
@ -707,13 +693,7 @@ mod tests {
|
|||
bytes_avail: 3000,
|
||||
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),
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(
|
||||
|
@ -738,7 +718,6 @@ mod tests {
|
|||
..Default::default()
|
||||
};
|
||||
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(),
|
||||
|
@ -748,13 +727,7 @@ mod tests {
|
|||
bytes_avail: 3072,
|
||||
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),
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(
|
||||
|
@ -774,32 +747,14 @@ mod tests {
|
|||
#[test]
|
||||
fn test_row_formatter_with_round_up_usage() {
|
||||
let options = Options {
|
||||
block_size: BlockSize::Bytes(1),
|
||||
columns: vec![Column::Pcent],
|
||||
..Default::default()
|
||||
};
|
||||
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),
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
bytes_capacity: Some(0.5),
|
||||
|
||||
inodes: 10,
|
||||
inodes_used: 2,
|
||||
inodes_free: 8,
|
||||
inodes_usage: Some(0.2),
|
||||
..Default::default()
|
||||
};
|
||||
let fmt = RowFormatter::new(&row, &options);
|
||||
assert_eq!(
|
||||
fmt.get_values(),
|
||||
vec!("my_device", "100", "25", "75", "26%", "my_mount")
|
||||
);
|
||||
assert_eq!(fmt.get_values(), vec!("26%"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue