diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index ca23e6823b..1fcd1983e4 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -307,7 +307,6 @@ fn from_nuon_datetime() { } #[test] -#[ignore] fn to_nuon_errs_on_closure() { let actual = nu!(pipeline( r#" @@ -316,7 +315,19 @@ fn to_nuon_errs_on_closure() { "# )); - assert!(actual.err.contains("can't convert closure to NUON")); + assert!(actual.err.contains("not deserializable")); +} + +#[test] +fn to_nuon_closure_coerced_to_quoted_string() { + let actual = nu!(pipeline( + r#" + {|| to nuon} + | to nuon --serialize + "# + )); + + assert_eq!(actual.out, "\"{|| to nuon}\""); } #[test] diff --git a/crates/nuon/src/to.rs b/crates/nuon/src/to.rs index e7ed06c461..fae454cd9a 100644 --- a/crates/nuon/src/to.rs +++ b/crates/nuon/src/to.rs @@ -99,7 +99,9 @@ fn value_to_string( } Value::Closure { val, .. } => { if serialize_types { - Ok(val.coerce_into_string(engine_state, span)?.to_string()) + Ok(escape_quote_string( + &val.coerce_into_string(engine_state, span)?, + )) } else { Err(ShellError::UnsupportedInput { msg: "closures are currently not deserializable (use --serialize to serialize as a string)".into(), diff --git a/tests/eval/mod.rs b/tests/eval/mod.rs index db954df231..736d4a1af9 100644 --- a/tests/eval/mod.rs +++ b/tests/eval/mod.rs @@ -108,7 +108,7 @@ fn literal_closure() { #[test] fn literal_closure_to_nuon() { - test_eval("{||} | to nuon --serialize", Eq("{||}")) + test_eval("{||} | to nuon --serialize", Eq("\"{||}\"")) } #[test]