From e2f4bfe0cf72f5f36aa55e90a1345da94015176c Mon Sep 17 00:00:00 2001 From: Adam Boniecki Date: Thu, 3 Nov 2022 16:27:29 +0100 Subject: [PATCH] Add tests for unmatched curly brace Two tests for unmatched curly brace in interpolated string --- .../Compiler/Language/StringInterpolation.fs | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/fsharp/Compiler/Language/StringInterpolation.fs b/tests/fsharp/Compiler/Language/StringInterpolation.fs index 367f4997d858..52a76921fa4a 100644 --- a/tests/fsharp/Compiler/Language/StringInterpolation.fs +++ b/tests/fsharp/Compiler/Language/StringInterpolation.fs @@ -803,9 +803,9 @@ let TripleInterpolatedInVerbatimInterpolated = $\"123{456}789{$\"\"\"012\"\"\"}3 "Incomplete structured construct at or before this point in binding. Expected interpolated string (final part), interpolated string (part) or other token."); (FSharpDiagnosticSeverity.Error, 3379, (1, 38, 1, 39), "Incomplete interpolated string begun at or before here")|] - + [] - let ``String interpolation negative incomplete string fill`` () = + let ``String interpolation negative incomplete string with incomplete fill`` () = let code = """let x1 = $"one %d{System.String.Empty""" CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:5.0" |] code @@ -813,7 +813,36 @@ let TripleInterpolatedInVerbatimInterpolated = $\"123{456}789{$\"\"\"012\"\"\"}3 "Incomplete structured construct at or before this point in binding. Expected interpolated string (final part), interpolated string (part) or other token."); (FSharpDiagnosticSeverity.Error, 3378, (1, 18, 1, 19), "Incomplete interpolated string expression fill begun at or before here")|] - + + [] + let ``String interpolation negative incomplete fill`` () = + let code = "let x1 = $\"one %d{System.String.Empty\"" + CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:5.0" |] + code + [|(FSharpDiagnosticSeverity.Error, 3373, (1, 38, 1, 39), + "Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. \ + Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal."); + (FSharpDiagnosticSeverity.Error, 10, (1, 1, 1, 39), + "Incomplete structured construct at or before this point in binding. Expected interpolated string (final part), interpolated string (part) or other token."); + (FSharpDiagnosticSeverity.Error, 514, (1, 38, 1, 39), + "End of file in string begun at or before here")|] + + [] + let ``String interpolation negative incomplete fill with another valid string`` () = + let code = """ +let x1 = $"one %d{System.String.Empty" +let x2 = "any old string" +""" + CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:5.0" |] + code + [|(FSharpDiagnosticSeverity.Error, 3373, (2, 38, 2, 39), + "Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. \ + Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal."); + (FSharpDiagnosticSeverity.Error, 10, (4, 1, 4, 1), + "Incomplete structured construct at or before this point in binding. Expected interpolated string (final part), interpolated string (part) or other token."); + (FSharpDiagnosticSeverity.Error, 514, (3, 25, 3, 26), + "End of file in string begun at or before here")|] + [] let ``String interpolation negative incomplete verbatim string`` () = let code = """let x1 = @$"one %d{System.String.Empty} """