1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

df: implement Default for Row for unit tests

This commit is contained in:
Daniel Hofstetter 2022-05-04 16:11:03 +02:00
parent f6b9d36891
commit 00a3ec2d1f

View file

@ -446,6 +446,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();
@ -565,9 +589,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,
@ -575,13 +597,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!(
@ -598,7 +614,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(),
@ -608,13 +623,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!(
@ -631,23 +640,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!(
@ -664,23 +665,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"));
@ -694,7 +681,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(),
@ -704,13 +690,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!(
@ -735,7 +715,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(),
@ -745,13 +724,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!(
@ -771,32 +744,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")
);
} }
} }