mirror of
https://github.com/nushell/nushell.git
synced 2024-11-15 04:54:46 +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 {
|
||||
match input {
|
||||
Value::Filesize { .. } => input.clone(),
|
||||
Value::Int { val, .. } => Value::Filesize { val: *val, span },
|
||||
Value::Float { val, .. } => Value::Filesize {
|
||||
val: *val as i64,
|
||||
span,
|
||||
},
|
||||
Value::String { val, .. } => match int_from_string(val, span) {
|
||||
Ok(val) => Value::Filesize { val, span },
|
||||
Err(error) => Value::Error { error },
|
||||
},
|
||||
_ => Value::Error {
|
||||
if let Ok(value_span) = input.span() {
|
||||
match input {
|
||||
Value::Filesize { .. } => input.clone(),
|
||||
Value::Int { val, .. } => Value::Filesize {
|
||||
val: *val,
|
||||
span: value_span,
|
||||
},
|
||||
Value::Float { val, .. } => Value::Filesize {
|
||||
val: *val as i64,
|
||||
span: value_span,
|
||||
},
|
||||
Value::String { val, .. } => match int_from_string(val, value_span) {
|
||||
Ok(val) => Value::Filesize {
|
||||
val,
|
||||
span: value_span,
|
||||
},
|
||||
Err(error) => Value::Error { error },
|
||||
},
|
||||
_ => Value::Error {
|
||||
error: ShellError::UnsupportedInput(
|
||||
"'into filesize' for unsupported type".into(),
|
||||
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> {
|
||||
match a_string.parse::<bytesize::ByteSize>() {
|
||||
match a_string.trim().parse::<bytesize::ByteSize>() {
|
||||
Ok(n) => Ok(n.0 as i64),
|
||||
Err(_) => Err(ShellError::CantConvert("int".into(), "string".into(), span)),
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ fn into_filesize_str() {
|
||||
assert!(actual.out.contains("2.0 KiB"));
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn into_filesize_str_newline() {
|
||||
let actual = nu!(
|
||||
@ -51,8 +49,6 @@ fn into_filesize_str_newline() {
|
||||
assert!(actual.out.contains("2.0 KiB"));
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn into_filesize_str_many_newlines() {
|
||||
let actual = nu!(
|
||||
|
Loading…
Reference in New Issue
Block a user