mirror of
https://github.com/nushell/nushell.git
synced 2025-01-31 18:49:26 +01:00
fix into filesize tests and filesize (#932)
* fix into filesize tests and filesize * tweaks * added span back for like the 10th time * Update filesize.rs Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This commit is contained in:
parent
fefd5fef12
commit
ece1e43238
@ -111,27 +111,42 @@ fn into_filesize(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn action(input: &Value, span: Span) -> Value {
|
pub fn action(input: &Value, span: Span) -> Value {
|
||||||
|
if let Ok(value_span) = input.span() {
|
||||||
match input {
|
match input {
|
||||||
Value::Filesize { .. } => input.clone(),
|
Value::Filesize { .. } => input.clone(),
|
||||||
Value::Int { val, .. } => Value::Filesize { val: *val, span },
|
Value::Int { val, .. } => Value::Filesize {
|
||||||
|
val: *val,
|
||||||
|
span: value_span,
|
||||||
|
},
|
||||||
Value::Float { val, .. } => Value::Filesize {
|
Value::Float { val, .. } => Value::Filesize {
|
||||||
val: *val as i64,
|
val: *val as i64,
|
||||||
span,
|
span: value_span,
|
||||||
|
},
|
||||||
|
Value::String { val, .. } => match int_from_string(val, value_span) {
|
||||||
|
Ok(val) => Value::Filesize {
|
||||||
|
val,
|
||||||
|
span: value_span,
|
||||||
},
|
},
|
||||||
Value::String { val, .. } => match int_from_string(val, span) {
|
|
||||||
Ok(val) => Value::Filesize { val, span },
|
|
||||||
Err(error) => Value::Error { error },
|
Err(error) => Value::Error { error },
|
||||||
},
|
},
|
||||||
_ => Value::Error {
|
_ => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
error: ShellError::UnsupportedInput(
|
||||||
"'into filesize' for unsupported type".into(),
|
"'into filesize' for unsupported type".into(),
|
||||||
span,
|
value_span,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Value::Error {
|
||||||
|
error: ShellError::UnsupportedInput(
|
||||||
|
"'into filesize' for unsupported type".into(),
|
||||||
|
span,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
|
||||||
match a_string.parse::<bytesize::ByteSize>() {
|
match a_string.trim().parse::<bytesize::ByteSize>() {
|
||||||
Ok(n) => Ok(n.0 as i64),
|
Ok(n) => Ok(n.0 as i64),
|
||||||
Err(_) => Err(ShellError::CantConvert("int".into(), "string".into(), span)),
|
Err(_) => Err(ShellError::CantConvert("int".into(), "string".into(), span)),
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,6 @@ fn into_filesize_str() {
|
|||||||
assert!(actual.out.contains("2.0 KiB"));
|
assert!(actual.out.contains("2.0 KiB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: jt: needs more work
|
|
||||||
#[ignore]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_str_newline() {
|
fn into_filesize_str_newline() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -51,8 +49,6 @@ fn into_filesize_str_newline() {
|
|||||||
assert!(actual.out.contains("2.0 KiB"));
|
assert!(actual.out.contains("2.0 KiB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: jt: needs more work
|
|
||||||
#[ignore]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn into_filesize_str_many_newlines() {
|
fn into_filesize_str_many_newlines() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
|
Loading…
Reference in New Issue
Block a user