diff --git a/src/Verify.Terminal.IntegrationTests/Harness.cs b/src/Verify.Terminal.IntegrationTests/Harness.cs index 3cf2707..2f3b2af 100644 --- a/src/Verify.Terminal.IntegrationTests/Harness.cs +++ b/src/Verify.Terminal.IntegrationTests/Harness.cs @@ -216,10 +216,10 @@ public InlineSnapshot FindSingleInline() return finder.Find(Directory).Single(); } - public SnapshotResult Accept(ISnapshot snapshot) => + public static SnapshotResult Accept(ISnapshot snapshot) => CreateManager().Accept(snapshot); - public SnapshotResult Reject(ISnapshot snapshot) => + public static SnapshotResult Reject(ISnapshot snapshot) => CreateManager().Reject(snapshot); private static SnapshotManager CreateManager() diff --git a/src/Verify.Terminal.IntegrationTests/InlineSnapshotTests.cs b/src/Verify.Terminal.IntegrationTests/InlineSnapshotTests.cs index ff004fc..efc8909 100644 --- a/src/Verify.Terminal.IntegrationTests/InlineSnapshotTests.cs +++ b/src/Verify.Terminal.IntegrationTests/InlineSnapshotTests.cs @@ -54,7 +54,7 @@ public Task Sample() => // snapshot pending. harness.FindFileSnapshots().ShouldBeEmpty(); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); // The literal is written as the raw string Verify reads back, which is what makes the next // run pass rather than fail against its own snapshot. @@ -101,7 +101,7 @@ public Task Sample() => snapshot.Expected.ShouldBeEmpty(); snapshot.Received.ShouldBe(Value); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); harness.ReadSource().ShouldBe( """" @@ -165,7 +165,7 @@ await Fails( // Accept: asked of the owner, which applies the patch and drops the entry, so every // surface agrees the snapshot is no longer pending. - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); harness.ReadSource().ShouldBe( """" @@ -201,7 +201,7 @@ public Task Sample() => await Fails(harness, _ => _.Snapshot("old snapshot", source, 4, "\"old snapshot\"", "Sample")); harness.PublishInline().ShouldBe(1); - harness.Reject(harness.FindSingleInline()).Succeeded.ShouldBeTrue(); + Harness.Reject(harness.FindSingleInline()).Succeeded.ShouldBeTrue(); harness.ReadSource().ShouldBe(before); diff --git a/src/Verify.Terminal.IntegrationTests/IntegrationTestBase.cs b/src/Verify.Terminal.IntegrationTests/IntegrationTestBase.cs index b5f854f..bb648aa 100644 --- a/src/Verify.Terminal.IntegrationTests/IntegrationTestBase.cs +++ b/src/Verify.Terminal.IntegrationTests/IntegrationTestBase.cs @@ -38,7 +38,7 @@ protected static string AssemblyConfiguration() => // snapshots from an older Verify, or when obj is not scanned. Both have to reach the same file. // Looped rather than a [Theory], since a test method parameter would be appended to the snapshot // name by Verify and change the very names under assertion. - protected async Task AssertExistingVerifiedIsDetected( + protected static async Task AssertExistingVerifiedIsDetected( string method, Action configure, string expectedVerified) @@ -83,7 +83,7 @@ async Task Run(bool withMap) var literal = received.Replace(".received.", ".verified."); snapshot.IsRerouted.ShouldBe(correctVerified != literal, because); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(because); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(because); // The received value now lives at the correct verified name, so Verify passes. (await Verifies(settings)).ShouldBeTrue(because); @@ -93,7 +93,7 @@ async Task Run(bool withMap) // A brand new snapshot with no verified file on disk. With nothing to pair against, the finder // falls back to the received-derived name. Whether that is correct depends on whether the correct // verified name equals the received-derived name. - protected async Task AssertNewSnapshot( + protected static async Task AssertNewSnapshot( string method, Action configure, string expectedVerified, @@ -118,14 +118,14 @@ protected async Task AssertNewSnapshot( System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(literal); snapshot.IsRerouted.ShouldBeFalse(); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); (await Verifies(settings)).ShouldBe(expectRoundTrips); } // A brand new snapshot, but with Verify's received map available. The map names the verified file, // so the finder places it correctly instead of falling back to the received-derived name. - protected async Task AssertNewSnapshotWithMap( + protected static async Task AssertNewSnapshotWithMap( string method, Action configure, string expectedVerified) @@ -149,7 +149,7 @@ protected async Task AssertNewSnapshotWithMap( System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(correctVerified); snapshot.IsRerouted.ShouldBe(correctVerified != received.Replace(".received.", ".verified.")); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); // The accept landed where Verify expects, so the next run passes. (await Verifies(settings)).ShouldBeTrue(); diff --git a/src/Verify.Terminal.IntegrationTests/ParameterNamingTests.cs b/src/Verify.Terminal.IntegrationTests/ParameterNamingTests.cs index 0954ee2..1cce8a6 100644 --- a/src/Verify.Terminal.IntegrationTests/ParameterNamingTests.cs +++ b/src/Verify.Terminal.IntegrationTests/ParameterNamingTests.cs @@ -30,7 +30,7 @@ public Task IgnoreTrailingParameter_ExistingVerified_IsDetected(string a, string // Run against both the map, which is how Verify behaves now, and the fallback, which still applies // to an older Verify, or when obj is not scanned. Looped rather than another [InlineData], since an extra // test method parameter would be appended to the snapshot name by Verify. - async Task AssertParametersAreDetected(string name, string a, string b, string? ignored, string expectedVerified) + static async Task AssertParametersAreDetected(string name, string a, string b, string? ignored, string expectedVerified) { await Run(withMap: true); await Run(withMap: false); @@ -41,23 +41,18 @@ async Task Run(bool withMap) { using var harness = new Harness(name); - VerifySettings Settings() + var settings = harness.CreateSettings(); + settings.UseTypeName("N"); + settings.UseMethodName("Params"); + settings.UseParameters(a, b); + if (ignored != null) { - var settings = harness.CreateSettings(); - settings.UseTypeName("N"); - settings.UseMethodName("Params"); - settings.UseParameters(a, b); - if (ignored != null) - { - settings.IgnoreParameters(ignored); - } - - return settings; + settings.IgnoreParameters(ignored); } var because = withMap ? "with map" : "without map"; - var correctVerified = await ProduceReceived(Settings()); + var correctVerified = await ProduceReceived(settings); correctVerified.ShouldBe(expectedVerified, because); var received = harness.ReceivedFileNames().ShouldHaveSingleItem(); @@ -74,8 +69,8 @@ VerifySettings Settings() System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(correctVerified, because); snapshot.IsRerouted.ShouldBeTrue(because); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(because); - (await Verifies(Settings())).ShouldBeTrue(because); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(because); + (await Verifies(settings)).ShouldBeTrue(because); } } @@ -85,17 +80,13 @@ public async Task IgnoreLeadingParameter_WithMap_IsPlaced(string a, string b) { using var harness = new Harness(nameof(IgnoreLeadingParameter_WithMap_IsPlaced)); - VerifySettings Settings() - { - var settings = harness.CreateSettings(); - settings.UseTypeName("N"); - settings.UseMethodName("Params"); - settings.UseParameters(a, b); - settings.IgnoreParameters("a"); - return settings; - } + var settings = harness.CreateSettings(); + settings.UseTypeName("N"); + settings.UseMethodName("Params"); + settings.UseParameters(a, b); + settings.IgnoreParameters("a"); - var correctVerified = await ProduceReceived(Settings()); + var correctVerified = await ProduceReceived(settings); correctVerified.ShouldBe("N.Params_b=2.verified.txt"); harness.SeedVerified(correctVerified, "old-verified"); @@ -106,8 +97,8 @@ VerifySettings Settings() System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(correctVerified); snapshot.IsRerouted.ShouldBeTrue(); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); - (await Verifies(Settings())).ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + (await Verifies(settings)).ShouldBeTrue(); } [Theory] @@ -116,17 +107,13 @@ public async Task IgnoreLeadingParameter_WithoutMap_CannotBePaired(string a, str { using var harness = new Harness(nameof(IgnoreLeadingParameter_WithoutMap_CannotBePaired)); - VerifySettings Settings() - { - var settings = harness.CreateSettings(); - settings.UseTypeName("N"); - settings.UseMethodName("Params"); - settings.UseParameters(a, b); - settings.IgnoreParameters("a"); - return settings; - } + var settings = harness.CreateSettings(); + settings.UseTypeName("N"); + settings.UseMethodName("Params"); + settings.UseParameters(a, b); + settings.IgnoreParameters("a"); - var correctVerified = await ProduceReceived(Settings()); + var correctVerified = await ProduceReceived(settings); // The leading parameter `a` is dropped, so the verified name is not a prefix of the received name. correctVerified.ShouldBe("N.Params_b=2.verified.txt"); @@ -141,11 +128,11 @@ VerifySettings Settings() System.IO.Path.GetFileName(snapshot.Verified.FullPath).ShouldBe(literal); snapshot.IsRerouted.ShouldBeFalse(); - harness.Accept(snapshot).Succeeded.ShouldBeTrue(); + Harness.Accept(snapshot).Succeeded.ShouldBeTrue(); // A non-trailing ignored parameter cannot be reconstructed from the received name, so the // accept lands at the wrong verified file and Verify still fails. This is only reachable // without a map, ie. an older Verify, or when obj is not scanned. See the WithMap case above. - (await Verifies(Settings())).ShouldBeFalse(); + (await Verifies(settings)).ShouldBeFalse(); } } diff --git a/src/Verify.Terminal.Tests/InlineSnapshotFinderTests.cs b/src/Verify.Terminal.Tests/InlineSnapshotFinderTests.cs index 8009d9f..7420a53 100644 --- a/src/Verify.Terminal.Tests/InlineSnapshotFinderTests.cs +++ b/src/Verify.Terminal.Tests/InlineSnapshotFinderTests.cs @@ -69,7 +69,7 @@ public void Should_Merge_Staged_Patches_That_Agree() // with both sets of files to clear once it is dealt with. var fileSystem = CreateFileSystem(); InlineTestData.Stage(fileSystem, InlineTestData.Patch("new snapshot"), "DotNet8_0"); - InlineTestData.Stage(fileSystem, InlineTestData.Patch("new snapshot"), "DotNet10_0"); + InlineTestData.Stage(fileSystem, InlineTestData.Patch("new snapshot")); var result = Find(fileSystem).ShouldHaveSingleItem(); @@ -83,7 +83,7 @@ public void Should_Flag_Staged_Patches_That_Disagree() { var fileSystem = CreateFileSystem(); InlineTestData.Stage(fileSystem, InlineTestData.Patch("from net8"), "DotNet8_0"); - InlineTestData.Stage(fileSystem, InlineTestData.Patch("from net10"), "DotNet10_0"); + InlineTestData.Stage(fileSystem, InlineTestData.Patch("from net10")); var result = Find(fileSystem).ShouldHaveSingleItem(); @@ -156,7 +156,7 @@ private static InlinePatch Origin(InlinePatch patch, string framework) } private static FakeFileSystem CreateFileSystem() => - new(new FakeEnvironment(PlatformFamily.Linux)); + new(new(PlatformFamily.Linux)); private static IReadOnlyList Find( FakeFileSystem fileSystem, diff --git a/src/Verify.Terminal.Tests/InlineSnapshotManagerTests.cs b/src/Verify.Terminal.Tests/InlineSnapshotManagerTests.cs index 1f561d7..557266c 100644 --- a/src/Verify.Terminal.Tests/InlineSnapshotManagerTests.cs +++ b/src/Verify.Terminal.Tests/InlineSnapshotManagerTests.cs @@ -242,7 +242,7 @@ public void Should_Clear_The_Staged_Files_On_Reject() } private static FakeFileSystem CreateFileSystem() => - new(new FakeEnvironment(PlatformFamily.Linux)); + new(new(PlatformFamily.Linux)); private static InlineSnapshotManager Create( IInlineQueueOwner? queue = null, @@ -262,7 +262,7 @@ private static IReadOnlyList Staged(FakeFileSystem fileSystem, Inl // Through the finder rather than by hand, so the manager is handed what it is handed in a // real run: the patch as it was read back off disk, beside the files it was read from. return finder - .Find(new DirectoryPath("/Working")) + .Find(new("/Working")) .SelectMany(_ => _.Staged) .ToList(); } @@ -271,7 +271,7 @@ private static IReadOnlyList StagedFiles(FakeFileSystem fileSystem) { var globber = new Globber(fileSystem, new FakeEnvironment(PlatformFamily.Linux)); return globber - .Match("**/VerifyInline/*", new GlobberSettings { Root = new DirectoryPath("/Working") }) + .Match("**/VerifyInline/*", new() { Root = new("/Working") }) .OfType() .Select(_ => _.FullPath) .ToList(); diff --git a/src/Verify.Terminal.Tests/SnapshotRendererTests.cs b/src/Verify.Terminal.Tests/SnapshotRendererTests.cs index 73b4811..9a9c014 100644 --- a/src/Verify.Terminal.Tests/SnapshotRendererTests.cs +++ b/src/Verify.Terminal.Tests/SnapshotRendererTests.cs @@ -84,7 +84,7 @@ public Task Should_Render_A_Conflicted_Inline_Snapshot() // are there. var diff = differ.Diff( new InlineSnapshot( - InlineTestData.Patch("from net10", "old snapshot"), + InlineTestData.Patch("from net10"), isQueued: true, conflict: "net8.0 / net10.0")); diff --git a/src/Verify.Terminal/Program.cs b/src/Verify.Terminal/Program.cs index defd58e..e089cc5 100644 --- a/src/Verify.Terminal/Program.cs +++ b/src/Verify.Terminal/Program.cs @@ -38,6 +38,6 @@ private static TypeRegistrar BuildContainer() services.AddSingleton(); services.AddSingleton(); - return new TypeRegistrar(services); + return new(services); } } diff --git a/src/Verify.Terminal/Rendering/ReportBuilder.cs b/src/Verify.Terminal/Rendering/ReportBuilder.cs index 5917d6d..946833b 100644 --- a/src/Verify.Terminal/Rendering/ReportBuilder.cs +++ b/src/Verify.Terminal/Rendering/ReportBuilder.cs @@ -13,8 +13,8 @@ public sealed class ReportBuilder public ReportBuilder(IAnsiConsole console, CharacterSet characters) { _console = console.NotNull(); - _buffer = new List(); - _lines = new List(); + _buffer = new(); + _lines = new(); Characters = characters.NotNull(); } @@ -42,12 +42,12 @@ public void Append(string text, Color? color = null, Decoration? decoration = nu text = text[..maxLength.Value]; } - _buffer.Add(new Segment(text, new Style(foreground: color, decoration: decoration))); + _buffer.Add(new(text, new(foreground: color, decoration: decoration))); } public void Append(char character, Color? color = null, Decoration? decoration = null) { - _buffer.Add(new Segment(new string(character, 1), new Style(foreground: color, decoration: decoration))); + _buffer.Add(new(new(character, 1), new(foreground: color, decoration: decoration))); } public void AppendRepeated(Character character, int count, Color? color = null) @@ -80,7 +80,7 @@ public void CommitLine() AppendSpace(); } - _lines.Add(new SegmentLine(_buffer)); + _lines.Add(new(_buffer)); _buffer.Clear(); } diff --git a/src/Verify.Terminal/Rendering/ReportRenderable.cs b/src/Verify.Terminal/Rendering/ReportRenderable.cs index dbb5369..540e312 100644 --- a/src/Verify.Terminal/Rendering/ReportRenderable.cs +++ b/src/Verify.Terminal/Rendering/ReportRenderable.cs @@ -8,12 +8,12 @@ internal sealed class ReportRenderable : IRenderable public ReportRenderable(IEnumerable lines) { - _lines = new List(lines.NotNull()); + _lines = new(lines.NotNull()); } public Measurement Measure(RenderOptions context, int maxWidth) { - return new Measurement(maxWidth, maxWidth); + return new(maxWidth, maxWidth); } public IEnumerable Render(RenderOptions context, int maxWidth) diff --git a/src/Verify.Terminal/SnapshotDiff.cs b/src/Verify.Terminal/SnapshotDiff.cs index fa99d2e..cd87e57 100644 --- a/src/Verify.Terminal/SnapshotDiff.cs +++ b/src/Verify.Terminal/SnapshotDiff.cs @@ -66,7 +66,7 @@ public SnapshotDiff(ISnapshot snapshot, List old, List @ne if (ranges.Count == 0) { - return new List<(int Start, int Stop)>(); + return new(); } return MergeRanges(ranges); diff --git a/src/Verify.Terminal/SnapshotDiffer.cs b/src/Verify.Terminal/SnapshotDiffer.cs index 6e693ac..ab01c06 100644 --- a/src/Verify.Terminal/SnapshotDiffer.cs +++ b/src/Verify.Terminal/SnapshotDiffer.cs @@ -17,7 +17,7 @@ public SnapshotDiff Diff(ISnapshot snapshot) var diff = SideBySideDiffBuilder.Instance.BuildDiffModel(oldText, newText, false); - return new SnapshotDiff(snapshot, diff.OldText.Lines, diff.NewText.Lines); + return new(snapshot, diff.OldText.Lines, diff.NewText.Lines); } private (string Old, string New) Text(ISnapshot snapshot) diff --git a/src/Verify.Terminal/SnapshotFinder.cs b/src/Verify.Terminal/SnapshotFinder.cs index d23b923..bfa42a4 100644 --- a/src/Verify.Terminal/SnapshotFinder.cs +++ b/src/Verify.Terminal/SnapshotFinder.cs @@ -42,7 +42,7 @@ public ISet Find(DirectoryPath? root = null) foreach (var received in Match(root, "**/*.received.*", "received")) { var (verifiedPath, isRerouted) = GetVerified(received, maps, verifiedByDirectory); - result.Add(new Snapshot(received.Path, verifiedPath, isRerouted)); + result.Add(new(received.Path, verifiedPath, isRerouted)); } return result; @@ -50,7 +50,7 @@ public ISet Find(DirectoryPath? root = null) private IEnumerable Match(DirectoryPath root, string pattern, string marker) => _globber - .Match(pattern, new GlobberSettings { Root = root }) + .Match(pattern, new() { Root = root }) .OfType() .Where(_ => !IsInlineStaging(_)) .Select(_ => ParsedName.Parse(_, marker)); @@ -63,7 +63,7 @@ private static bool IsInlineStaging(FilePath path) => $"/{InlineSnapshotFinder.StagingDirectoryName}/", StringComparison.OrdinalIgnoreCase); - private (FilePath VerifiedPath, bool IsRerouted) GetVerified( + private static (FilePath VerifiedPath, bool IsRerouted) GetVerified( ParsedName received, ReceivedMaps maps, Dictionary> verifiedByDirectory)