2021-09-03 01:19:54 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_int() {
|
2023-07-21 17:32:37 +02:00
|
|
|
let actual = nu!("1 | into filesize");
|
2021-09-03 01:19:54 +02:00
|
|
|
|
|
|
|
assert!(actual.out.contains("1 B"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn into_filesize_float() {
|
2023-07-21 17:32:37 +02:00
|
|
|
let actual = nu!("1.2 | into filesize");
|
2021-09-03 01:19:54 +02:00
|
|
|
|
|
|
|
assert!(actual.out.contains("1 B"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_str() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2021-09-03 01:19:54 +02:00
|
|
|
'2000' | into filesize
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2021-09-03 01:19:54 +02:00
|
|
|
|
2022-02-04 03:01:45 +01:00
|
|
|
assert!(actual.out.contains("2.0 KiB"));
|
2021-09-03 01:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_str_newline() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2021-09-03 01:19:54 +02:00
|
|
|
r#"
|
2022-02-04 03:01:45 +01:00
|
|
|
"2000
|
|
|
|
" | into filesize
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("2.0 KiB"));
|
2021-09-03 01:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_str_many_newlines() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2021-09-03 01:19:54 +02:00
|
|
|
r#"
|
2022-02-04 03:01:45 +01:00
|
|
|
"2000
|
|
|
|
|
|
|
|
" | into filesize
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("2.0 KiB"));
|
2021-09-03 01:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_filesize() {
|
2023-07-21 17:32:37 +02:00
|
|
|
let actual = nu!("3kib | into filesize");
|
2022-02-04 03:01:45 +01:00
|
|
|
|
|
|
|
assert!(actual.out.contains("3.0 KiB"));
|
2021-09-03 01:19:54 +02:00
|
|
|
}
|
2022-11-10 22:33:15 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_negative_filesize() {
|
2023-07-21 17:32:37 +02:00
|
|
|
let actual = nu!("-3kib | into filesize");
|
2022-11-10 22:33:15 +01:00
|
|
|
|
|
|
|
assert!(actual.out.contains("-3.0 KiB"));
|
|
|
|
}
|