Skip to content

Commit e93cd97

Browse files
committed
Split tests into separate cases
This splits two unit tests that were testing multiple cases in one go into multiple unit tests - one per each case. Note, that original tests were expecting an accurate error for each of multiple lines of malformed string literals. They would no longer pass with changes introduced by previous commits in this PR.
1 parent e2f4bfe commit e93cd97

File tree

1 file changed

+40
-60
lines changed

1 file changed

+40
-60
lines changed

tests/fsharp/Compiler/Language/StringInterpolation.fs

+40-60
Original file line numberDiff line numberDiff line change
@@ -730,70 +730,50 @@ let x3 : FormattableString = $"one %10s{String.Empty}" // no %10s in Formattable
730730
(FSharpDiagnosticSeverity.Error, 3376, (6, 30, 6, 55),
731731
"Invalid interpolated string. Interpolated strings used as type IFormattable or type FormattableString may not use '%' specifiers, only .NET-style interpolands such as '{expr}', '{expr,3}' or '{expr:N5}' may be used.")|]
732732

733-
734-
[<Test>]
735-
let ``String interpolation negative nested in single`` () =
736-
let code = """
737-
738-
open System
739-
let s1 = $"123{456}789{"012"}345"
740-
let s2 = $"123{456}789{@"012"}345"
741-
let s3 = $"123{456}789{$"012"}345"
742-
let s4 = $@"123{456}789{"012"}345"
743-
let s5 = @$"123{456}789{"012"}345"
744-
let s6 = $@"123{456}789{@"012"}345"
745-
let s7 = @$"123{456}789{$"012"}345"
746-
let s8 = $@"123{456}789{@$"012"}345"
747-
let s9 = @$"123{456}789{$@"012"}345"
748-
"""
749-
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:5.0" |]
733+
[<TestCase("""let s1 = $"123{456}789{""", "\"012\"", "}345\"")>]
734+
[<TestCase("""let s2 = $"123{456}789{""", "@\"012\"", "}345\"")>]
735+
[<TestCase("""let s3 = $"123{456}789{""", "$\"012\"", "}345\"")>]
736+
[<TestCase("""let s4 = $@"123{456}789{""", "\"012\"", "}345\"")>]
737+
[<TestCase("""let s5 = @$"123{456}789{""", "\"012\"", "}345\"")>]
738+
[<TestCase("""let s6 = $@"123{456}789{""", "@\"012\"", "}345\"")>]
739+
[<TestCase("""let s7 = @$"123{456}789{""", "$\"012\"", "}345\"")>]
740+
[<TestCase("""let s8 = $@"123{456}789{""", "@$\"012\"", "}345\"")>]
741+
[<TestCase("""let s9 = @$"123{456}789{""", "$@\"012\"", "}345\"")>]
742+
let ``String interpolation negative nested in single`` ((part1: string, expr: string, part2: string)) =
743+
let code = part1 + expr + part2
744+
let exprPosBegin = 1 + part1.Length
745+
let quotePosInExpr = exprPosBegin + (expr |> Seq.findIndex (fun c -> c = '"'))
746+
let closingBracePos = exprPosBegin + expr.Length
747+
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:5.0" |]
750748
code
751-
[|(FSharpDiagnosticSeverity.Error, 3373, (4, 24, 4, 25),
752-
"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.");
753-
(FSharpDiagnosticSeverity.Error, 3373, (5, 24, 5, 26),
754-
"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.");
755-
(FSharpDiagnosticSeverity.Error, 3373, (6, 24, 6, 26),
756-
"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.");
757-
(FSharpDiagnosticSeverity.Error, 3373, (7, 25, 7, 26),
758-
"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.");
759-
(FSharpDiagnosticSeverity.Error, 3373, (8, 25, 8, 26),
760-
"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.");
761-
(FSharpDiagnosticSeverity.Error, 3373, (9, 25, 9, 27),
762-
"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.");
763-
(FSharpDiagnosticSeverity.Error, 3373, (10, 25, 10, 27),
764-
"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.");
765-
(FSharpDiagnosticSeverity.Error, 3373, (11, 25, 11, 28),
766-
"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.");
767-
(FSharpDiagnosticSeverity.Error, 3373, (12, 25, 12, 28),
768-
"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.")|]
769-
770-
[<Test>]
771-
let ``String interpolation negative nested in triple`` () =
772-
let code = "
773-
774-
open System
775-
let TripleInTripleInterpolated = $\"\"\"123{456}789{\"\"\"012\"\"\"}345\"\"\"
776-
let TripleInSingleInterpolated = $\"123{456}789{\"\"\"012\"\"\"}345\"
777-
let TripleInVerbatimInterpolated = $\"123{456}789{\"\"\"012\"\"\"}345\"
778-
let TripleInterpolatedInTripleInterpolated = $\"\"\"123{456}789{$\"\"\"012\"\"\"}345\"\"\"
779-
let TripleInterpolatedInSingleInterpolated = $\"123{456}789{$\"\"\"012\"\"\"}345\"
780-
let TripleInterpolatedInVerbatimInterpolated = $\"123{456}789{$\"\"\"012\"\"\"}345\"
781-
"
749+
[|(FSharpDiagnosticSeverity.Error, 3373, (1, exprPosBegin, 1, quotePosInExpr + 1),
750+
"Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. \
751+
Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal.");
752+
(FSharpDiagnosticSeverity.Error, 10, (1, closingBracePos, 1, closingBracePos + 1),
753+
"Unexpected symbol '}' in binding. Expected interpolated string (final part), interpolated string (part) or other token.");
754+
(FSharpDiagnosticSeverity.Error, 514, (1, code.Length, 1, code.Length + 1), "End of file in string begun at or before here")|]
755+
756+
[<TestCase("let TripleInTripleInterpolated = $\"\"\"123{456}789{", "\"\"\"012\"\"\"", "}345\"\"\"")>]
757+
[<TestCase("let TripleInSingleInterpolated = $\"123{456}789{", "\"\"\"012\"\"\"", "}345\"\"\"")>]
758+
[<TestCase("let TripleInVerbatimInterpolated = @$\"123{456}789{", "\"\"\"012\"\"\"", "}345\"\"\"")>]
759+
[<TestCase("let TripleInterpolatedInTripleInterpolated = $\"\"\"123{456}789{", "$\"\"\"012\"\"\"", "}345\"\"\"")>]
760+
[<TestCase("let TripleInterpolatedInSingleInterpolated = $\"123{456}789{", "$\"\"\"012\"\"\"", "}345\"\"\"")>]
761+
[<TestCase("let TripleInterpolatedInVerbatimInterpolated = @$\"123{456}789{", "$\"\"\"012\"\"\"", "}345\"\"\"")>]
762+
let ``String interpolation negative nested in triple`` ((part1: string, expr: string, part2: string)) =
763+
let code = part1 + expr + part2
764+
let exprPosBegin = 1 + part1.Length
765+
let exprOpenQuoteEnd = exprPosBegin + 3 + (expr |> Seq.takeWhile (fun c -> c <> '"') |> Seq.length)
766+
let closingBracePos = exprPosBegin + expr.Length
767+
let closingQuotePos = code.Length + 1 - 3
782768
CompilerAssert.TypeCheckWithErrorsAndOptions [| "--langversion:5.0" |]
783769
code
784-
[|(FSharpDiagnosticSeverity.Error, 3374, (4, 52, 4, 55),
785-
"Invalid interpolated string. Triple quote string literals may not be used in interpolated expressions. Consider using an explicit 'let' binding for the interpolation expression.");
786-
(FSharpDiagnosticSeverity.Error, 3374, (5, 50, 5, 53),
787-
"Invalid interpolated string. Triple quote string literals may not be used in interpolated expressions. Consider using an explicit 'let' binding for the interpolation expression.");
788-
(FSharpDiagnosticSeverity.Error, 3374, (6, 50, 6, 53),
770+
[|(FSharpDiagnosticSeverity.Error, 3374, (1, exprPosBegin, 1, exprOpenQuoteEnd),
789771
"Invalid interpolated string. Triple quote string literals may not be used in interpolated expressions. Consider using an explicit 'let' binding for the interpolation expression.");
790-
(FSharpDiagnosticSeverity.Error, 3374, (7, 64, 7, 68),
791-
"Invalid interpolated string. Triple quote string literals may not be used in interpolated expressions. Consider using an explicit 'let' binding for the interpolation expression.");
792-
(FSharpDiagnosticSeverity.Error, 3374, (8, 62, 8, 66),
793-
"Invalid interpolated string. Triple quote string literals may not be used in interpolated expressions. Consider using an explicit 'let' binding for the interpolation expression.");
794-
(FSharpDiagnosticSeverity.Error, 3374, (9, 62, 9, 66),
795-
"Invalid interpolated string. Triple quote string literals may not be used in interpolated expressions. Consider using an explicit 'let' binding for the interpolation expression.")|]
796-
772+
(FSharpDiagnosticSeverity.Error, 10, (1, closingBracePos, 1, closingBracePos + 1),
773+
"Unexpected symbol '}' in binding. Expected interpolated string (final part), interpolated string (part) or other token.");
774+
(FSharpDiagnosticSeverity.Error, 1232, (1, closingQuotePos, 1, closingQuotePos + 3),
775+
"End of file in triple-quote string begun at or before here")|]
776+
797777
[<Test>]
798778
let ``String interpolation negative incomplete string`` () =
799779
let code = """let x1 = $"one %d{System.String.Empty}"""

0 commit comments

Comments
 (0)