-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDefinitionsTest.cs
222 lines (183 loc) · 6.21 KB
/
DefinitionsTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
public class DefinitionsTest(ITestOutputHelper output) :
XunitContextBase(output)
{
[Fact]
public void WriteList()
{
var md = Path.Combine(SourceDirectory, "diffToolList.include.md");
File.Delete(md);
using var writer = File.CreateText(md);
foreach (var tool in Definitions.Tools)
{
AddToolLink(writer, tool);
}
}
[Fact]
public void EnvironmentVariablesShouldBeUnique()
{
static void FindDuplicates(Func<OsSupport, OsSettings?> selectOs)
{
var findDuplicates = Definitions.Tools
.Select(_ => _.OsSupport)
.Select(selectOs)
.Where(_ => _ is not null)
.GroupBy(_ => _);
foreach (var group in findDuplicates)
{
Assert.Single(group);
}
}
FindDuplicates(_ => _.Windows);
FindDuplicates(_ => _.Osx);
FindDuplicates(_ => _.Linux);
}
static void AddToolLink(TextWriter writer, Definition tool)
{
var osSupport = GetOsSupport(tool.OsSupport);
writer.WriteLine($" * **[{tool.Tool}](/docs/diff-tool.md#{tool.Tool.ToString().ToLower()})** {osSupport} (Cost: {tool.Cost})");
}
static string GetOsSupport(OsSupport osSupport)
{
var builder = new StringBuilder();
if (osSupport.Windows != null)
{
builder.Append("Win/");
}
if (osSupport.Osx != null)
{
builder.Append("OSX/");
}
if (osSupport.Linux != null)
{
builder.Append("Linux/");
}
builder.Length--;
return builder.ToString();
}
[Fact]
public void WriteDefaultOrder()
{
var md = Path.Combine(SourceDirectory, "defaultOrder.include.md");
File.Delete(md);
using var writer = File.CreateText(md);
foreach (var tool in Definitions.Tools)
{
AddToolLink(writer, tool);
}
}
[Fact]
public void WriteFoundTools()
{
var md = Path.Combine(SourceDirectory, "diffTools.include.md");
File.Delete(md);
using var writer = File.CreateText(md);
writer.WriteLine(
"""
## Non-MDI tools
Non-MDI tools are preferred since it allows [DiffEngineTray](tray.md) to track and close diffs.
""");
foreach (var tool in Definitions.Tools
.Where(_ => !_.IsMdi)
.OrderBy(_ => _.Tool.ToString()))
{
AddTool(writer, tool);
}
writer.WriteLine(
"""
## MDI tools
""");
foreach (var tool in Definitions.Tools
.Where(_ => _.IsMdi)
.OrderBy(_ => _.Tool.ToString()))
{
AddTool(writer, tool);
}
}
static void AddTool(StreamWriter writer, Definition tool)
{
writer.WriteLine(
$"""
### [{tool.Tool}]({tool.Url})
* Cost: {tool.Cost}
* Is MDI: {tool.IsMdi}
* Supports auto-refresh: {tool.AutoRefresh}
* Supports text files: {tool.SupportsText}
* Use shell execute: {tool.UseShellExecute}
* Environment variable for custom install location: `DiffEngine_{tool.Tool}`
""");
if (tool.BinaryExtensions.Length != 0)
{
writer.WriteLine($" * Supported binaries: {string.Join(", ", tool.BinaryExtensions.OrderBy(_ => _))}");
}
if (tool.Notes != null)
{
writer.WriteLine(
$"""
#### Notes:
{tool.Notes}
""");
}
var (windows, linux, osx) = tool.OsSupport;
if (windows != null)
{
writer.WriteLine(
"""
#### Windows settings:
""");
WriteArguments(writer, windows.LaunchArguments);
WritePaths(windows.ExeName, windows.PathCommandName, writer, OsSettingsResolver.ExpandProgramFiles(windows.SearchDirectories).ToList());
}
if (osx != null)
{
writer.WriteLine(
"""
#### OSX settings:
""");
WriteArguments(writer, osx.LaunchArguments);
WritePaths(osx.ExeName, osx.PathCommandName, writer, osx.SearchDirectories);
}
if (linux != null)
{
writer.WriteLine(
"""
#### Linux settings:
""");
WriteArguments(writer, linux.LaunchArguments);
WritePaths(linux.ExeName, linux.PathCommandName, writer, linux.SearchDirectories);
}
}
static void WriteArguments(StreamWriter writer, LaunchArguments arguments)
{
var leftText = arguments.Left("tempFile.txt", "targetFile.txt");
var rightText = arguments.Right("tempFile.txt", "targetFile.txt");
var leftBinary = arguments.Left("tempFile.png", "targetFile.png");
var rightBinary = arguments.Right("tempFile.png", "targetFile.png");
if (leftText.Replace(".txt", "") == leftBinary.Replace(".png", ""))
{
writer.WriteLine(
$"""
* Example target on left arguments: `{leftText} `
* Example target on right arguments: `{rightText} `
""");
}
else
{
writer.WriteLine(
$"""
* Example target on left arguments for text: `{leftText} `
* Example target on right arguments for text: `{rightText} `
* Example target on left arguments for binary: `{leftBinary} `
* Example target on right arguments for binary: `{rightBinary} `
""");
}
}
static void WritePaths(string exeName, string pathCommandName, TextWriter writer, IReadOnlyCollection<string> paths)
{
writer.WriteLine(" * Scanned paths:");
foreach (var path in paths)
{
writer.WriteLine($" * `{path}{exeName}`");
}
writer.WriteLine($" * `%PATH%{pathCommandName}`");
}
}