public void Matches_IsTrue_WhenParametersAreEquivalent() { var function1 = @"using System; public static void Run(string id, out string output) { output = string.Empty; }"; // Diferent formatting, qualified name, not using alias var function2 = @"using System; public static void Run( System.String id , out String output ) { string result = string.Empty; output = result; }"; var tree1 = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var tree2 = CSharpSyntaxTree.ParseText(function2, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation1 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references) .AddSyntaxTrees(tree1)); var compilation2 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test2", references: references) .AddSyntaxTrees(tree1)); var signature1 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); var signature2 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); Assert.True(signature1.Equals(signature2)); Assert.Equal(signature1.GetHashCode(), signature2.GetHashCode()); }
private Tuple <FunctionSignature, FunctionSignature> GetFunctionSignatures(string function1, string function2) { var tree1 = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var tree2 = CSharpSyntaxTree.ParseText(function2, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation1 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references) .AddSyntaxTrees(tree1)); var compilation2 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test2", references: references) .AddSyntaxTrees(tree2)); var signature1 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); var signature2 = compilation2.GetEntryPointSignature(new FunctionEntryPointResolver()); return(Tuple.Create(signature1, signature2)); }
private Tuple<FunctionSignature, FunctionSignature> GetFunctionSignatures(string function1, string function2) { var tree1 = CSharpSyntaxTree.ParseText(function1, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var tree2 = CSharpSyntaxTree.ParseText(function2, CSharpParseOptions.Default.WithKind(SourceCodeKind.Script)); var references = new MetadataReference[] { MetadataReference.CreateFromFile(typeof(string).Assembly.Location) }; var compilation1 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test1", references: references) .AddSyntaxTrees(tree1)); var compilation2 = new Script.Description.CSharpCompilation(CodeAnalysis.CSharp.CSharpCompilation.Create("test2", references: references) .AddSyntaxTrees(tree2)); var signature1 = compilation1.GetEntryPointSignature(new FunctionEntryPointResolver()); var signature2 = compilation2.GetEntryPointSignature(new FunctionEntryPointResolver()); return Tuple.Create(signature1, signature2); }