nushell/crates/nu-protocol/tests/test_config.rs
Leon 5b616770df
Make config.filesize_format/config.filesize_metric conflict resolution consistent (#7410)
# Description

Currently, `filesize_format`/`filesize_metric` conflicts are resolved as
follows: if the `filesize_format` ends in "ib", then that overrides
`filesize_metric`, otherwise, `filesize_metric` overrides
`filesize_format`. This removes this difficult-to-predict asymmetric
behaviour, and makes it so that `filesize_metric` always overrides
`filesize_format`.

This also adds tests for `$env.config.filesize.format` and
`$env.config.filesize.metric` values.

REMINDER: `filesize_metric` means "increments of 1000", and refers to
KB-MB-GB-TB etc.

# User-Facing Changes

See above.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2022-12-22 08:46:55 -06:00

52 lines
1.5 KiB
Rust

use nu_test_support::{nu, nu_repl_code};
#[test]
fn filesize_metric_true() {
let code = &[
r#"let-env config = { filesize: { metric: true, format:"mb" } }"#,
r#"20mib | into string"#,
];
let actual = nu!(cwd: ".", nu_repl_code( code ));
assert_eq!(actual.out, "21.0 MB");
}
#[test]
fn filesize_metric_false() {
let code = &[
r#"let-env config = { filesize: { metric: false, format:"mib" } }"#,
r#"20mib | into string"#,
];
let actual = nu!(cwd: ".", nu_repl_code( code ));
assert_eq!(actual.out, "20.0 MiB");
}
#[test]
fn filesize_metric_overrides_format() {
let code = &[
r#"let-env config = { filesize: { metric: false, format:"mb" } }"#,
r#"20mib | into string"#,
];
let actual = nu!(cwd: ".", nu_repl_code( code ));
assert_eq!(actual.out, "20.0 MiB");
}
#[test]
fn filesize_format_auto_metric_true() {
let code = &[
r#"let-env config = { filesize: { metric: true, format:"auto" } }"#,
r#"[2mb 2gb 2tb] | into string | to nuon"#,
];
let actual = nu!(cwd: ".", nu_repl_code( code ));
assert_eq!(actual.out, r#"["2.0 MB", "2.0 GB", "2.0 TB"]"#);
}
#[test]
fn filesize_format_auto_metric_false() {
let code = &[
r#"let-env config = { filesize: { metric: false, format:"auto" } }"#,
r#"[2mb 2gb 2tb] | into string | to nuon"#,
];
let actual = nu!(cwd: ".", nu_repl_code( code ));
assert_eq!(actual.out, r#"["1.9 MiB", "1.9 GiB", "1.8 TiB"]"#);
}