mirror of
https://github.com/nushell/nushell
synced 2024-12-30 23:08:56 +00:00
3f0db11ae5
# Description Fixes https://github.com/nushell/nushell/issues/12968. After apply this patch, we can use explict plus sign character included string with `into filesize` cmd. # User-Facing Changes AS-IS (before fixing) ``` $ "+8 KiB" | into filesize Error: nu:🐚:cant_convert × Can't convert to int. ╭─[entry #31:1:1] 1 │ "+8 KiB" | into filesize · ────┬─── · ╰── can't convert string to int ╰──── ``` TO-BE (after fixing) ``` $ "+8KiB" | into filesize 8.0 KiB ``` # Tests + Formatting Added a test # 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. -->
119 lines
2.3 KiB
Rust
119 lines
2.3 KiB
Rust
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn into_filesize_int() {
|
|
let actual = nu!("1 | into filesize");
|
|
|
|
assert!(actual.out.contains("1 B"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_float() {
|
|
let actual = nu!("1.2 | into filesize");
|
|
|
|
assert!(actual.out.contains("1 B"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_str() {
|
|
let actual = nu!(r#"
|
|
'2000' | into filesize
|
|
"#);
|
|
|
|
assert!(actual.out.contains("2.0 KiB"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_str_newline() {
|
|
let actual = nu!(pipeline(
|
|
r#"
|
|
"2000
|
|
" | into filesize
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("2.0 KiB"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_str_many_newlines() {
|
|
let actual = nu!(pipeline(
|
|
r#"
|
|
"2000
|
|
|
|
" | into filesize
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("2.0 KiB"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_filesize() {
|
|
let actual = nu!("3kib | into filesize");
|
|
|
|
assert!(actual.out.contains("3.0 KiB"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_negative_filesize() {
|
|
let actual = nu!("-3kib | into filesize");
|
|
|
|
assert!(actual.out.contains("-3.0 KiB"));
|
|
}
|
|
|
|
#[test]
|
|
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"));
|
|
}
|
|
|
|
#[test]
|
|
fn into_filesize_negative_str() {
|
|
let actual = nu!("'-1' | into filesize");
|
|
|
|
assert!(actual.out.contains("-1 B"));
|
|
}
|
|
|
|
#[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"));
|
|
}
|
|
|
|
#[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"));
|
|
}
|