Update string interpolation tests

This commit is contained in:
Richard Feldman 2023-07-29 18:13:03 -04:00
parent 009e6f911a
commit 1ffadb7102
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
2 changed files with 83 additions and 25 deletions

View file

@ -1322,3 +1322,79 @@ fn ordered_tag_union_memory_layout() {
r#"Height 1 { column: 3, line: 2 } : Node"#, r#"Height 1 { column: 3, line: 2 } : Node"#,
); );
} }
#[test]
fn interpolation_with_nested_strings() {
expect_success(
indoc!(
r#"
"foo \(Str.joinWith ["a", "b", "c"] ", ") bar"
"#
),
r#""foo a, b, c bar" : Str"#,
);
}
#[test]
fn interpolation_with_num_to_str() {
expect_success(
indoc!(
r#"
"foo \(Num.toStr Num.maxI8) bar"
"#
),
r#""foo 127 bar" : Str"#,
);
}
#[test]
fn interpolation_with_operator_desugaring() {
expect_success(
indoc!(
r#"
"foo \(Num.toStr (1 + 2)) bar"
"#
),
r#""foo 3 bar" : Str"#,
);
}
#[test]
fn interpolation_with_nested_interpolation() {
expect_failure(
indoc!(
r#"
"foo \(Str.joinWith ["a\(Num.toStr 5)", "b"] "c")"
"#
),
indoc!(
r#"
SYNTAX PROBLEM
This string interpolation is invalid:
4 "foo \(Str.joinWith ["a\(Num.toStr 5)", "b"] "c")"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
String interpolation cannot contain newlines, comments, or nested
interpolations.
You can learn more about string interpolation at
<https://www.roc-lang.org/tutorial#string-interpolation>
Enter an expression to evaluate, or a definition (like x = 1) to use in future expressions.
Unless there was a compile-time error, expressions get automatically named so you can refer to them later.
For example, if you see # val1 after an output, you can now refer to that expression as val1 in future expressions.
Tips:
- ctrl-v + ctrl-j makes a newline
- :q to quit
- :help"#
),
);
}

View file

@ -5365,24 +5365,6 @@ Tab characters are not allowed."###,
"### "###
); );
test_report!(
interpolate_not_identifier,
r#""abc\(32)def""#,
@r###"
SYNTAX PROBLEM /code/proj/Main.roc
This string interpolation is invalid:
4 "abc\(32)def"
^^
I was expecting an identifier, like \u(message) or
\u(LoremIpsum.text).
Learn more about string interpolation at TODO
"###
);
test_report!( test_report!(
unicode_too_large, unicode_too_large,
r#""abc\u(110000)def""#, r#""abc\u(110000)def""#,