Skip to content

Commit 889caba

Browse files
authored
Add LaunchForTextAsync (#591)
1 parent 43ced8a commit 889caba

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

docs/diff-tool.order.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ For example `VisualStudio,Meld` will result in VisualStudio then Meld then all o
5151
```cs
5252
DiffTools.UseOrder(DiffTool.VisualStudio, DiffTool.AraxisMerge);
5353
```
54-
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L167-L171' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseOrder' title='Start of snippet'>anchor</a></sup>
54+
<sup><a href='/src/DiffEngine.Tests/DiffToolsTest.cs#L174-L178' title='Snippet source file'>snippet source</a> | <a href='#snippet-UseOrder' title='Start of snippet'>anchor</a></sup>
5555
<!-- endSnippet -->

src/DiffEngine.Tests/DiffToolsTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,15 @@ public Task TextFileConvention()
155155
var targetFile = Path.Combine(SourceDirectory, "input.target.txtConvention");
156156
return DiffRunner.LaunchAsync(tempFile, targetFile);
157157
}
158-
**/
159158
159+
[Fact]
160+
public Task LaunchForTextAsync()
161+
{
162+
var tempFile = Path.Combine(SourceDirectory, "input.temp.txtConvention");
163+
var targetFile = Path.Combine(SourceDirectory, "input.target.txtConvention");
164+
return DiffRunner.LaunchForTextAsync(tempFile, targetFile);
165+
}
166+
**/
160167
//todo: re enable tests with fake diff tool.
161168

162169
/**

src/DiffEngine/DiffRunner.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ public static Task<LaunchResult> LaunchAsync(string tempFile, string targetFile,
6464
targetFile,
6565
encoding);
6666
}
67+
/// <summary>
68+
/// Launch a diff tool for the given paths.
69+
/// </summary>
70+
public static Task<LaunchResult> LaunchForTextAsync(string tempFile, string targetFile, Encoding? encoding = null)
71+
{
72+
GuardFiles(tempFile, targetFile);
73+
74+
return InnerLaunchAsync(
75+
([NotNullWhen(true)] out ResolvedTool? tool) =>
76+
DiffTools.TryFindForText(out tool),
77+
tempFile,
78+
targetFile,
79+
encoding);
80+
}
81+
82+
/// <summary>
83+
/// Launch a diff tool for the given paths.
84+
/// </summary>
85+
public static LaunchResult LaunchForText(string tempFile, string targetFile, Encoding? encoding = null)
86+
{
87+
GuardFiles(tempFile, targetFile);
88+
89+
return InnerLaunch(
90+
([NotNullWhen(true)] out ResolvedTool? tool) =>
91+
DiffTools.TryFindForText(out tool),
92+
tempFile,
93+
targetFile,
94+
encoding);
95+
}
6796

6897
public static LaunchResult Launch(ResolvedTool tool, string tempFile, string targetFile, Encoding? encoding = null)
6998
{

src/DiffEngine/DiffTools_TryFind.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public static bool TryFindByExtension(
2020
return ExtensionLookup.TryGetValue(extension, out tool);
2121
}
2222

23+
public static bool TryFindForText([NotNullWhen(true)] out ResolvedTool? tool)
24+
{
25+
tool = resolved.FirstOrDefault(_ => _.SupportsText);
26+
return tool != null;
27+
}
28+
2329
public static bool TryFindForInputFilePath(
2430
string path,
2531
[NotNullWhen(true)] out ResolvedTool? tool)

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649</NoWarn>
5-
<Version>15.7.1</Version>
5+
<Version>15.8.0</Version>
66
<AssemblyVersion>1.0.0</AssemblyVersion>
77
<PackageTags>Testing, Snapshot, Diff, Compare</PackageTags>
88
<Description>Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries.</Description>

0 commit comments

Comments
 (0)