diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5df5b596..38eebc6e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,7 +54,7 @@ jobs: (cd Rewrite && dotnet build Rewrite.sln --no-restore) - name: test-cs if: "!startsWith(github.event.head_commit.message, '[lst-change]')" - run: (cd Rewrite && dotnet test Rewrite.sln --filter "Category!=KnownBug & Category!=Exploratory") + run: (cd Rewrite && dotnet test Rewrite.sln --filter "Category!=KnownBug & Category!=Exploratory & Category!=Roslyn") - name: publish-java-snapshots if: github.event_name != 'pull_request' diff --git a/Rewrite/Directory.Build.props b/Rewrite/Directory.Build.props index ee663f6a..e9143bfc 100644 --- a/Rewrite/Directory.Build.props +++ b/Rewrite/Directory.Build.props @@ -10,6 +10,7 @@ openrewrite.png Apache-2.0 0.9.1 + ..\..\..\..\..\moderneinc\rewrite-remote\Rewrite.Remote True False True diff --git a/Rewrite/Rewrite.Sources.sln b/Rewrite/Rewrite.Sources.sln new file mode 100644 index 00000000..855a5d32 --- /dev/null +++ b/Rewrite/Rewrite.Sources.sln @@ -0,0 +1,130 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Core", "src\Rewrite.Core\Rewrite.Core.csproj", "{FB30394C-7930-4BFF-97E2-400CFADE92C2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Properties", "src\Rewrite.Properties\Rewrite.Properties.csproj", "{C7E280C5-E841-4690-8AA3-653ECBC7C78B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Yaml", "src\Rewrite.Yaml\Rewrite.Yaml.csproj", "{F7F4F27F-2CAE-422B-B6CE-25A88C3603A1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Xml", "src\Rewrite.Xml\Rewrite.Xml.csproj", "{D38BB305-3276-4AE1-87B1-C19C7A9F3840}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Json", "src\Rewrite.Json\Rewrite.Json.csproj", "{5DD7D88A-5A10-457D-B1A2-30F7CF67AD9F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Java", "src\Rewrite.Java\Rewrite.Java.csproj", "{06BCC1C7-9D8C-4D3B-934D-072C35A5C984}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.CSharp", "src\Rewrite.CSharp\Rewrite.CSharp.csproj", "{25208A27-E598-4BE3-9CD9-0618A6B9598F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.CSharp.Tests", "tests\Rewrite.CSharp.Tests\Rewrite.CSharp.Tests.csproj", "{25EEACCB-9BAE-4361-A980-9E9CDA37602E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test", "src\Rewrite.Test\Rewrite.Test.csproj", "{D3F48947-C702-4D1A-B6EE-96B89D13953D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C7A4A8F9-0343-4A3E-AB77-101C458C23B5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7B268266-B9CD-4D85-ABC5-3B2C4611FD74}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_solution", "_solution", "{B5C675AF-506B-47E6-AB10-4E7BC36531D2}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + Directory.Build.props = Directory.Build.props + Directory.Build.targets = Directory.Build.targets + README.md = README.md + Directory.Build.props.user = Directory.Build.props.user + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "commercial", "commercial", "{45B6292D-DC7E-46A7-A86E-7455BBEAED70}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Remote", "..\..\..\moderneinc\rewrite-remote\Rewrite.Remote\src\Rewrite.Remote\Rewrite.Remote.csproj", "{0E364862-1ACA-4C94-8EA0-23724FF67AA2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.MSBuild", "..\..\..\moderneinc\rewrite-remote\Rewrite.Remote\src\Rewrite.MSBuild\Rewrite.MSBuild.csproj", "{DE03049F-95A3-483F-939C-C2325548D590}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "..\_build\_build.csproj", "{C714F4F1-E2DF-4B29-A277-9B40BD7DE406}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Remote.Codec", "src\Rewrite.Remote.Codec\Rewrite.Remote.Codec.csproj", "{40C71491-3CCC-40A0-8F01-3EC7204CF85F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test.CSharp", "src\Rewrite.Test.CSharp\Rewrite.Test.CSharp.csproj", "{5C70ACE0-BE37-4D67-A67F-EE69767994D2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rewrite.Test.Engine.Remote", "src\Rewrite.Test.Engine.Remote\Rewrite.Test.Engine.Remote.csproj", "{C04C7CA4-69C3-444F-A654-6C722A0FC3BE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C714F4F1-E2DF-4B29-A277-9B40BD7DE406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C714F4F1-E2DF-4B29-A277-9B40BD7DE406}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB30394C-7930-4BFF-97E2-400CFADE92C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB30394C-7930-4BFF-97E2-400CFADE92C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB30394C-7930-4BFF-97E2-400CFADE92C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB30394C-7930-4BFF-97E2-400CFADE92C2}.Release|Any CPU.Build.0 = Release|Any CPU + {C7E280C5-E841-4690-8AA3-653ECBC7C78B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7E280C5-E841-4690-8AA3-653ECBC7C78B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7E280C5-E841-4690-8AA3-653ECBC7C78B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7E280C5-E841-4690-8AA3-653ECBC7C78B}.Release|Any CPU.Build.0 = Release|Any CPU + {F7F4F27F-2CAE-422B-B6CE-25A88C3603A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7F4F27F-2CAE-422B-B6CE-25A88C3603A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7F4F27F-2CAE-422B-B6CE-25A88C3603A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7F4F27F-2CAE-422B-B6CE-25A88C3603A1}.Release|Any CPU.Build.0 = Release|Any CPU + {D38BB305-3276-4AE1-87B1-C19C7A9F3840}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D38BB305-3276-4AE1-87B1-C19C7A9F3840}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D38BB305-3276-4AE1-87B1-C19C7A9F3840}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D38BB305-3276-4AE1-87B1-C19C7A9F3840}.Release|Any CPU.Build.0 = Release|Any CPU + {5DD7D88A-5A10-457D-B1A2-30F7CF67AD9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5DD7D88A-5A10-457D-B1A2-30F7CF67AD9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5DD7D88A-5A10-457D-B1A2-30F7CF67AD9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5DD7D88A-5A10-457D-B1A2-30F7CF67AD9F}.Release|Any CPU.Build.0 = Release|Any CPU + {06BCC1C7-9D8C-4D3B-934D-072C35A5C984}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06BCC1C7-9D8C-4D3B-934D-072C35A5C984}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06BCC1C7-9D8C-4D3B-934D-072C35A5C984}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06BCC1C7-9D8C-4D3B-934D-072C35A5C984}.Release|Any CPU.Build.0 = Release|Any CPU + {25208A27-E598-4BE3-9CD9-0618A6B9598F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25208A27-E598-4BE3-9CD9-0618A6B9598F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25208A27-E598-4BE3-9CD9-0618A6B9598F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25208A27-E598-4BE3-9CD9-0618A6B9598F}.Release|Any CPU.Build.0 = Release|Any CPU + {25EEACCB-9BAE-4361-A980-9E9CDA37602E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25EEACCB-9BAE-4361-A980-9E9CDA37602E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25EEACCB-9BAE-4361-A980-9E9CDA37602E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25EEACCB-9BAE-4361-A980-9E9CDA37602E}.Release|Any CPU.Build.0 = Release|Any CPU + {D3F48947-C702-4D1A-B6EE-96B89D13953D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3F48947-C702-4D1A-B6EE-96B89D13953D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3F48947-C702-4D1A-B6EE-96B89D13953D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3F48947-C702-4D1A-B6EE-96B89D13953D}.Release|Any CPU.Build.0 = Release|Any CPU + {0E364862-1ACA-4C94-8EA0-23724FF67AA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E364862-1ACA-4C94-8EA0-23724FF67AA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E364862-1ACA-4C94-8EA0-23724FF67AA2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E364862-1ACA-4C94-8EA0-23724FF67AA2}.Release|Any CPU.Build.0 = Release|Any CPU + {DE03049F-95A3-483F-939C-C2325548D590}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE03049F-95A3-483F-939C-C2325548D590}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE03049F-95A3-483F-939C-C2325548D590}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE03049F-95A3-483F-939C-C2325548D590}.Release|Any CPU.Build.0 = Release|Any CPU + {40C71491-3CCC-40A0-8F01-3EC7204CF85F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40C71491-3CCC-40A0-8F01-3EC7204CF85F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40C71491-3CCC-40A0-8F01-3EC7204CF85F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40C71491-3CCC-40A0-8F01-3EC7204CF85F}.Release|Any CPU.Build.0 = Release|Any CPU + {5C70ACE0-BE37-4D67-A67F-EE69767994D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C70ACE0-BE37-4D67-A67F-EE69767994D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C70ACE0-BE37-4D67-A67F-EE69767994D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C70ACE0-BE37-4D67-A67F-EE69767994D2}.Release|Any CPU.Build.0 = Release|Any CPU + {C04C7CA4-69C3-444F-A654-6C722A0FC3BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C04C7CA4-69C3-444F-A654-6C722A0FC3BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C04C7CA4-69C3-444F-A654-6C722A0FC3BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C04C7CA4-69C3-444F-A654-6C722A0FC3BE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {25EEACCB-9BAE-4361-A980-9E9CDA37602E} = {7B268266-B9CD-4D85-ABC5-3B2C4611FD74} + {FB30394C-7930-4BFF-97E2-400CFADE92C2} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {25208A27-E598-4BE3-9CD9-0618A6B9598F} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {06BCC1C7-9D8C-4D3B-934D-072C35A5C984} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {5DD7D88A-5A10-457D-B1A2-30F7CF67AD9F} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {C7E280C5-E841-4690-8AA3-653ECBC7C78B} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {D3F48947-C702-4D1A-B6EE-96B89D13953D} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {D38BB305-3276-4AE1-87B1-C19C7A9F3840} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {F7F4F27F-2CAE-422B-B6CE-25A88C3603A1} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {0E364862-1ACA-4C94-8EA0-23724FF67AA2} = {45B6292D-DC7E-46A7-A86E-7455BBEAED70} + {DE03049F-95A3-483F-939C-C2325548D590} = {45B6292D-DC7E-46A7-A86E-7455BBEAED70} + {C714F4F1-E2DF-4B29-A277-9B40BD7DE406} = {B5C675AF-506B-47E6-AB10-4E7BC36531D2} + {40C71491-3CCC-40A0-8F01-3EC7204CF85F} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {5C70ACE0-BE37-4D67-A67F-EE69767994D2} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + {C04C7CA4-69C3-444F-A654-6C722A0FC3BE} = {C7A4A8F9-0343-4A3E-AB77-101C458C23B5} + EndGlobalSection +EndGlobal diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/ModuleInitializer.cs b/Rewrite/tests/Rewrite.CSharp.Tests/ModuleInitializer.cs index cc762f57..ee9de5e5 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/ModuleInitializer.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/ModuleInitializer.cs @@ -1,4 +1,6 @@ using System.Runtime.CompilerServices; +using Microsoft.Build.Locator; +using Rewrite.MSBuild; using Rewrite.Remote; using Rewrite.Remote.Codec.CSharp; using Rewrite.Remote.Codec.Java; @@ -19,6 +21,7 @@ public class ModuleInitializer [ModuleInitializer] internal static void OnAssemblyLoad() { + ProjectParser.Init(); if (ITestExecutionContext.Current() == null) { ITestExecutionContext.SetCurrent(new LocalTestExecutionContext()); diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Rewrite.CSharp.Tests.csproj b/Rewrite/tests/Rewrite.CSharp.Tests/Rewrite.CSharp.Tests.csproj index 68c0c04e..dee12f8d 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Rewrite.CSharp.Tests.csproj +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Rewrite.CSharp.Tests.csproj @@ -11,6 +11,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -19,6 +20,8 @@ + + diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/ParseTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/ParseTests.cs new file mode 100644 index 00000000..8b0cac92 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/ParseTests.cs @@ -0,0 +1,158 @@ +using System.Collections; +using System.Diagnostics; +using System.Text.RegularExpressions; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Rewrite.Test.CSharp; +using Rewrite.Test; +using Socolin.ANSITerminalColor; + +namespace Rewrite.CSharp.Tests.RoslynTestCases; + +using static Assertions; + +public class ParseTests : RewriteTest +{ + private readonly ITestOutputHelper _output; + private readonly CSharpParser _parser; + + public ParseTests(ITestOutputHelper output) + { + _output = output; + _parser = new CSharpParser.Builder().Build(); + } + + [Theory] + [Exploratory] + [InlineData("abc\n123","abc123")] + [InlineData("abc123","abc134")] + [InlineData(""" + one + two + three + four + NOT five + """, + """ + one + two + four + five + six + """)] + public void Delta(string before, string after) + { + after.ShouldBeSameAs(before); + } + + [Fact] + [Exploratory] + public void TestReport() + { + var badTestCases = new List<(SourceTestCase, List)>(); + var testCases = new CSharpSyntaxFragments().Select(x => (SourceTestCase)x[0]).ToList(); + List report = new(); + foreach (var testCase in testCases) + { + var roslynDiagnostics = CSharpSyntaxTree.ParseText(testCase.SourceText).GetDiagnostics().ToList(); + if (roslynDiagnostics.Any()) + { + badTestCases.Add((testCase,roslynDiagnostics)); + // report.Add(testCase.Fail("Original.Parse.RoslynIssues")); + continue; + } + + var lst = _parser.Parse(testCase.SourceText); + + if (lst is ParseError) + { + report.Add(testCase.Fail("LstParseError")); + continue; + } + + var lstPrint = lst.ToString()!; + + string StripWhiteSpace(string s) => Regex.Replace(s, @"[\r\n]", ""); + var equalBeforeTrim = lstPrint == testCase.SourceText; + var equalAfterTrim = StripWhiteSpace(lstPrint) == StripWhiteSpace(testCase.SourceText); + if (!equalBeforeTrim && equalAfterTrim) + { + report.Add(testCase.Fail("DifferentWhitespace")); + } + else if(!equalAfterTrim) + { + var roslynLstReParse = CSharpSyntaxTree.ParseText(lstPrint); + if (roslynLstReParse.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error).Any()) + { + report.Add(testCase.Fail("DifferentUncompilable")); + } + else + { + report.Add(testCase.Fail("DifferentCompilable")); + } + + + } + else + { + report.Add(testCase.Pass()); + } + } + + _output.WriteLine(AnsiColor.ColorizeText($"Total: {report.Count}", AnsiColor.Foreground(Terminal256ColorCodes.Red1C196))); + _output.WriteLine($" Successful: {report.Count(x => x.Success)}"); + var failed = report.Where(x => !x.Success).ToList(); + _output.WriteLine($" Failed: {failed.Count}"); + foreach (var (failureReason, count) in failed + .GroupBy(x => x.FailureReason) + .Select(x => (Reason: x.Key, count: x.Count())) + .OrderBy(x => x.Reason)) + { + _output.WriteLine($" {failureReason}: {count}"); + } + + foreach (var (testCase, diagnostics) in badTestCases) + { + _output.WriteLine($"\"{testCase.Name}\","); + // _output.WriteLine(testCase.SourceText); + // _output.WriteLine(string.Join("\n", diagnostics.Select(x => x.ToString()))); + } + } + + + + + [Theory] + [ClassData(typeof(CSharpSyntaxFragments))] + [Category("Roslyn")] + public void ParseAndPrint(SourceTestCase syntax) + { + var lst = _parser.Parse(syntax.SourceText); + lst.Should().NotBeOfType(); + + var lstPrint = lst.ToString()!; + // lstPrint.Should().Be(syntax.SourceText); + lstPrint.ShouldBeSameAs(syntax.SourceText); + + } +} + +public class TestResult +{ + public TestResult(SourceTestCase testCase, string? failureReason = null) + { + TestCase = testCase.Name; + FailureReason = failureReason; + } + + public bool Success => FailureReason == null; + public string TestCase { get; } + public string? FailureReason { get; set; } +} + +public static class Extensions +{ + public static TestResult Pass(this SourceTestCase testCase) => new TestResult(testCase); + public static TestResult Fail(this SourceTestCase testCase, string reason) => new TestResult(testCase, reason); +} + diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/RoslynTestData.g.cs b/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/RoslynTestData.g.cs new file mode 100644 index 00000000..cd9f8609 --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/RoslynTestData.g.cs @@ -0,0 +1,3497 @@ +using System.Collections; +namespace Rewrite.CSharp.Tests.RoslynTestCases; +public class CSharpSyntaxFragments : IEnumerable +{ + public IEnumerator GetEnumerator() + { + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_Single",@" +class C where T : allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_Single_MissingRefAndStruct",@" +class C where T : allows +{}") + }; + + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_TwoInARow",@" +class C where T : allows ref struct, ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_TwoInARow_MissingRef",@" +class C where T : allows ref struct, struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_TwoAllowsInARow",@" +class C where T : allows ref struct, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_FollowedByWhere_01",@" +class C where T : allows ref struct where S : class +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_FollowedByWhere_02",@" +class C where T : struct, allows ref struct where S : class +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterStruct",@" +class C where T : struct, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterClass",@" +class C where T : class, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterDefault",@" +class C where T : default, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterUnmanaged",@" +class C where T : unmanaged, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterNotNull",@" +class C where T : notnull, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterTypeConstraint",@" +class C where T : SomeType, allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterNew",@" +class C where T : new(), allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_AfterMultiple",@" +class C where T : struct, SomeType, new(), allows ref struct +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_BeforeClass",@" +class C where T : allows ref struct, class +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_BeforeDefault",@" +class C where T : allows ref struct, default +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_BeforeUnmanaged",@" +class C where T : allows ref struct, unmanaged +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_BeforeNotNull",@" +class C where T : allows ref struct, notnull +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_BeforeTypeConstraint",@" +class C where T : allows ref struct, SomeType +{}") + }; + + yield return new object[] + { + new SourceTestCase("AllowsConstraintParsing.RefStruct_BeforeNew",@" +class C where T : allows ref struct, new() +{}") + }; + + yield return new object[] + { + new SourceTestCase("AsyncParsingTests.AsyncAsType_Indexer_ExpressionBody_ErrorCase","interface async { async this[async i] => null; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestExternAlias","extern alias a;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsing","using a;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsingStatic","using static a;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsingDottedName","using a.b;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsingStaticDottedName","using static a.b;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsingStaticGenericName","using static a;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsingAliasName","using a = b;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestUsingAliasGenericName","using a = b;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttribute","[assembly:a]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttribute_Verbatim","[@assembly:a]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttribute_Escape",@"[as\u0073embly:a]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalModuleAttribute","[module:a]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalModuleAttribute_Verbatim","[@module:a]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttributeWithParentheses","[assembly:a()]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttributeWithMultipleArguments","[assembly:a(b, c)]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttributeWithNamedArguments","[assembly:a(b = c)]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGlobalAttributeWithMultipleAttributes","[assembly:a, b]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestMultipleGlobalAttributeDeclarations","[assembly:a] [assembly:b]") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespace","namespace a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestFileScopedNamespace","namespace a;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceWithDottedName","namespace a.b.c { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceWithUsing","namespace a { using b.c; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestFileScopedNamespaceWithUsing","namespace a; using b.c;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceWithExternAlias","namespace a { extern alias b; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestFileScopedNamespaceWithExternAlias","namespace a; extern alias b;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceWithNestedNamespace","namespace a { namespace b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClass","class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithPublic","public class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithInternal","internal class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithStatic","static class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithSealed","sealed class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithAbstract","abstract class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithPartial","partial class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithAttribute","[attr] class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithMultipleAttributes","[attr1] [attr2] class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithMultipleAttributesInAList","[attr1, attr2] class a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithBaseType","class a : b { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithMultipleBases","class a : b, c { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithTypeConstraintBound","class a where b : c { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNonGenericClassWithTypeConstraintBound","class a where b : c { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNonGenericMethodWithTypeConstraintBound","class a { void M() where b : c { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithNewConstraintBound","class a where b : new() { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithClassConstraintBound","class a where b : class { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithStructConstraintBound","class a where b : struct { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithMultipleConstraintBounds","class a where b : class, c, new() { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithMultipleConstraints","class a where b : c where b : new() { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassWithMultipleBasesAndConstraints","class a : c, d where b : class, e, new() { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestInterface","interface a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGenericInterface","interface A { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGenericInterfaceWithAttributesAndVariance","interface A<[B] out C> { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestStruct","struct a { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedClass","class a { class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedPrivateClass","class a { private class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedProtectedClass","class a { protected class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedProtectedInternalClass","class a { protected internal class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedInternalProtectedClass","class a { internal protected class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedPublicClass","class a { public class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedInternalClass","class a { internal class b { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegate","delegate a b();") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithRefReturnType","delegate ref a b();") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithRefReadonlyReturnType","delegate ref readonly a b();") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithParameter","delegate a b(c d);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithMultipleParameters","delegate a b(c d, e f);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithRefParameter","delegate a b(ref c d);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithOutParameter","delegate a b(out c d);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithParamsParameter","delegate a b(params c d);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithArgListParameter","delegate a b(__arglist);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestDelegateWithParameterAttribute","delegate a b([attr] c d);") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNestedDelegate","class a { delegate b c(); }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethod","class a { b X() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethodWithRefReturn","class a { ref b X() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethodWithRefReadonlyReturn","class a { ref readonly b X() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethodWithPartial","class a { partial void M() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestStructMethodWithReadonly","struct a { readonly void M() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestReadOnlyRefReturning","struct a { readonly ref readonly int M() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestStructExpressionPropertyWithReadonly","struct a { readonly int M => 42; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestStructGetterPropertyWithReadonly","struct a { int P { readonly get { return 42; } } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethodWithParameter","class a { b X(c d) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethodWithMultipleParameters","class a { b X(c d, e f) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassMethodWithArgListParameter","class a { b X(__arglist) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGenericClassMethod","class a { b M() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGenericClassMethodWithTypeConstraintBound","class a { b X() where b : d { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestGenericClassConstructor",@" +class Class1{ + public Class1() { } +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassConstructor","class a { a() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassDestructor","class a { ~a() { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassField","class a { b c; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassConstField","class a { const b c = d; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassFieldWithInitializer","class a { b c = e; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassFieldWithArrayInitializer","class a { b c = { }; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassFieldWithMultipleVariables","class a { b c, d, e; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassFieldWithMultipleVariablesAndInitializers","class a { b c = x, d = y, e = z; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassFixedField","class a { fixed b c[10]; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassProperty","class a { b c { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassPropertyWithRefReturn","class a { ref b c { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassPropertyWithRefReadonlyReturn","class a { ref readonly b c { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassPropertyWithBodies","class a { b c { get { } set { } } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassAutoPropertyWithInitializer","class a { b c { get; set; } = d; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.InitializerOnNonAutoProp","class C { int P { set {} } = 0; }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassPropertyExplicit","class a { b I.c { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassEventProperty","class a { event b c { add { } remove { } } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassEventPropertyExplicit","class a { event b I.c { add { } remove { } } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassIndexer","class a { b this[c d] { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassIndexerWithRefReturn","class a { ref b this[c d] { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassIndexerWithRefReadonlyReturn","class a { ref readonly b this[c d] { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassIndexerWithMultipleParameters","class a { b this[c d, e f] { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassIndexerExplicit","class a { b I.this[c d] { get; set; } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassRightShiftOperatorMethod","class a { b operator >> (c d, e f) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassUnsignedRightShiftOperatorMethod","class a { b operator >>> (c d, e f) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassImplicitConversionOperatorMethod","class a { implicit operator b (c d) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestClassExplicitConversionOperatorMethod","class a { explicit operator b (c d) { } }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceDeclarationsBadNames","namespace A::B { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceDeclarationsBadNames1",@"namespace A::B { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceDeclarationsBadNames2",@"namespace A { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestNamespaceDeclarationsBadNames3",@"namespace A<,> { }") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestPartialEnum",@"partial enum E{}") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestEscapedConstructor",@" +class @class +{ + public @class() + { + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TestAnonymousMethodWithDefaultParameter",@" +delegate void F(int x); +class C { + void M() { + F f = delegate (int x = 0) { }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.RegressIfDevTrueUnicode",@" +class P +{ +static void Main() +{ +#if tru\u0065 +System.Console.WriteLine(""Good, backwards compatible""); +#else +System.Console.WriteLine(""Bad, breaking change""); +#endif +} +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.RegressLongDirectiveIdentifierDefn",@" +//130 chars (max is 128) +#define A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +class P +{ +static void Main() +{ +//first 128 chars of defined value +#if A2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 +System.Console.WriteLine(""Good, backwards compatible""); +#else +System.Console.WriteLine(""Bad, breaking change""); +#endif +} +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.RegressLongDirectiveIdentifierUse",@" +//128 chars (max) +#define A2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 +class P +{ +static void Main() +{ +//defined value + two chars (larger than max) +#if A234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 +System.Console.WriteLine(""Good, backwards compatible""); +#else +System.Console.WriteLine(""Bad, breaking change""); +#endif +} +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.ValidFixedBufferTypes",@" +unsafe struct s +{ + public fixed bool _Type1[10]; + internal fixed int _Type3[10]; + private fixed short _Type4[10]; + unsafe fixed long _Type5[10]; + new fixed char _Type6[10]; +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.ValidFixedBufferTypesMultipleDeclarationsOnSameLine",@" +unsafe struct s +{ + public fixed bool _Type1[10], _Type2[10], _Type3[20]; +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.ValidFixedBufferTypesWithCountFromConstantOrLiteral",@" +unsafe struct s +{ + public const int abc = 10; + public fixed bool _Type1[abc]; + public fixed bool _Type2[20]; + } +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.ValidFixedBufferTypesAllValidTypes",@" +unsafe struct s +{ + public fixed bool _Type1[10]; + public fixed byte _Type12[10]; + public fixed int _Type2[10]; + public fixed short _Type3[10]; + public fixed long _Type4[10]; + public fixed char _Type5[10]; + public fixed sbyte _Type6[10]; + public fixed ushort _Type7[10]; + public fixed uint _Type8[10]; + public fixed ulong _Type9[10]; + public fixed float _Type10[10]; + public fixed double _Type11[10]; + } + + +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TupleArgument01",@" +class C1 +{ + static (T, T) Test1(int a, (byte, byte) arg0) + { + return default((T, T)); + } + + static (T, T) Test2(ref (byte, byte) arg0) + { + return default((T, T)); + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.TupleArgument02",@" +class C1 +{ + static (T, T) Test3((byte, byte) arg0) + { + return default((T, T)); + } + + (T, T) Test3((byte a, byte b)[] arg0) + { + return default((T, T)); + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.Interface_SemicolonBody",@" +interface C +;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.Interface_SemicolonBodyAfterBase_01",@" +interface C : I1 +;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.Interface_SemicolonBodyAfterBase_02",@" +interface C : I1, I2 +;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.Interface_SemicolonBodyAfterConstraint_01",@" +interface C where T1 : U1 +;") + }; + + yield return new object[] + { + new SourceTestCase("DeclarationParsingTests.Interface_SemicolonBodyAfterConstraint_02",@" +interface C where T1 : U1 where T2 : U2 +;") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.TupleArray","(T, T)[] id;") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.ParenthesizedExpression","(x).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.TupleLiteralStatement","(x, x).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.Statement4","((x)).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.Statement5","((x, y) = M()).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.CastWithTupleType","(((x, y))z).Goo();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.NotACast","((Int32.MaxValue, Int32.MaxValue)).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.AlsoNotACast","((x, y)).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.StillNotACast","((((x, y)))).ToString();") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.LambdaInExpressionStatement","(a) => a;") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.LambdaWithBodyInExpressionStatement","(a, b) => { };") + }; + + yield return new object[] + { + new SourceTestCase("DeconstructionTests.NullableTuple","(x, y)? z = M();") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_01",@" +class C +{ + void M() + { + //int a = 1; + //int i = 1; + var j = a < i >> 2; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_02",@" +class C +{ + void M() + { + //const int a = 1; + //const int i = 2; + switch (false) + { + case a < i >> 2: break; + } + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_03",@" +class C +{ + void M() + { + M(out a < i >> 2); + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_04",@" +class C +{ + void M() + { + // (e is a) > 2 + var j = e is a < i >> 2; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_05",@" +class C +{ + void M() + { + var j = e is a < i >>> 2; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_08",@" +class C +{ + void M() + { + M(out a < i >>> 2); + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_09",@" +class C +{ + void M() + { + //const int a = 1; + //const int i = 2; + switch (false) + { + case a < i >>> 2: break; + } + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ExpressionParsingTests.TypeArgumentShiftAmbiguity_10",@" +class C +{ + void M() + { + //int a = 1; + //int i = 1; + var j = a < i >>> 2; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("FunctionPointerTests.LangVersion8","delegate* unmanaged[cdecl] ptr;") + }; + + yield return new object[] + { + new SourceTestCase("LocalFunctionParsingTests.DiagnosticsWithoutExperimental",@" +class c +{ + void m() + { + int local() => 0; + } + void m2() + { + int local() { return 0; } + } +}") + }; + + yield return new object[] + { + new SourceTestCase("LocalFunctionParsingTests.StaticFunctions",@"class Program +{ + void M() + { + static void F() { } + } +}") + }; + + yield return new object[] + { + new SourceTestCase("LocalFunctionParsingTests.AsyncStaticFunctions",@"class Program +{ + void M() + { + static async void F1() { } + async static void F2() { } + } +}") + }; + + yield return new object[] + { + new SourceTestCase("MemberDeclarationParsingTests.OperatorDeclaration_ExplicitImplementation_01","public int N.I.operator +(int x, int y) => x + y;") + }; + + yield return new object[] + { + new SourceTestCase("MemberDeclarationParsingTests.OperatorDeclaration_ExplicitImplementation_11","public int N.I.operator +(int x, int y) => x + y;") + }; + + yield return new object[] + { + new SourceTestCase("MemberDeclarationParsingTests.OperatorDeclaration_ExplicitImplementation_23","int N.I.operator +(int x, int y) => x + y;") + }; + + yield return new object[] + { + new SourceTestCase("MemberDeclarationParsingTests.OperatorDeclaration_ExplicitImplementation_33","int N.I.operator +(int x, int y) => x + y;") + }; + + yield return new object[] + { + new SourceTestCase("MemberDeclarationParsingTests.ConversionDeclaration_ExplicitImplementation_01","implicit N.I.operator int(int x) => x;") + }; + + yield return new object[] + { + new SourceTestCase("MemberDeclarationParsingTests.ConversionDeclaration_ExplicitImplementation_11","explicit N.I.operator int(int x) => x;") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.CS1031ERR_TypeExpected02_Tuple",@"namespace x +{ + public class @a + { + public static void Main() + { + var e = new (); + } + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.CS1031ERR_TypeExpected02WithCSharp6_Tuple",@"namespace x +{ + public class @a + { + public static void Main() + { + var e = new (); + } + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.CS1031ERR_TypeExpected02WithCSharp7_Tuple",@"namespace x +{ + public class @a + { + public static void Main() + { + var e = new (); + } + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.PartialTypesBeforeVersionTwo",@" +partial class C +{ +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.PartialMethodsVersionThree",@" +class C +{ + partial int Goo() { } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.QueryBeforeVersionThree",@" +class C +{ + void Goo() + { + var q = from a in b + select c; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.AnonymousTypeBeforeVersionThree",@" +class C +{ + void Goo() + { + var q = new { }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.ImplicitArrayBeforeVersionThree",@" +class C +{ + void Goo() + { + var q = new [] { }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.ObjectInitializerBeforeVersionThree",@" +class C +{ + void Goo() + { + var q = new Goo { }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.LambdaBeforeVersionThree",@" +class C +{ + void Goo() + { + var q = a => b; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.ExceptionFilterBeforeVersionSix",@" +public class C +{ + public static int Main() + { + try { } catch when (true) {} + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.InterpolatedStringBeforeCSharp6",@" +class C +{ + string M() + { + return $""hello""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.InterpolatedStringWithReplacementBeforeCSharp6",@" +class C +{ + string M() + { + string other = ""world""; + return $""hello + {other}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.AsyncBeforeCSharp5",@" +class C +{ + async void M() { } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.AsyncWithOtherModifiersBeforeCSharp5",@" +class C +{ + async static void M() { } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.AsyncLambdaBeforeCSharp5",@" +class C +{ + static void Main() + { + Func> f = async x => x; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.AsyncDelegateBeforeCSharp5",@" +class C +{ + static void Main() + { + Func> f = async delegate (int x) { return x; }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.NamedArgumentBeforeCSharp4",@" +[Attr(x:1)] +class C +{ + C() + { + M(y:2); + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.GlobalKeywordBeforeCSharp2",@" +class C : global::B +{ +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.AliasQualifiedNameBeforeCSharp2",@" +class C : A::B +{ +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.OptionalParameterBeforeCSharp4",@" +class C +{ + void M(int x = 1) { } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.ObjectInitializerBeforeCSharp3",@" +class C +{ + void M() + { + return new C { Goo = 1 }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.CollectionInitializerBeforeCSharp3",@" +class C +{ + void M() + { + return new C { 1, 2, 3 }; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.CrefGenericBeforeCSharp2",@" +/// +class C +{ +} +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.CrefAliasQualifiedNameBeforeCSharp2",@" +/// +/// +class C { } +") + }; + + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.PragmaBeforeCSharp2",@" +#pragma warning disable 1584 +#pragma checksum ""file.txt"" ""{00000000-0000-0000-0000-000000000000}"" ""2453"" +class C { } +") + }; + + yield return new object[] + { + new SourceTestCase("ParserErrorMessageTests.PragmaBeforeCSharp2_InDisabledCode",@" +#if UNDEF +#pragma warning disable 1584 +#pragma checksum ""file.txt"" ""{00000000-0000-0000-0000-000000000000}"" ""2453"" +#endif +class C { } +") + }; + + yield return new object[] + { + new SourceTestCase("PatternParsingTests.ParenthesizedSwitchCase",@" +switch (e) +{ + case (0): break; + case (-1): break; + case (+2): break; + case (~3): break; +} +") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLine1",@" +class C +{ + void M() + { + var v = $"""""" """"""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineSingleQuoteInside",@" +class C +{ + void M() + { + var v = $"""""" "" """"""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineDoubleQuoteInside",@" +class C +{ + void M() + { + var v = $"""""" """" """"""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationInside",@" +class C +{ + void M() + { + var v = $""""""{0}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationInsideSpacesOutside",@" +class C +{ + void M() + { + var v = $"""""" {0} """"""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationInsideSpacesInside",@" +class C +{ + void M() + { + var v = $""""""{ 0 }""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationInsideSpacesInsideAndOutside",@" +class C +{ + void M() + { + var v = $"""""" { 0 } """"""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationMultipleCurliesAllowed1",@" +class C +{ + void M() + { + var v = $$""""""{{0}}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationMultipleCurliesAllowed2",@" +class C +{ + void M() + { + var v = $$""""""{{{0}}}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationMultipleCurliesAllowed4",@" +class C +{ + void M() + { + var v = $$""""""{{{0}}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingNormalString",@" +class C +{ + void M() + { + var v = $""""""{""a""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingVerbatimString1",@" +class C +{ + void M() + { + var v = $""""""{@""a""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingVerbatimString2",@" +class C +{ + void M() + { + var v = $""""""{@"" +a""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingInterpolatedString1",@" +class C +{ + void M() + { + var v = $""""""{$""a""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingInterpolatedString2",@" +class C +{ + void M() + { + var v = $""""""{$""{0}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingVerbatimInterpolatedString1",@" +class C +{ + void M() + { + var v = $""""""{$@""{0}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingVerbatimInterpolatedString2",@" +class C +{ + void M() + { + var v = $""""""{@$""{0}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingVerbatimInterpolatedString3",@" +class C +{ + void M() + { + var v = $""""""{$@""{ +0}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingVerbatimInterpolatedString4",@" +class C +{ + void M() + { + var v = $""""""{ +$@""{ +0}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawStringLiteral1",@" +class C +{ + void M() + { + var v = $""""""{""""""a""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawStringLiteral2",@" +class C +{ + void M() + { + var v = $""""""{"""""" + a + """"""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral1",@" +class C +{ + void M() + { + var v = $""""""{$"""""" """"""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral2",@" +class C +{ + void M() + { + var v = $""""""{$"""""""" """"""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral3",@" +class C +{ + void M() + { + var v = $""""""{$""""""{0}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral4",@" +class C +{ + void M() + { + var v = $""""""{$""""""{ +0}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral5",@" +class C +{ + void M() + { + var v = $""""""{ +$""""""{ +0}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral6",@" +class C +{ + void M() + { + var v = $""""""{$$""""""{{0}}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral7",@" +class C +{ + void M() + { + var v = $""""""{$$""""""{{{0}}}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingRawInterpolatedStringLiteral8",@" +class C +{ + void M() + { + var v = $$""""""{{{$""""""{0}""""""}}}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingClosingBraceAsCharacterLiteral",@" +class C +{ + void M() + { + var v = $""""""{'}'}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingClosingBraceAsRegularStringLiteral",@" +class C +{ + void M() + { + var v = $""""""{""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingClosingBraceAsVerbatimStringLiteral",@" +class C +{ + void M() + { + var v = $""""""{@""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.SingleLineInterpolationContainingClosingBraceAsRawStringLiteral",@" +class C +{ + void M() + { + var v = $""""""{""""""}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleNormalInnerNormal",@" +class C +{ + void M() + { + var v = $""{$""{$""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleNormalInnerVerbatim",@" +class C +{ + void M() + { + var v = $""{$""{$@""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleNormalInnerRaw",@" +class C +{ + void M() + { + var v = $""{$""{$""""""{0}""""""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleVerbatimInnerNormal",@" +class C +{ + void M() + { + var v = $""{@$""{$""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleVerbatimInnerVerbatim",@" +class C +{ + void M() + { + var v = $""{@$""{@$""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleVerbatimInnerRaw",@" +class C +{ + void M() + { + var v = $""{@$""{$""""""{0}""""""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleRawInnerNormal",@" +class C +{ + void M() + { + var v = $""{$""""""{$""{0}""}""""""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleRawInnerVerbatim",@" +class C +{ + void M() + { + var v = $""{$""""""{@$""{0}""}""""""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterNormalMiddleRawInnerRaw",@" +class C +{ + void M() + { + var v = $""{$""""""{$""""""{0}""""""}""""""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleNormalInnerNormal",@" +class C +{ + void M() + { + var v = $@""{$""{$""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleNormalInnerVerbatim",@" +class C +{ + void M() + { + var v = $@""{$""{$@""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleNormalInnerRaw",@" +class C +{ + void M() + { + var v = $@""{$""{$""""""{0}""""""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleVerbatimInnerNormal",@" +class C +{ + void M() + { + var v = $@""{@$""{$""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleVerbatimInnerVerbatim",@" +class C +{ + void M() + { + var v = $@""{@$""{@$""{0}""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleVerbatimInnerRaw",@" +class C +{ + void M() + { + var v = $@""{@$""{$""""""{0}""""""}""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleRawInnerNormal",@" +class C +{ + void M() + { + var v = $@""{$""""""{$""{0}""}""""""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleRawInnerVerbatim",@" +class C +{ + void M() + { + var v = $@""{$""""""{@$""{0}""}""""""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterVerbatimMiddleRawInnerRaw",@" +class C +{ + void M() + { + var v = $@""{$""""""{$""""""{0}""""""}""""""}""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleNormalInnerNormal",@" +class C +{ + void M() + { + var v = $""""""{$""{$""{0}""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleNormalInnerVerbatim",@" +class C +{ + void M() + { + var v = $""""""{$""{$@""{0}""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleNormalInnerRaw",@" +class C +{ + void M() + { + var v = $""""""{$""{$""""""{0}""""""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleVerbatimInnerNormal",@" +class C +{ + void M() + { + var v = $""""""{@$""{$""{0}""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleVerbatimInnerVerbatim",@" +class C +{ + void M() + { + var v = $""""""{@$""{@$""{0}""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleVerbatimInnerRaw",@" +class C +{ + void M() + { + var v = $""""""{@$""{$""""""{0}""""""}""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleRawInnerNormal",@" +class C +{ + void M() + { + var v = $""""""{$""""""{$""{0}""}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleRawInnerVerbatim",@" +class C +{ + void M() + { + var v = $""""""{$""""""{@$""{0}""}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RawInterpolatedStringLiteralParsingTests.OuterRawMiddleRawInnerRaw",@" +class C +{ + void M() + { + var v = $""""""{$""""""{$""""""{0}""""""}""""""}""""""; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("ReadOnlyStructs.ReadOnlyStructSimple",@" +class Program +{ + readonly struct S1{} + + public readonly struct S2{} + + readonly public struct S3{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("ReadOnlyStructs.ReadOnlyStructSimpleLangVer",@" +class Program +{ + readonly struct S1{} + + public readonly struct S2{} + + readonly public struct S3{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("ReadOnlyStructs.ReadOnlyClassErr",@" +class Program +{ + readonly class S1{} + + public readonly delegate ref readonly int S2(); + + readonly public interface S3{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("ReadOnlyStructs.ReadOnlyRefStruct",@" +class Program +{ + readonly ref struct S1{} + + unsafe readonly public ref struct S2{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("ReadOnlyStructs.ReadOnlyStructPartialMatchingModifiers",@" +class Program +{ + readonly partial struct S1{} + + readonly partial struct S1{} + + readonly ref partial struct S2{} + + readonly ref partial struct S2{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("ReadOnlyStructs.ReadOnlyStructPartialNotMatchingModifiers",@" +class Program +{ + readonly partial struct S1{} + + readonly ref partial struct S1{} + + readonly partial struct S2{} + + partial struct S2{} + + readonly ref partial struct S3{} + + partial struct S3{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.FieldNamedData",@" +class C +{ + int data; +}") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing01","record C(int X, int Y);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing02","record C(int X, int Y);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing03","record C;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing04","record C { public int record; }") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing05","record Point;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing07","interface P(int x, int y);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing_BlockBodyAndSemiColon","record C { };") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.WithParsingLangVer",@" +class C +{ + int x = 0 with {}; +}") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.WithParsing2",@" +class C +{ + int M() + { + int x = M() with { } + 3; + } +}") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.WithParsing17",@"x = x with { X = ""2"" };") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.Base_03","interface C : B;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.Base_04","interface C(int X, int Y) : B;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.Base_05","interface C : B(X, Y);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing","record struct C(int X, int Y);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_WithBody","record struct C(int X, int Y) { }") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordClassParsing","record class C(int X, int Y);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.StructNamedRecord_CSharp8","struct record { }") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.StructNamedRecord_CSharp9","struct record { }") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.StructNamedRecord_CSharp10","struct record { }") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_Partial","partial record struct S;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordClassParsing_Partial","partial record class S;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing_Partial","partial record S;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_Partial_WithParameterList","partial record struct S(int X);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_Partial_WithParameterList_AndMembers","partial record struct S(int X) { }") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_Readonly","readonly record struct S;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_ReadonlyPartial","readonly partial record struct S;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_Ref","ref record struct S;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordParsing_Ref","ref record R;") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_BaseListWithParens","record struct S : Base(1);") + }; + + yield return new object[] + { + new SourceTestCase("RecordParsingTests.RecordStructParsing_BaseListWithParens_WithPositionalParameterList","record struct S(int X) : Base(1);") + }; + + yield return new object[] + { + new SourceTestCase("RefReadonlyTests.RefReadonlyReturn_CSharp7",@" +unsafe class Program +{ + delegate ref readonly int D1(); + + static ref readonly T M() + { + return ref (new T[1])[0]; + } + + public virtual ref readonly int* P1 => throw null; + + public ref readonly int[][] this[int i] => throw null; +} +") + }; + + yield return new object[] + { + new SourceTestCase("RefReadonlyTests.InArgs_CSharp7",@" +class Program +{ + static void M(in int x) + { + } + + int this[in int x] + { + get + { + return 1; + } + } + + static void Test1() + { + int x = 1; + M(in x); + + _ = (new Program())[in x]; + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("RefReadonlyTests.RefReadonlyReturn_UnexpectedBindTime",@" + +class Program +{ + static void Main() + { + ref readonly int local = ref (new int[1])[0]; + + (ref readonly int, ref readonly int Alice)? t = null; + + System.Collections.Generic.List x = null; + + Use(local); + Use(t); + Use(x); + } + + static void Use(T dummy) + { + } +} +") + }; + + yield return new object[] + { + new SourceTestCase("RefStructs.RefStructSimple",@" +class Program +{ + ref struct S1{} + + public ref struct S2{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("RefStructs.RefStructSimpleLangVer",@" +class Program +{ + ref struct S1{} + + public ref struct S2{} +} +") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestDottedName","a.b();") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestGenericName","a();") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestGenericDotName","a.c();") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestDotGenericName","a.b();") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatement","T a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithVar","var a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithTuple","(int, int) a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithNamedTuple","(T x, (U k, V l, W m) y) a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithDynamic","dynamic a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithGenericType","T b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithDottedType","T.X.Y a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithMixedType","T.X.Y a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithArrayType","T[][,][,,] a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithPointerType","T* a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithNullableType","T? a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithMultipleVariables","T a, b, c;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithInitializer","T a = b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithMultipleVariablesAndInitializers","T a = va, b = vb, c = vc;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLocalDeclarationStatementWithArrayInitializer","T a = {b, c};") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestConstLocalDeclarationStatement","const T a = b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestRefLocalDeclarationStatement","ref T a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestRefLocalDeclarationStatementWithInitializer","ref T a = ref b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestRefLocalDeclarationStatementWithMultipleInitializers","ref T a = ref b, c = ref d;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestFixedStatement","fixed(T a = b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestFixedVarStatement","fixed(var a = b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestFixedStatementWithMultipleVariables","fixed(T a = b, c = d) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestEmptyStatement",";") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLabeledStatement","label: ;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestBreakStatement","break;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestContinueStatement","continue;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestGotoStatement","goto label;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestGotoCaseStatement","goto case label;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestGotoDefault","goto default;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestReturn","return;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestReturnExpression","return a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestYieldReturnExpression","yield return a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestYieldBreakExpression","yield break;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestThrow","throw;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestThrowExpression","throw a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestTryCatch","try { } catch(T e) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestTryCatchWithNoExceptionName","try { } catch(T) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestTryCatchWithNoExceptionDeclaration","try { } catch { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestTryCatchWithMultipleCatches","try { } catch(T e) { } catch(T2) { } catch { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestTryFinally","try { } finally { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestTryCatchWithMultipleCatchesAndFinally","try { } catch(T e) { } catch(T2) { } catch { } finally { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestChecked","checked { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUnchecked","unchecked { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUnsafe","unsafe { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestWhile","while(a) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestDoWhile","do { } while (a);") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestFor","for(;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithVariableDeclaration","for(T a = 0;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithVarDeclaration","for(var a = 0;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithMultipleVariableDeclarations","for(T a = 0, b = 1;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithRefVariableDeclaration","for(ref T a = ref b, c = ref d;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithVariableInitializer","for(a = 0;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithMultipleVariableInitializers","for(a = 0, b = 1;;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithCondition","for(; a;) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithIncrementor","for(; ; a++) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithMultipleIncrementors","for(; ; a++, b++) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForWithDeclarationConditionAndIncrementor","for(T a = 0; a < 10; a++) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForEach","foreach(T a in b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestForEachWithVar","foreach(var a in b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestIf","if (a) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestIfElse","if (a) { } else { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestIfElseIf","if (a) { } else if (b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestLock","lock (a) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestSwitch","switch (a) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestSwitchWithCase","switch (a) { case b:; }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestSwitchWithMultipleCases","switch (a) { case b:; case c:; }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestSwitchWithDefaultCase","switch (a) { default:; }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestSwitchWithMultipleLabelsOnOneCase","switch (a) { case b: case c:; }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestSwitchWithMultipleStatementsOnOneCase","switch (a) { case b: s1(); s2(); }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingWithExpression","using (a) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingWithDeclaration","using (T a = b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingVarWithDeclaration","using T a = b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingWithVarDeclaration","using (var a = b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingVarWithVarDeclaration","using var a = b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestAwaitUsingWithVarDeclaration","await using var a = b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingWithDeclarationWithMultipleVariables","using (T a = b, c = d) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingVarWithDeclarationWithMultipleVariables","using T a = b, c = d;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingSpecialCase1","using (f ? x = a : x = b) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingVarSpecialCase1","using var x = f ? a : b;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingSpecialCase2","using (f ? x = a) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingVarSpecialCase2","using f ? x = a;") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingSpecialCase3","using (f ? x, y) { }") + }; + + yield return new object[] + { + new SourceTestCase("StatementParsingTests.TestUsingVarSpecialCase3","using f ? x, y;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.StaticUsingDirectiveRefType",@"using static x = ref int;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveNamePointer1",@"using x = A*; + +struct A { }") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveNamePointer2",@"using unsafe x = A*; + +struct A { }") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveFunctionPointer1",@"using x = delegate*;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveFunctionPointer2",@"using unsafe x = delegate*;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingUnsafeNonAlias",@"using unsafe System;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedType_CSharp11",@"using x = int;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedType_CSharp12",@"using x = int;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedType_Preview",@"using x = int;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveRefType",@"using x = ref int;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveRefReadonlyType",@"using x = ref readonly int;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer1",@"using x = int*;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer2",@"using unsafe x = int*;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer3",@" +using unsafe X = int*; + +namespace N +{ + using Y = X; +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer4",@" +using unsafe X = int*; + +namespace N +{ + using unsafe Y = X; +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer5",@" +using X = int*; + +namespace N +{ + using unsafe Y = X; +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer6",@" +using unsafe X = int*; + +namespace N +{ + using Y = X[]; +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectivePredefinedTypePointer7",@" +using unsafe X = int*; + +namespace N +{ + using unsafe Y = X[]; +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveTuple1",@"using x = (int, int);") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveTuple2",""" + using X = (int, int); + + class C + { + X x = (0, 0); + } + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveTuple3",""" + using X = (int, int); + + class C + { + X x = (true, false); + } + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingNullableValueType",@"using x = int?;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingNullableReferenceType1",@"using x = string?;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingNullableReferenceType2",""" + #nullable enable + using X = string?; + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingNullableReferenceType3",""" + using X = string; + namespace N + { + using Y = X?; + } + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingNullableReferenceType4",""" + #nullable enable + using X = string; + namespace N + { + using Y = X?; + } + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingVoidPointer1",@"using unsafe VP = void*; + +class C +{ + void M(VP vp) { } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingVoidPointer2",@"using unsafe VP = void*; + +class C +{ + unsafe void M(VP vp) { } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingVoidPointer3",@"using VP = void*; + +class C +{ + unsafe void M(VP vp) { } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingDirectiveDynamic1",@" +using dynamic;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveDynamic1",@" +using D = dynamic; + +class C +{ + void M(D d) + { + d.Goo(); + } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveDynamic2",@" +using D = System.Collections.Generic.List; + +class C +{ + void M(D d) + { + d[0].Goo(); + } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveDynamic3",@" +using D = dynamic[]; + +class C +{ + void M(D d) + { + d[0].Goo(); + } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveDynamic4",@" +using D = dynamic; + +class dynamic +{ + void M(D d) + { + d.Goo(); + } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDirectiveDynamic5",@" +// Note: this is weird, but is supported by language. It checks just that the ValueText is `dynamic`, not the raw text. +using D = @dynamic; + +class C +{ + void M(D d) + { + d.Goo(); + } +}") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDuplicate1",""" + using X = int?; + using X = System; + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDuplicate2",""" + using X = int?; + using X = int; + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingDuplicate3",""" + using X = int?; + using X = System.Int32; + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.AliasUsingNotDuplicate1",""" + using X = int?; + namespace N; + using X = int; + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.TestObsolete1",""" + using System; + using X = C; + + [Obsolete("", error: true)] + class C + { + } + + class D + { + X x; + C c; + } + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.TestObsolete2",""" + using System; + using X = C[]; + + [Obsolete("", error: true)] + class C + { + } + + class D + { + X x1; + C[] c1; + } + """) + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_SafeType_CSharp11_NoUnsafeFlag",@"using static unsafe System.Console;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_SafeType_CSharp11_UnsafeFlag",@"using static unsafe System.Console;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_SafeType_CSharp12_NoUnsafeFlag",@"using static unsafe System.Console;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_SafeType_CSharp12_UnsafeFlag",@"using static unsafe System.Console;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_UnsafeType_CSharp11_NoUnsafeFlag",@"using static unsafe System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_UnsafeType_CSharp11_UnsafeFlag",@"using static unsafe System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_UnsafeType_CSharp12_NoUnsafeFlag",@"using static unsafe System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStaticUnsafe_UnsafeType_CSharp12_UnsafeFlag",@"using static unsafe System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStatic_UnsafeType_CSharp11_NoUnsafeFlag",@"using static System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStatic_UnsafeType_CSharp11_UnsafeFlag",@"using static System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStatic_UnsafeType_CSharp12_NoUnsafeFlag",@"using static System.Collections.Generic.List;") + }; + + yield return new object[] + { + new SourceTestCase("UsingDirectiveParsingTests.UsingStatic_UnsafeType_CSharp12_UnsafeFlag",@"using static System.Collections.Generic.List;") + }; + + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/SourceTestCase.cs b/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/SourceTestCase.cs new file mode 100644 index 00000000..cd663cda --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/RoslynTestCases/SourceTestCase.cs @@ -0,0 +1,6 @@ +namespace Rewrite.CSharp.Tests.RoslynTestCases; + +public record SourceTestCase(string Name, string SourceText) +{ + public override string ToString() => Name; +} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionParser.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionParser.cs deleted file mode 100644 index 6c4854d2..00000000 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionParser.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.Reflection; -using log4net; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.MSBuild; -using Rewrite.Core; -using Rewrite.RewriteCSharp; - -namespace Rewrite.CSharp.Tests.Solutions; - -public class SolutionParser -{ - private static readonly ILog log = LogManager.GetLogger(typeof(SolutionParser)); - - public async Task LoadSolutionAsync(string solutionFilePath, CancellationToken cancellationToken) - { - var workspace = MSBuildWorkspace.Create(); - return await workspace.OpenSolutionAsync(solutionFilePath, cancellationToken: cancellationToken); - } - - public IEnumerable ParseProjectSources(Solution solution, string projectName, string rootDir, - InMemoryExecutionContext ctx) - { - var project = solution.Projects.First(it => it.FilePath!.Equals(projectName)); - var fullProjectPath = Path.GetFullPath(Path.GetDirectoryName(project.FilePath!)!); - var objPath = Path.Combine(Path.GetDirectoryName(project.FilePath!)!, "obj"); - var builder = new CSharpParser.Builder(); - var allMetadataReferences = GetAllMetadataReferences(project); - var parser = builder.References(allMetadataReferences).Build(); - - IList inputs = []; - foreach (var doc in project.Documents - .Where(d => d.SourceCodeKind == SourceCodeKind.Regular) - .Where(d => Path.GetFullPath(d.FilePath!).StartsWith(fullProjectPath)) - .Where(d => !d.FilePath!.StartsWith(objPath))) - { - inputs.Add(new Parser.Input(Path.GetFullPath(doc.FilePath!), - () => new FileStream(doc.FilePath!, FileMode.Open))); - } - - var sourceFiles = parser.ParseInputs(inputs, rootDir, ctx); - return sourceFiles; - } - - private static IEnumerable GetAllMetadataReferences(Project project) - { - var allReferences = new HashSet(); - var projectsToProcess = new Queue(); - projectsToProcess.Enqueue(project); - - while (projectsToProcess.Count > 0) - { - var currentProject = projectsToProcess.Dequeue(); - - // Add metadata references of the current project - foreach (var reference in currentProject.MetadataReferences) - allReferences.Add(reference); - - // Queue up the referenced projects for processing - foreach (var projectReference in currentProject.ProjectReferences) - { - var referencedProject = project.Solution.GetProject(projectReference.ProjectId); - if (referencedProject != null && !projectsToProcess.Contains(referencedProject)) - projectsToProcess.Enqueue(referencedProject); - } - } - - return allReferences; - } -} diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs b/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs index 30f0c148..6449d94a 100644 --- a/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs +++ b/Rewrite/tests/Rewrite.CSharp.Tests/Solutions/SolutionTests.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Runtime.ExceptionServices; using System.Text.RegularExpressions; +using Rewrite.MSBuild; using Rewrite.Test.CSharp; namespace Rewrite.CSharp.Tests.Solutions; diff --git a/Rewrite/tests/Rewrite.CSharp.Tests/StringAssertionExtensions.cs b/Rewrite/tests/Rewrite.CSharp.Tests/StringAssertionExtensions.cs new file mode 100644 index 00000000..e4dee25b --- /dev/null +++ b/Rewrite/tests/Rewrite.CSharp.Tests/StringAssertionExtensions.cs @@ -0,0 +1,133 @@ +using System.Text; +using System.Text.RegularExpressions; +using DiffPlex; +using DiffPlex.Chunkers; +using DiffPlex.DiffBuilder.Model; +using Socolin.ANSITerminalColor; + +namespace Rewrite.CSharp.Tests; + +public static class StringAssertionExtensions +{ + + public static void ShouldBeSameAs(this string newText, string oldText) + { + var result = GetDifferences(oldText, newText); + if (result != null) + { + Assert.Fail($"Expected string to be the same but are different\n{result}"); + } + } + public static string? GetDifferences(string oldText, string newText) + { + string AddVisibleCrLf(string str) => + Regex.Replace(str.Replace("\r", "\u240D").Replace("\n", "\u2424"), "([\u240D\u2424]+)", "$1\n");// + (AnsiColor.ColorizeText("<-EOF", AnsiColor.Foreground(Terminal256ColorCodes.Yellow1C226))); + oldText = AddVisibleCrLf(oldText); + newText = AddVisibleCrLf(newText); + + var differ = new Differ(); + var diff = DiffPlex.DiffBuilder.SideBySideDiffBuilder.Diff(differ, oldText, newText, ignoreWhiteSpace: false, wordChunker: new CharacterChunker()); + if (!diff.NewText.HasDifferences) + return null; + int padSize = diff.OldText.Lines.Count > 0 ? (int)Math.Log10(diff.OldText.Lines.Count) + 1 : 1; + + var result = new StringBuilder(); + var oldLastLineIndex = diff.OldText.Lines.Last(x => x.Type != ChangeType.Imaginary).Position; + var newLastLineIndex = diff.NewText.Lines.Last(x => x.Type != ChangeType.Imaginary).Position; + for (int i = 0; i < diff.OldText.Lines.Count ; i++) + { + var oldLine = diff.OldText.Lines[i]; + var newLine = diff.NewText.Lines[i]; + var lineChange = diff.NewText.Lines[i].Type; + if (lineChange == ChangeType.Unchanged) + continue; + result.AppendLine("-------------------"); + string oldRender = AnsiColor.ColorizeText(oldLine.Text, AnsiColor.Background(Terminal256ColorCodes.BlackC0))!; + string newRender = AnsiColor.ColorizeText(newLine.Text, AnsiColor.Background(Terminal256ColorCodes.BlackC0))!; + if (oldLine.Text != null && newLine.Text != null) + { + // check if this is a pure linebreak issue. if it is, collapse diffs for this line and next, into a single diff rendering (we just need to highlight the missing line break characters) + var oldThisAndNextLine = diff.OldText.Lines.Count > i + 1 ? oldLine.Text + diff.OldText.Lines[i+1].Text : oldLine.Text; + var newThisAndNextLine = diff.NewText.Lines.Count > i + 1 ? newLine.Text + diff.NewText.Lines[i+1].Text : newLine.Text; + string StripWhitespace(string str) => Regex.Replace(str,"[\u240D\u2424\n]",""); + if(StripWhitespace(oldThisAndNextLine) == StripWhitespace(newThisAndNextLine)) + { + var twoLineDiff = DiffPlex.DiffBuilder.SideBySideDiffBuilder.Diff(differ, oldThisAndNextLine, newThisAndNextLine, ignoreWhiteSpace: false, wordChunker: new CharacterChunker()); + oldLine = twoLineDiff.OldText.Lines[0]; + newLine = twoLineDiff.NewText.Lines[0]; + i++; + } + } + + + if (lineChange == ChangeType.Modified) + { + oldRender = GetDiffText(oldLine.SubPieces); + newRender = GetDiffText(newLine.SubPieces); + } + + var oldLineNum = oldLine.Position?.ToString(); + var newLineNum = newLine.Position?.ToString(); + + oldLineNum = $"{AnsiColor.ColorizeText(oldLineNum, GetStyle(oldLine.Type))}|".PadLeft(padSize); + newLineNum = $"{AnsiColor.ColorizeText(newLineNum, GetStyle(newLine.Type))}|".PadLeft(padSize); + + // if whole line is different, then make every character take line colour + if (oldLine.Type is not ChangeType.Modified) + { + oldRender = AnsiColor.ColorizeText(oldLine.Text, GetStyle(oldLine.Type))!; + } + if (newLine.Type is not ChangeType.Modified) + { + newRender = AnsiColor.ColorizeText(newLine.Text!, GetStyle(newLine.Type))!; + } + // append EOF character + if (oldLine.Position == oldLastLineIndex) + { + oldRender += AnsiColor.ColorizeText("\u2403", AnsiColor.Foreground(Terminal256ColorCodes.YellowC11)); + } + if (newLine.Position == oldLastLineIndex) + { + newRender += AnsiColor.ColorizeText("\u2403", AnsiColor.Foreground(Terminal256ColorCodes.YellowC11)); + } + + if (oldLine.Type is not ChangeType.Imaginary) + result.AppendLine($"{oldLineNum}{oldRender}"); + + if (newLine.Type is not ChangeType.Imaginary) + result.AppendLine($"{newLineNum}{newRender}"); + } + + return result.ToString(); + } + + static string GetDiffText(List current) + { + var sb = new StringBuilder(); + foreach (var charDelta in current) + { + var text = charDelta.Text; + if (charDelta.Type == ChangeType.Imaginary) + { + text = " "; + } + var style = GetStyle(charDelta.Type); + sb.Append(AnsiColor.ColorizeText(text, style)); + } + + return sb.ToString(); + } + + static AnsiColor GetStyle(ChangeType type) + { + return type switch + { + ChangeType.Deleted => AnsiColor.Composite(AnsiColor.Foreground(Terminal256ColorCodes.Red1C196), AnsiColor.Background(Terminal256ColorCodes.BlackC0)), + ChangeType.Inserted => AnsiColor.Composite(AnsiColor.Foreground(Terminal256ColorCodes.Green1C46), AnsiColor.Background(Terminal256ColorCodes.BlackC0)), + ChangeType.Modified => AnsiColor.Composite(AnsiColor.Background(Terminal256ColorCodes.Blue1C21)), + ChangeType.Imaginary => AnsiColor.Reset, // AnsiColor.Background(Terminal256ColorCodes.GreyC8), + // ChangeType.Imaginary => AnsiColor.Composite(AnsiColor.Background(Terminal256ColorCodes.GreyC8), AnsiColor.Foreground(Terminal256ColorCodes.SeaGreen3C78)), + _ => AnsiColor.Background(Terminal256ColorCodes.BlackC0) + }; + } +}