From 83674909f18c6c7f680c429f4e439a5de951996f Mon Sep 17 00:00:00 2001 From: Texas Toland Date: Wed, 10 Apr 2024 09:28:54 -0500 Subject: [PATCH] Lex whitespace in input-output types. (#12339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Fixes #12264. # User-Facing Changes Multiple input-output types can break across lines like command params. # Tests + Formatting ✅ E2E parser tests --- crates/nu-parser/src/parser.rs | 3 ++- src/tests/test_parser.rs | 35 +++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 79c4cc73b9..a665c24805 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -3041,7 +3041,8 @@ pub fn parse_input_output_types( full_span.end -= 1; } - let (tokens, parse_error) = lex_signature(bytes, full_span.start, &[b','], &[], true); + let (tokens, parse_error) = + lex_signature(bytes, full_span.start, &[b'\n', b'\r', b','], &[], true); if let Some(parse_error) = parse_error { working_set.parse_errors.push(parse_error); diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 83fc7aa339..241aaccecf 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -657,12 +657,41 @@ fn let_variable_disallows_completer() -> TestResult { } #[test] -fn def_with_input_output_1() -> TestResult { +fn def_with_input_output() -> TestResult { run_test(r#"def foo []: nothing -> int { 3 }; foo"#, "3") } #[test] -fn def_with_input_output_2() -> TestResult { +fn def_with_input_output_with_line_breaks() -> TestResult { + run_test( + r#"def foo []: [ + nothing -> int + ] { 3 }; foo"#, + "3", + ) +} + +#[test] +fn def_with_multi_input_output_with_line_breaks() -> TestResult { + run_test( + r#"def foo []: [ + nothing -> int + string -> int + ] { 3 }; foo"#, + "3", + ) +} + +#[test] +fn def_with_multi_input_output_without_commas() -> TestResult { + run_test( + r#"def foo []: [nothing -> int string -> int] { 3 }; foo"#, + "3", + ) +} + +#[test] +fn def_with_multi_input_output_called_with_first_sig() -> TestResult { run_test( r#"def foo []: [int -> int, string -> int] { 3 }; 10 | foo"#, "3", @@ -670,7 +699,7 @@ fn def_with_input_output_2() -> TestResult { } #[test] -fn def_with_input_output_3() -> TestResult { +fn def_with_multi_input_output_called_with_second_sig() -> TestResult { run_test( r#"def foo []: [int -> int, string -> int] { 3 }; "bob" | foo"#, "3",