diff --git a/crates/nu-command/tests/commands/match_.rs b/crates/nu-command/tests/commands/match_.rs index c03eed5f4f..b37d4a32e2 100644 --- a/crates/nu-command/tests/commands/match_.rs +++ b/crates/nu-command/tests/commands/match_.rs @@ -1,4 +1,6 @@ use nu_test_support::nu; +use nu_test_support::playground::Playground; +use std::fs; #[test] fn match_for_range() { @@ -226,3 +228,40 @@ fn match_with_guard_no_expr_after_if() { assert!(actual.err.contains("Match guard without an expression")); } + +#[test] +fn match_with_comment_1() { + Playground::setup("match_with_comment", |dirs, _| { + let data = r#" +match 1 { + # comment + _ => { print 'success' } +} + "#; + fs::write(dirs.root().join("match_test"), data).expect("Unable to write file"); + let actual = nu!( + cwd: dirs.root(), + "source match_test" + ); + + assert_eq!(actual.out, "success"); + }); +} + +#[test] +fn match_with_comment_2() { + Playground::setup("match_with_comment", |dirs, _| { + let data = r#" +match 1 { + _ => { print 'success' } # comment +} + "#; + fs::write(dirs.root().join("match_test"), data).expect("Unable to write file"); + let actual = nu!( + cwd: dirs.root(), + "source match_test" + ); + + assert_eq!(actual.out, "success"); + }); +} diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index ef1955c6e4..d13b21e7a0 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -4177,7 +4177,7 @@ pub fn parse_match_block_expression(working_set: &mut StateWorkingSet, span: Spa let source = working_set.get_span_contents(inner_span); - let (output, err) = lex(source, start, &[b' ', b'\r', b'\n', b',', b'|'], &[], false); + let (output, err) = lex(source, start, &[b' ', b'\r', b'\n', b',', b'|'], &[], true); if let Some(err) = err { working_set.error(err); }