From 8584aa79a2b61af379ffadeb82d1eed5367557bc Mon Sep 17 00:00:00 2001 From: tesla232 Date: Fri, 12 May 2023 12:57:50 -0400 Subject: [PATCH] Span fixes during duration conversion (#9143) Description: Fix of #8945. # Description # User-Facing Changes # Tests + Formatting # After Submitting --------- Co-authored-by: jpaldino --- crates/nu-command/src/conversions/into/duration.rs | 9 ++++++--- tests/parsing/mod.rs | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/conversions/into/duration.rs b/crates/nu-command/src/conversions/into/duration.rs index f7279dc1a..135157864 100644 --- a/crates/nu-command/src/conversions/into/duration.rs +++ b/crates/nu-command/src/conversions/into/duration.rs @@ -179,7 +179,10 @@ fn into_duration( call: &Call, input: PipelineData, ) -> Result { - let head = call.head; + let span = match input.span() { + Some(t) => t, + None => call.head, + }; let convert_to_unit: Option> = call.get_flag(engine_state, stack, "convert")?; let column_paths: Vec = call.rest(engine_state, stack, 0)?; let config = engine_state.get_config(); @@ -188,14 +191,14 @@ fn into_duration( input.map( move |v| { if column_paths.is_empty() { - action(&v, &convert_to_unit, float_precision, head) + action(&v, &convert_to_unit, float_precision, span) } else { let mut ret = v; for path in &column_paths { let d = convert_to_unit.clone(); let r = ret.update_cell_path( &path.members, - Box::new(move |old| action(old, &d, float_precision, head)), + Box::new(move |old| action(old, &d, float_precision, span)), ); if let Err(error) = r { return Value::Error { diff --git a/tests/parsing/mod.rs b/tests/parsing/mod.rs index 1fe9d845c..d31847ddb 100644 --- a/tests/parsing/mod.rs +++ b/tests/parsing/mod.rs @@ -238,3 +238,13 @@ fn call_command_with_non_ascii_argument() { assert_eq!(actual.err.len(), 0); } + +#[test] +fn parse_long_duration() { + let actual = nu!(cwd: "tests/parsing/samples", + r#" + "78.797877879789789sec" | into duration + "#); + + assert_eq!(actual.out, "1min 18sec 797ms"); +}