public void WhenEqualWhitespaceEnd() { var x = @" namespace RoslynSandbox { class Foo { private readonly int _value; } } a "; var y = @" namespace RoslynSandbox { class Foo { private readonly int _value; } } a "; Assert.AreEqual(true, CodeComparer.Equals(x, y)); }
public void AnalyzersBenchmark(DiagnosticAnalyzer analyzer) { var expectedName = analyzer.GetType().Name + "Benchmarks"; var fileName = Path.Combine(BenchmarksDirectory, expectedName + ".cs"); var code = new StringBuilder().AppendLine("// ReSharper disable RedundantNameQualifier") .AppendLine($"namespace {this.GetType().Namespace}") .AppendLine("{") .AppendLine($" public class {expectedName}") .AppendLine(" {") .AppendLine($" private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new {analyzer.GetType().FullName}());") .AppendLine() .AppendLine(" [BenchmarkDotNet.Attributes.Benchmark]") .AppendLine(" public void RunOnIDisposableAnalyzers()") .AppendLine(" {") .AppendLine(" Benchmark.Run();") .AppendLine(" }") .AppendLine(" }") .AppendLine("}") .ToString(); if (!File.Exists(fileName) || !CodeComparer.Equals(File.ReadAllText(fileName), code)) { File.WriteAllText(fileName, code); Assert.Fail(); } }
public static void WhenEqualWhitespaceEnd() { var x = @" namespace N { class C { private readonly int _value; } } a "; var y = @" namespace N { class C { private readonly int _value; } } a "; Assert.AreEqual(true, CodeComparer.Equals(x, y)); }
public void AllBenchmarks() { var fileName = Path.Combine(Program.BenchmarksDirectory, "AllBenchmarks.cs"); var builder = new StringBuilder(); builder.AppendLine("// ReSharper disable RedundantNameQualifier") .AppendLine($"namespace {this.GetType().Namespace}") .AppendLine("{") .AppendLine(" [BenchmarkDotNet.Attributes.MemoryDiagnoser]") .AppendLine(" public class AllBenchmarks") .AppendLine(" {"); foreach (var analyzer in AllAnalyzers) { builder.AppendLine( $" private static readonly Gu.Roslyn.Asserts.Benchmark {analyzer.GetType().Name}Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.ValidCodeProject, new {analyzer.GetType().FullName}());") .AppendLine(); } foreach (var analyzer in AllAnalyzers) { builder.AppendLine($" [BenchmarkDotNet.Attributes.Benchmark]") .AppendLine($" public void {analyzer.GetType().Name}()") .AppendLine(" {") .AppendLine($" {analyzer.GetType().Name}Benchmark.Run();") .AppendLine(" }"); if (!ReferenceEquals(analyzer, AllAnalyzers[AllAnalyzers.Count - 1])) { builder.AppendLine(); } } builder.AppendLine(" }") .AppendLine("}"); var code = builder.ToString(); if (!File.Exists(fileName) || !CodeComparer.Equals(File.ReadAllText(fileName), code)) { File.WriteAllText(fileName, code); Assert.Fail(); } }
public void WhenNotEqual() { var x = @" namespace RoslynSandbox { class Foo { private readonly int _value; } }"; var y = @" namespace RoslynSandbox { class Foo { private readonly int bar; } }"; Assert.AreEqual(false, CodeComparer.Equals(x, y)); }
public static void WhenNotEqual() { var x = @" namespace N { class C { private readonly int _value; } }"; var y = @" namespace N { class C { private readonly int bar; } }"; Assert.AreEqual(false, CodeComparer.Equals(x, y)); }
public void WhenEqualMixedNewLines(string x, string y) { Assert.AreEqual(true, CodeComparer.Equals(x, y)); }