Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/DiffEngine/Inline/RuntimeMoniker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static class RuntimeMoniker
return null;
}

// ReSharper disable once RedundantSuppressNullableWarningExpression
var parts = frameworkName!.Split(',');
var identifier = parts[0].Trim();
string? versionText = null;
Expand All @@ -35,7 +36,7 @@ static class RuntimeMoniker
var part = parts[index].Trim();
if (part.StartsWith("Version=v", StringComparison.Ordinal))
{
versionText = part.Substring("Version=v".Length);
versionText = part["Version=v".Length..];
break;
}
}
Expand All @@ -52,6 +53,7 @@ static class RuntimeMoniker
".NETCoreApp" when version.Major >= 5 => $"net{version.Major}.{minor}",
".NETCoreApp" => $"netcoreapp{version.Major}.{minor}",
// "4.6.2" reads as net462, matching how TFMs are written.
// ReSharper disable once RedundantSuppressNullableWarningExpression
".NETFramework" => "net" + versionText!.Replace(".", ""),
".NETStandard" => $"netstandard{version.Major}.{minor}",
_ => null
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngine/Viewer/ImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static class ImageExtensions
".webp"
];

static readonly HashSet<string> lookup = new(All, StringComparer.OrdinalIgnoreCase);
static readonly HashSet<string> lookup = [with(All, StringComparer.OrdinalIgnoreCase)];

public static bool Is(string path) =>
lookup.Contains(Path.GetExtension(path));
Expand Down
12 changes: 6 additions & 6 deletions src/DiffEngineTray.Tests/TrackerTrackedFilesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public async Task AcceptingATrackedMoveMovesTheFile()
{
await using var tracker = new RecordingTracker();
ITrackedFiles tracked = tracker;
File.WriteAllText(temp, "content");
await File.WriteAllTextAsync(temp, "content");
tracker.AddMove(temp, target, null, null, false, null);

var (ok, _) = tracked.Accept(TrackedKeys.ForMove(temp));

await Assert.That(ok).IsTrue();
await Assert.That(File.ReadAllText(target)).IsEqualTo("content");
await Assert.That(await File.ReadAllTextAsync(target)).IsEqualTo("content");
await Assert.That(tracker.Moves).IsEmpty();
}

Expand All @@ -86,7 +86,7 @@ public async Task ALockedMoveIsRefusedWithoutPrompting()
await using var tracker = new RecordingTracker(
lockedFilesResolver: (_, _) => throw new("must not prompt"));
ITrackedFiles tracked = tracker;
File.WriteAllText(temp, "content");
await File.WriteAllTextAsync(temp, "content");
tracker.AddMove(temp, target, null, null, false, null);
using (new FileStream(target, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
{
Expand Down Expand Up @@ -115,15 +115,15 @@ public async Task AcceptAllSweepsAndCountsWhatStayed()
await using var tracker = new RecordingTracker();
ITrackedFiles tracked = tracker;
tracker.AddDelete(file);
File.WriteAllText(temp, "content");
await File.WriteAllTextAsync(temp, "content");
tracker.AddMove(temp, target, null, null, false, null);

var (accepted, kept) = tracked.AcceptAll();

await Assert.That(accepted).IsEqualTo(2);
await Assert.That(kept).IsEqualTo(0);
await Assert.That(File.Exists(file)).IsFalse();
await Assert.That(File.ReadAllText(target)).IsEqualTo("content");
await Assert.That(await File.ReadAllTextAsync(target)).IsEqualTo("content");
}

[Test]
Expand All @@ -132,7 +132,7 @@ public async Task DiscardAllUntracksDeletesAndDropsMoveTemps()
await using var tracker = new RecordingTracker();
ITrackedFiles tracked = tracker;
tracker.AddDelete(file);
File.WriteAllText(temp, "content");
await File.WriteAllTextAsync(temp, "content");
tracker.AddMove(temp, target, null, null, false, null);

var count = tracked.DiscardAll();
Expand Down
18 changes: 8 additions & 10 deletions src/DiffEngineTray.Tests/TrayViewerSyncTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
extern alias viewer;

using System.Collections.Concurrent;

// The viewer's own copies of the protocol types. DiffEngineViewer links DiffEngine's Inline and
// Protocol sources rather than referencing them, so the same names exist in both assemblies and
// only the alias tells them apart. That duplication is the point of these tests: the two halves
Expand Down Expand Up @@ -130,7 +128,7 @@ public async Task TrayAcceptOfATrackedMoveReachesTheAttachedViewer()
pair.Tracker.Accept(pair.Tracker.Moves.Single());

await Assert.That(pair.Pump().Keys()).IsEquivalentTo([Key(sample, 1)]);
await Assert.That(File.ReadAllText(move.Target)).IsEqualTo("received");
await Assert.That(await File.ReadAllTextAsync(move.Target)).IsEqualTo("received");
}

[Test]
Expand Down Expand Up @@ -186,7 +184,7 @@ public async Task ViewerAcceptAllEmptiesTheTray()
await Assert.That(pair.Tracker.Snapshots).IsEmpty();
await Assert.That(pair.Tracker.Moves).IsEmpty();
await Assert.That(pair.Tracker.Deletes).IsEmpty();
await Assert.That(File.ReadAllText(move.Target)).IsEqualTo("received");
await Assert.That(await File.ReadAllTextAsync(move.Target)).IsEqualTo("received");
await Assert.That(File.Exists(delete.File)).IsFalse();
}

Expand Down Expand Up @@ -250,7 +248,7 @@ public async Task ViewerAcceptOfATrackedMoveReachesTheTray()

await Assert.That(pair.Pump().Keys()).IsEquivalentTo([Key(sample, 1)]);
await Assert.That(pair.Tracker.Moves).IsEmpty();
await Assert.That(File.ReadAllText(move.Target)).IsEqualTo("received");
await Assert.That(await File.ReadAllTextAsync(move.Target)).IsEqualTo("received");
}

/// <summary>
Expand Down Expand Up @@ -493,7 +491,7 @@ public async Task ADeleteWithNoTrayReachesTheViewerAndTheFileGoes()
using var noTray = new NoTray();
var file = pair.StageStaleFile();

DiffRunner.AddDelete(file);
await DiffRunner.AddDeleteAsync(file);

await Assert.That(pair.Viewer.Keys()).IsEquivalentTo([TrackedKeys.ForDelete(file)]);

Expand Down Expand Up @@ -535,7 +533,7 @@ public async Task AMoveWithNoTrayReachesTheViewerAndTheFileMoves()

pair.Act(CommandKind.Accept, move.Key);

await Assert.That(File.ReadAllText(move.Target)).IsEqualTo("received");
await Assert.That(await File.ReadAllTextAsync(move.Target)).IsEqualTo("received");
await Assert.That(File.Exists(move.Temp)).IsFalse();
}

Expand Down Expand Up @@ -564,7 +562,7 @@ public async Task AResentMoveReplacesItsEntry()
var move = pair.StageMove();
PendingFiles.AddMove(move.Temp, move.Target, null, null, false, null);

File.WriteAllText(move.Temp, "second run");
await File.WriteAllTextAsync(move.Temp, "second run");
PendingFiles.AddMove(move.Temp, move.Target, null, null, false, null);

await Assert.That(pair.Viewer.Queue).HasSingleItem();
Expand All @@ -581,7 +579,7 @@ public async Task AFullListingCarriesTheViewersOwnPendingFiles()
await using var pair = new ViewerOwned();
using var noTray = new NoTray();
var file = pair.StageStaleFile();
DiffRunner.AddDelete(file);
await DiffRunner.AddDeleteAsync(file);

var full = pair.Send(new(ViewerVerb.ListFull));
var plain = pair.Send(new(ViewerVerb.List));
Expand Down Expand Up @@ -801,7 +799,7 @@ public ViewerOwned(Func<ViewerSidePatch, ViewerSideApplyResult>? applier = null)
previousPort = Environment.GetEnvironmentVariable(ViewerClient.PortVariable);
Environment.SetEnvironmentVariable(ViewerClient.PortVariable, server.Port.ToString());
Window = new(SessionState.Start(ViewerMode.Inline));
actions = new ViewerActions(
actions = new(
patch =>
{
Applied.Add(patch);
Expand Down
10 changes: 5 additions & 5 deletions src/DiffEngineViewer.Tests/AttachedViewerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ public async Task MoveAndDeleteLinesMaterialize()
{
var temp = Path.Combine(Path.GetTempPath(), $"deview_{Guid.NewGuid():N}.received.txt");
var target = Path.Combine(Path.GetTempPath(), $"deview_{Guid.NewGuid():N}.verified.txt");
File.WriteAllText(temp, "incoming");
File.WriteAllText(target, "committed");
await File.WriteAllTextAsync(temp, "incoming");
await File.WriteAllTextAsync(target, "committed");
try
{
var (server, cancel) = Listing(() => ViewerResponse.Listing(
Expand Down Expand Up @@ -260,7 +260,7 @@ public async Task MoveAndDeleteLinesMaterialize()
public async Task AnUnreadableFileDegradesNotCrashes()
{
var file = Path.Combine(Path.GetTempPath(), $"deview_{Guid.NewGuid():N}.verified.txt");
File.WriteAllText(file, "locked away");
await File.WriteAllTextAsync(file, "locked away");
try
{
using var holder = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None);
Expand Down Expand Up @@ -294,7 +294,7 @@ public async Task AnUnreadableFileDegradesNotCrashes()
public async Task UnchangedFilesAreNotReReadAndAChangeRefreshes()
{
var file = Path.Combine(Path.GetTempPath(), $"deview_{Guid.NewGuid():N}.verified.txt");
File.WriteAllText(file, "first");
await File.WriteAllTextAsync(file, "first");
try
{
var (server, cancel) = Listing(() => ViewerResponse.Listing(
Expand All @@ -312,7 +312,7 @@ public async Task UnchangedFilesAreNotReReadAndAChangeRefreshes()
await Assert.That(host.State.Queue.Single()).IsSameReferenceAs(first);

// A stamp needs a distinct write time; length changing makes it deterministic.
File.WriteAllText(file, "second, longer");
await File.WriteAllTextAsync(file, "second, longer");
link.Pump();
await Assert.That(host.State.Queue.Single().RightText).IsEqualTo("second, longer");
await cancel.CancelAsync();
Expand Down
2 changes: 2 additions & 0 deletions src/DiffEngineViewer.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
global using System.Text.RegularExpressions;
global using System.Buffers.Binary;
global using System.IO.Compression;
2 changes: 0 additions & 2 deletions src/DiffEngineViewer.Tests/ImageHeaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Buffers.Binary;

/// <summary>
/// What the sniffer makes of each format's leading bytes.
/// <para>
Expand Down
4 changes: 2 additions & 2 deletions src/DiffEngineViewer.Tests/ImageScreenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public Task DeleteInQueue() =>
public async Task PanesCarryThePicture()
{
var screen = ScreenBuilder.Build(State(Received(), Expected()));
await Assert.That(screen.Left.Image).IsEqualTo(new ImagePane("temp/sample.received.png", 800, 600));
await Assert.That(screen.Right.Image).IsEqualTo(new ImagePane("code/sample.verified.png", 800, 600));
await Assert.That(screen.Left.Image).IsEqualTo(new("temp/sample.received.png", 800, 600));
await Assert.That(screen.Right.Image).IsEqualTo(new("code/sample.verified.png", 800, 600));
}

[Test]
Expand Down
4 changes: 0 additions & 4 deletions src/DiffEngineViewer.Tests/SamplePng.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Buffers.Binary;
using System.IO.Compression;
using System.Text;

/// <summary>
/// A real, decodable PNG built byte by byte.
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngineViewer.Tests/ViewerLaunchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public async Task GroupedQueue()
"Accepting the conflicted entry writes the variant on screen",
"Accept all skips the conflict and says 1 conflict needs review");

foreach (var patch in new engine::DiffEngine.InlinePatch[]
foreach (var patch in new[]
{
new(grouped, 6, "\"old value\"", "first new")
{
Expand Down
2 changes: 2 additions & 0 deletions src/DiffEngineViewer.Windows.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using System.Buffers.Binary;
global using System.IO.Compression;
2 changes: 1 addition & 1 deletion src/DiffEngineViewer.Windows.Tests/ImageCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task RedecodesWhenTheFileChanges()

// A different size, so the change is visible whatever the file system's timestamp
// resolution turns out to be.
File.WriteAllBytes(path, SamplePng.Build(4, 4, 40, 200, 40));
await File.WriteAllBytesAsync(path, SamplePng.Build(4, 4, 40, 200, 40));
await Assert.That(cache.Get(path)!.Width).IsEqualTo(4);
}

Expand Down
3 changes: 1 addition & 2 deletions src/DiffEngineViewer/Images/ImageHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ static bool TryJpeg(ReadOnlySpan<byte> bytes, out ImageHeader header)
continue;
}

if (marker == 0x01 ||
marker is >= 0xD0 and <= 0xD9)
if (marker is 0x01 or >= 0xD0 and <= 0xD9)
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DiffEngineViewer/Images/ImageRows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static Row Cell(int number, string label, string? value, string? other, RowKind
kind = value == other ? RowKind.Unchanged : RowKind.Modified;
}

return new(number, kind, $"{label.PadRight(labelWidth)}{value}");
return new(number, kind, $"{label,-labelWidth}{value}");
}

static string? Format(ImageFile? image)
Expand Down
2 changes: 0 additions & 2 deletions src/DiffEngineViewer/RevealFile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics;

/// <summary>
/// Shows a file in the platform's file manager. Best effort: revealing is a convenience beside
/// the review, so a missing file manager or a deleted file degrades to nothing rather than an
Expand Down
3 changes: 1 addition & 2 deletions src/DiffEngineViewer/ViewerProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ static SessionState Apply(SessionState state, ViewerInput input, OwnerLink? link
// resolve which item was chosen, so clearing first would swallow the command. And not when
// a right-click opened another menu in the same frame, which is the dismissal's successor
// rather than something to undo.
if (input.MenuClosed &&
input.RightClickedQueueItem < 0 &&
if (input is {MenuClosed: true, RightClickedQueueItem: < 0} &&
state.Menu is not null)
{
state = state with { Menu = null };
Expand Down
Loading