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"));
|
|
|
|
}
|
2024-04-07 18:50:11 +02:00
|
|
|
|
|
|
|
#[test]
|
2024-06-05 01:43:50 +02:00
|
|
|
fn into_filesize_negative_str_filesize() {
|
|
|
|
let actual = nu!("'-3kib' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.out.contains("-3.0 KiB"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_wrong_negative_str_filesize() {
|
|
|
|
let actual = nu!("'--3kib' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("can't convert string to filesize"));
|
|
|
|
}
|
|
|
|
|
2024-06-10 04:43:17 +02:00
|
|
|
#[test]
|
|
|
|
fn into_filesize_large_negative_str_filesize() {
|
|
|
|
let actual = nu!("'-10000PiB' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("can't convert string to filesize"));
|
|
|
|
}
|
|
|
|
|
2024-06-05 01:43:50 +02:00
|
|
|
#[test]
|
|
|
|
fn into_filesize_negative_str() {
|
2024-04-07 18:50:11 +02:00
|
|
|
let actual = nu!("'-1' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.out.contains("-1 B"));
|
|
|
|
}
|
2024-06-05 01:43:50 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_wrong_negative_str() {
|
|
|
|
let actual = nu!("'--1' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("can't convert string to filesize"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_positive_str_filesize() {
|
|
|
|
let actual = nu!("'+1Kib' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.out.contains("1.0 KiB"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_wrong_positive_str_filesize() {
|
|
|
|
let actual = nu!("'++1Kib' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("can't convert string to filesize"));
|
|
|
|
}
|
|
|
|
|
2024-06-10 04:43:17 +02:00
|
|
|
#[test]
|
|
|
|
fn into_filesize_large_positive_str_filesize() {
|
|
|
|
let actual = nu!("'+10000PiB' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("can't convert string to filesize"));
|
|
|
|
}
|
|
|
|
|
2024-06-05 01:43:50 +02:00
|
|
|
#[test]
|
|
|
|
fn into_filesize_positive_str() {
|
|
|
|
let actual = nu!("'+1' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.out.contains("1 B"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn into_filesize_wrong_positive_str() {
|
|
|
|
let actual = nu!("'++1' | into filesize");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("can't convert string to filesize"));
|
|
|
|
}
|