public void MemberMethodCallOnWildcard() { var tree = SyntaxFactory.ParseExpression("Foo.Bar.Baz()"); TreeMatcher.Match(tree, new Snippet("a.Baz()")) .Should().NotBeNull(); }
public void NoWildcardsExpressionAlmostMatches(string searchString) { var tree = SyntaxFactory.ParseExpression("Foo.Bar()"); TreeMatcher.Match(tree, new Snippet(searchString)) .Should().BeNull(); }
/// <summary> /// Command-line C# refactoring tool. /// </summary> /// <param name="from">Expression to be replaced.</param> /// <param name="to">Expression to replace <paramref name="from"/> with.</param> /// <param name="solutionPath">Path to a solution; replacement occurs for all compilation units in the solution.</param> /// <returns></returns> static async Task Main(string from, string to, string?solutionPath = null) { MSBuildLocator.RegisterDefaults(); var fromSnippet = new Snippet(from); var toSnippet = new Snippet(to); using var workspace = MSBuildWorkspace.Create(); var solution = await workspace.OpenSolutionAsync(solutionPath); foreach (var project in solution.Projects) { var compilation = await project.GetCompilationAsync(); foreach (var syntaxTree in compilation.SyntaxTrees) { foreach (var match in TreeMatcher.Matches(syntaxTree.GetRoot(), fromSnippet)) { Console.WriteLine(match); } } } }
public void WildcardWithDifferentArityDoesNotMatch() { var match = TreeMatcher.Match(tree.GetRoot(), new Snippet("Console.WriteLine(a, b)")); match.Should().BeNull(); }
public void WildcardMatchesStringLiteral() { var match = TreeMatcher.Match(tree.GetRoot(), new Snippet("Console.WriteLine(a)")); match.Should().NotBeNull(); }
public void DifferentLiteralTypeDifferenceIsDetected() { var match = TreeMatcher.Match(tree.GetRoot(), new Snippet("Console.WriteLine(12)")); match.Should().BeNull(); }
public void StringLiteralDifferenceIsDetected() { var match = TreeMatcher.Match(tree.GetRoot(), new Snippet("Console.WriteLine(\"Something else\")")); match.Should().BeNull(); }
public void PerfectExpressionMatchCanMatchOnlyOneExpressionOfKind() { var match = TreeMatcher.Match(tree.GetRoot(), new Snippet("Console.WriteLine(\"Hello, World!\")")); match.Should().NotBeNull(); }