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