2022-12-22 15:46:55 +01:00
|
|
|
use nu_test_support::{nu, nu_repl_code};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesize_metric_true() {
|
|
|
|
let code = &[
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.config = { filesize: { metric: true, format:"mb" } }"#,
|
2022-12-22 15:46:55 +01:00
|
|
|
r#"20mib | into string"#,
|
|
|
|
];
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(nu_repl_code(code));
|
2022-12-22 15:46:55 +01:00
|
|
|
assert_eq!(actual.out, "21.0 MB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesize_metric_false() {
|
|
|
|
let code = &[
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.config = { filesize: { metric: false, format:"mib" } }"#,
|
2022-12-22 15:46:55 +01:00
|
|
|
r#"20mib | into string"#,
|
|
|
|
];
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(nu_repl_code(code));
|
2022-12-22 15:46:55 +01:00
|
|
|
assert_eq!(actual.out, "20.0 MiB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesize_metric_overrides_format() {
|
|
|
|
let code = &[
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.config = { filesize: { metric: false, format:"mb" } }"#,
|
2022-12-22 15:46:55 +01:00
|
|
|
r#"20mib | into string"#,
|
|
|
|
];
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(nu_repl_code(code));
|
2022-12-22 15:46:55 +01:00
|
|
|
assert_eq!(actual.out, "20.0 MiB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesize_format_auto_metric_true() {
|
|
|
|
let code = &[
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.config = { filesize: { metric: true, format:"auto" } }"#,
|
2022-12-22 15:46:55 +01:00
|
|
|
r#"[2mb 2gb 2tb] | into string | to nuon"#,
|
|
|
|
];
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(nu_repl_code(code));
|
2022-12-22 15:46:55 +01:00
|
|
|
assert_eq!(actual.out, r#"["2.0 MB", "2.0 GB", "2.0 TB"]"#);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn filesize_format_auto_metric_false() {
|
|
|
|
let code = &[
|
2023-06-30 21:57:51 +02:00
|
|
|
r#"$env.config = { filesize: { metric: false, format:"auto" } }"#,
|
2022-12-22 15:46:55 +01:00
|
|
|
r#"[2mb 2gb 2tb] | into string | to nuon"#,
|
|
|
|
];
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(nu_repl_code(code));
|
2022-12-22 15:46:55 +01:00
|
|
|
assert_eq!(actual.out, r#"["1.9 MiB", "1.9 GiB", "1.8 TiB"]"#);
|
|
|
|
}
|