diff --git a/docs/diff-tool.custom.md b/docs/diff-tool.custom.md
index ea90e0c9..97132132 100644
--- a/docs/diff-tool.custom.md
+++ b/docs/diff-tool.custom.md
@@ -39,7 +39,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(
Left: (temp, target) => $"\"custom args \"{target}\" \"{temp}\"",
Right: (temp, target) => $"\"custom args \"{temp}\" \"{target}\""))!;
```
-snippet source | anchor
+snippet source | anchor
@@ -69,7 +69,7 @@ var resolvedTool = DiffTools.AddToolBasedOn(
await DiffRunner.LaunchAsync(resolvedTool!, "PathToTempFile", "PathToTargetFile");
```
-snippet source | anchor
+snippet source | anchor
diff --git a/docs/diff-tool.order.md b/docs/diff-tool.order.md
index 54094ecb..74ed923d 100644
--- a/docs/diff-tool.order.md
+++ b/docs/diff-tool.order.md
@@ -51,5 +51,5 @@ For example `VisualStudio,Meld` will result in VisualStudio then Meld then all o
```cs
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
```
-snippet source | anchor
+snippet source | anchor
diff --git a/src/DiffEngine.Tests/DiffEngine.Tests.csproj b/src/DiffEngine.Tests/DiffEngine.Tests.csproj
index a706f58f..617c73ad 100644
--- a/src/DiffEngine.Tests/DiffEngine.Tests.csproj
+++ b/src/DiffEngine.Tests/DiffEngine.Tests.csproj
@@ -16,6 +16,6 @@
-
+
\ No newline at end of file
diff --git a/src/DiffEngine.Tests/DiffToolsTest.cs b/src/DiffEngine.Tests/DiffToolsTest.cs
index b6bb3c92..7b882db0 100644
--- a/src/DiffEngine.Tests/DiffToolsTest.cs
+++ b/src/DiffEngine.Tests/DiffToolsTest.cs
@@ -55,6 +55,26 @@ public void OrderShouldNotMessWithAddTool()
Assert.Equal("MyCustomDiffTool", forExtension.Name);
}
+ [Fact]
+ public void TextConvention()
+ {
+ var diffToolPath = FakeDiffTool.Exe;
+ DiffTools.AddTool(
+ name: "MyCustomDiffTool",
+ autoRefresh: true,
+ isMdi: false,
+ supportsText: true,
+ requiresTarget: true,
+ launchArguments: new(
+ Left: (tempFile, targetFile) => $"\"{targetFile}\" \"{tempFile}\"",
+ Right: (tempFile, targetFile) => $"\"{tempFile}\" \"{targetFile}\""),
+ exePath: diffToolPath,
+ binaryExtensions: []);
+ var combine = Path.Combine(SourceDirectory, "input.temp.txtConvention");
+ Assert.True(DiffTools.TryFindForInputFilePath(combine, out var tool));
+ Assert.Equal("MyCustomDiffTool", tool.Name);
+ }
+
#if DEBUG
[Fact]
public void AddToolBasedOn()
@@ -99,34 +119,42 @@ public Task LaunchSpecificImageDiff() =>
DiffRunner.LaunchAsync(DiffTool.P4Merge,
Path.Combine(SourceDirectory, "input.temp.png"),
Path.Combine(SourceDirectory, "input.target.png"));
- **/
- //[Fact]
- //public async Task LaunchImageDiff()
- //{
- // foreach (var tool in DiffTools.Resolved)
- // {
- // await DiffRunner.LaunchAsync(tool,
- // Path.Combine(SourceDirectory, "input.temp.png"),
- // Path.Combine(SourceDirectory, "input.target.png"));
- // }
- //}
-
- //[Fact]
- //public async Task LaunchTextDiff()
- //{
- // foreach (var tool in DiffTools.Resolved)
- // {
- // await DiffRunner.LaunchAsync(tool,
- // Path.Combine(SourceDirectory, "input.temp.txt"),
- // Path.Combine(SourceDirectory, "input.target.txt"));
- // }
- //}
- /**
+
+ [Fact]
+ public async Task LaunchImageDiff()
+ {
+ foreach (var tool in DiffTools.Resolved)
+ {
+ await DiffRunner.LaunchAsync(tool,
+ Path.Combine(SourceDirectory, "input.temp.png"),
+ Path.Combine(SourceDirectory, "input.target.png"));
+ }
+ }
+
+ [Fact]
+ public async Task LaunchTextDiff()
+ {
+ foreach (var tool in DiffTools.Resolved)
+ {
+ await DiffRunner.LaunchAsync(tool,
+ Path.Combine(SourceDirectory, "input.temp.txt"),
+ Path.Combine(SourceDirectory, "input.target.txt"));
+ }
+ }
+
[Fact]
public Task LaunchSpecificTextDiff() =>
DiffRunner.LaunchAsync(DiffTool.WinMerge,
Path.Combine(SourceDirectory, "input.temp.txt"),
Path.Combine(SourceDirectory, "input.target.txt"));
+
+ [Fact]
+ public Task TextFileConvention()
+ {
+ var tempFile = Path.Combine(SourceDirectory, "input.temp.txtConvention");
+ var targetFile = Path.Combine(SourceDirectory, "input.target.txtConvention");
+ return DiffRunner.LaunchAsync(tempFile, targetFile);
+ }
**/
//todo: re enable tests with fake diff tool.
@@ -167,8 +195,7 @@ public void TryFindByName()
}
#endif
**/
- public DiffToolsTest(ITestOutputHelper output)
- :
+ public DiffToolsTest(ITestOutputHelper output) :
base(output) =>
DiffTools.Reset();
}
\ No newline at end of file
diff --git a/src/DiffEngine.Tests/GlobalUsings.cs b/src/DiffEngine.Tests/GlobalUsings.cs
index 6c8ea5c8..d8868e96 100644
--- a/src/DiffEngine.Tests/GlobalUsings.cs
+++ b/src/DiffEngine.Tests/GlobalUsings.cs
@@ -1,2 +1,3 @@
global using System.Collections.Immutable;
-global using System.Management;
\ No newline at end of file
+global using System.Management;
+global using EmptyFiles;
\ No newline at end of file
diff --git a/src/DiffEngine.Tests/ModuleInitializer.cs b/src/DiffEngine.Tests/ModuleInitializer.cs
index 2b1ce6dd..69da424e 100644
--- a/src/DiffEngine.Tests/ModuleInitializer.cs
+++ b/src/DiffEngine.Tests/ModuleInitializer.cs
@@ -5,6 +5,7 @@ public static class ModuleInitializer
[ModuleInitializer]
public static void Initialize()
{
+ FileExtensions.AddTextFileConvention(_ => _.EndsWith(".txtConvention".AsSpan()));
Logging.Enable();
DiffRunner.Disabled = false;
}
diff --git a/src/DiffEngine.Tests/input.target.txtConvention b/src/DiffEngine.Tests/input.target.txtConvention
new file mode 100644
index 00000000..a1098ab7
--- /dev/null
+++ b/src/DiffEngine.Tests/input.target.txtConvention
@@ -0,0 +1 @@
+target
\ No newline at end of file
diff --git a/src/DiffEngine.Tests/input.temp.txtConvention b/src/DiffEngine.Tests/input.temp.txtConvention
new file mode 100644
index 00000000..86345cb7
--- /dev/null
+++ b/src/DiffEngine.Tests/input.temp.txtConvention
@@ -0,0 +1 @@
+temp
\ No newline at end of file
diff --git a/src/DiffEngine/DiffRunner.cs b/src/DiffEngine/DiffRunner.cs
index 0ef3d733..b674c657 100644
--- a/src/DiffEngine/DiffRunner.cs
+++ b/src/DiffEngine/DiffRunner.cs
@@ -59,10 +59,7 @@ public static Task LaunchAsync(string tempFile, string targetFile,
return InnerLaunchAsync(
([NotNullWhen(true)] out ResolvedTool? tool) =>
- {
- var extension = Path.GetExtension(tempFile);
- return DiffTools.TryFindByExtension(extension, out tool);
- },
+ DiffTools.TryFindForInputFilePath(tempFile, out tool),
tempFile,
targetFile,
encoding);
diff --git a/src/DiffEngine/DiffTools_TryFind.cs b/src/DiffEngine/DiffTools_TryFind.cs
index 37ed13de..326adbad 100644
--- a/src/DiffEngine/DiffTools_TryFind.cs
+++ b/src/DiffEngine/DiffTools_TryFind.cs
@@ -20,6 +20,33 @@ public static bool TryFindByExtension(
return ExtensionLookup.TryGetValue(extension, out tool);
}
+ public static bool TryFindForInputFilePath(
+ string path,
+ [NotNullWhen(true)] out ResolvedTool? tool)
+ {
+ if (FileExtensions.IsTextFile(path))
+ {
+ tool = resolved.FirstOrDefault(_ => _.SupportsText);
+ return tool != null;
+ }
+
+ return ExtensionLookup.TryGetValue(Path.GetExtension(path), out tool);
+ }
+
+ public static bool TryFindForInputFilePath(
+ CharSpan path,
+ [NotNullWhen(true)] out ResolvedTool? tool)
+ {
+ if (FileExtensions.IsTextFile(path))
+ {
+ tool = resolved.FirstOrDefault(_ => _.SupportsText);
+ return tool != null;
+ }
+
+ var extension = PathPolyfill.GetExtension(path).ToString();
+ return ExtensionLookup.TryGetValue(extension, out tool);
+ }
+
public static bool TryFindByName(
DiffTool tool,
[NotNullWhen(true)] out ResolvedTool? resolvedTool)