mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
small refactoring around units and add tests (#15746)
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 ```
This commit is contained in:
15
crates/nu-command/tests/string/format/duration.rs
Normal file
15
crates/nu-command/tests/string/format/duration.rs
Normal file
@ -0,0 +1,15 @@
|
||||
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"));
|
||||
}
|
Reference in New Issue
Block a user