mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:36:08 +02:00
allow raw string to be used inside subexpression, list, and closure (#12776)
# Description Fixes: #12744 This pr is moving raw string lex logic into `lex_item` function, so we can use raw string inside subexpression, list, closure. ```nushell > [r#'abc'#] ╭───┬─────╮ │ 0 │ abc │ ╰───┴─────╯ > (r#'abc'#) abc > do {r#'aa'#} aa ``` # Tests + Formatting Done # After Submitting NaN
This commit is contained in:
@ -87,6 +87,72 @@ fn raw_string() -> TestResult {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_string_inside_parentheses() -> TestResult {
|
||||
let (left, right) = ('(', ')');
|
||||
run_test(
|
||||
&format!(r#"{left}r#'abcde""fghi"''''jkl'#{right}"#),
|
||||
r#"abcde""fghi"''''jkl"#,
|
||||
)?;
|
||||
run_test(
|
||||
&format!(r#"{left}r##'abcde""fghi"''''#jkl'##{right}"#),
|
||||
r#"abcde""fghi"''''#jkl"#,
|
||||
)?;
|
||||
run_test(
|
||||
&format!(r#"{left}r###'abcde""fghi"'''##'#jkl'###{right}"#),
|
||||
r#"abcde""fghi"'''##'#jkl"#,
|
||||
)?;
|
||||
run_test(&format!("{left}r#''#{right}"), "")?;
|
||||
run_test(
|
||||
&format!(r#"{left}r#'a string with sharp inside # and ends with #'#{right}"#),
|
||||
"a string with sharp inside # and ends with #",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_string_inside_list() -> TestResult {
|
||||
let (left, right) = ('[', ']');
|
||||
run_test(
|
||||
&format!(r#"{left}r#'abcde""fghi"''''jkl'#{right} | get 0"#),
|
||||
r#"abcde""fghi"''''jkl"#,
|
||||
)?;
|
||||
run_test(
|
||||
&format!(r#"{left}r##'abcde""fghi"''''#jkl'##{right} | get 0"#),
|
||||
r#"abcde""fghi"''''#jkl"#,
|
||||
)?;
|
||||
run_test(
|
||||
&format!(r#"{left}r###'abcde""fghi"'''##'#jkl'###{right} | get 0"#),
|
||||
r#"abcde""fghi"'''##'#jkl"#,
|
||||
)?;
|
||||
run_test(&format!("{left}r#''#{right} | get 0"), "")?;
|
||||
run_test(
|
||||
&format!(r#"{left}r#'a string with sharp inside # and ends with #'#{right} | get 0"#),
|
||||
"a string with sharp inside # and ends with #",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_string_inside_closure() -> TestResult {
|
||||
let (left, right) = ('{', '}');
|
||||
run_test(
|
||||
&format!(r#"do {left}r#'abcde""fghi"''''jkl'#{right}"#),
|
||||
r#"abcde""fghi"''''jkl"#,
|
||||
)?;
|
||||
run_test(
|
||||
&format!(r#"do {left}r##'abcde""fghi"''''#jkl'##{right}"#),
|
||||
r#"abcde""fghi"''''#jkl"#,
|
||||
)?;
|
||||
run_test(
|
||||
&format!(r#"do {left}r###'abcde""fghi"'''##'#jkl'###{right}"#),
|
||||
r#"abcde""fghi"'''##'#jkl"#,
|
||||
)?;
|
||||
run_test(&format!("do {left}r#''#{right}"), "")?;
|
||||
run_test(
|
||||
&format!(r#"do {left}r#'a string with sharp inside # and ends with #'#{right}"#),
|
||||
"a string with sharp inside # and ends with #",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_raw_string() -> TestResult {
|
||||
fail_test("r#abc", "expected '")
|
||||
|
Reference in New Issue
Block a user