mirror of
https://github.com/nushell/nushell.git
synced 2025-05-19 17:30:45 +02:00
Closes #14469 # Description - ~~Implement the ``--unit`` conversion in "into int" command~~ - New ``ShellError::InvalidUnit`` unit if users enter wrong units - Made ``ShellError::CantConvertToDuration`` more generic: became ``CantConvertToUnit`` - Tried to improve the way we parse units and get the supported units. It's not complete, though, I will continue this refactoring in another PR. But I already did some small refactorings in the "format duration" and "format filesize" commands - Add tests for "format filesize" and "format duration" # User-Facing Changes ```nu ~> 1MB | format filesize sec Error: nu:🐚:invalid_unit × Invalid unit ╭─[entry #7:1:23] 1 │ 1MB | format filesize sec · ─┬─ · ╰── encountered here ╰──── help: Supported units are: B, kB, MB, GB, TB, PB, EB, KiB, MiB, GiB, TiB, PiB, EiB ```
16 lines
310 B
Rust
16 lines
310 B
Rust
use nu_test_support::nu;
|
|
|
|
#[test]
|
|
fn format_duration() {
|
|
let actual = nu!(r#"1hr | format duration sec"#);
|
|
|
|
assert_eq!("3600 sec", actual.out);
|
|
}
|
|
|
|
#[test]
|
|
fn format_duration_with_invalid_unit() {
|
|
let actual = nu!(r#"1hr | format duration MB"#);
|
|
|
|
assert!(actual.err.contains("invalid_unit"));
|
|
}
|