-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fbf4c9
commit aaa786c
Showing
4 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using TrimTail; | ||
|
||
namespace TrimTailTests | ||
{ | ||
[TestClass] | ||
public class TrimTailTests | ||
{ | ||
[TestMethod] | ||
public void TestHasTrailingBlanks() | ||
{ | ||
const string filePath = "test.txt"; | ||
|
||
File.WriteAllText(filePath, "Test w/ trailing spaces "); | ||
Assert.IsTrue(Program.HasTrailingBlanks(filePath)); | ||
File.Delete(filePath); | ||
|
||
File.WriteAllText(filePath, "Test w/ trailing tabs\t\t"); | ||
Assert.IsTrue(Program.HasTrailingBlanks(filePath)); | ||
File.Delete(filePath); | ||
|
||
File.WriteAllText(filePath, "Test w/o trailing blanks"); | ||
Assert.IsFalse(Program.HasTrailingBlanks(filePath)); | ||
File.Delete(filePath); | ||
} | ||
|
||
[TestMethod] | ||
public void TestRemoveTrailingBlanks() | ||
{ | ||
const string filePath = "test.txt"; | ||
string content; | ||
|
||
File.WriteAllText(filePath, "Test w/ trailing blanks "); | ||
Program.RemoveTrailingBlanks(filePath); | ||
content = File.ReadAllText(filePath); | ||
Assert.AreEqual("Test w/ trailing blanks", content); | ||
File.Delete(filePath); | ||
|
||
File.WriteAllText(filePath, "Test w/ trailing blanks and newline \r\n"); | ||
Program.RemoveTrailingBlanks(filePath); | ||
content = File.ReadAllText(filePath); | ||
Assert.AreEqual("Test w/ trailing blanks and newline\r\n", content); | ||
File.Delete(filePath); | ||
} | ||
|
||
[TestMethod] | ||
public void TestProcessDir() | ||
{ | ||
const string dirPath = "testDir"; | ||
Directory.CreateDirectory(dirPath); | ||
File.WriteAllText(Path.Combine(dirPath, "test1.txt"), "This is a test with trailing blanks "); | ||
File.WriteAllText(Path.Combine(dirPath, "test2.txt"), "Another test with trailing blanks "); | ||
Program.ProcessDir(dirPath, [".txt"]); | ||
var files = Directory.EnumerateFiles(dirPath, "*", SearchOption.AllDirectories); | ||
Assert.IsTrue(files.All(filePath => !File.ReadAllText(filePath).EndsWith(' '))); | ||
Directory.Delete(dirPath, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TrimTail\TrimTail.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
</Project> |