-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folder to folder transformation logic fix.
- Loading branch information
Showing
3 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
csharp/Platform.RegularExpressions.Transformer.Tests/FileTransformerTests.cs
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,51 @@ | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace Platform.RegularExpressions.Transformer.Tests | ||
{ | ||
public class FileTransformerTests | ||
{ | ||
[Fact] | ||
public void FolderToFolderTransfomationTest() | ||
{ | ||
var tempPath = Path.GetTempPath(); | ||
var sourceFolderPath = Path.Combine(tempPath, "FileTransformerTestsFolderToFolderTransfomationTestSourceFolder"); | ||
var targetFolderPath = Path.Combine(tempPath, "FileTransformerTestsFolderToFolderTransfomationTestTargetFolder"); | ||
|
||
var baseTransformer = new TextTransformer(new SubstitutionRule[] | ||
{ | ||
("a", "b"), | ||
("b", "c") | ||
}); | ||
var fileTransformer = new FileTransformer(baseTransformer, ".cs", ".cpp"); | ||
|
||
// Delete before creation (if previous test failed) | ||
Directory.Delete(sourceFolderPath, true); | ||
Directory.Delete(targetFolderPath, true); | ||
|
||
Directory.CreateDirectory(sourceFolderPath); | ||
Directory.CreateDirectory(targetFolderPath); | ||
|
||
File.WriteAllText(Path.Combine(sourceFolderPath, "a.cs"), "a a a"); | ||
var aFolderPath = Path.Combine(sourceFolderPath, "A"); | ||
Directory.CreateDirectory(aFolderPath); | ||
File.WriteAllText(Path.Combine(aFolderPath, "b.cs"), "b b b"); | ||
File.WriteAllText(Path.Combine(sourceFolderPath, "x.txt"), "should not be translated"); | ||
|
||
fileTransformer.Transform(sourceFolderPath, $"{targetFolderPath}{Path.DirectorySeparatorChar}"); | ||
|
||
var aCppFile = Path.Combine(targetFolderPath, "a.cpp"); | ||
Assert.True(File.Exists(aCppFile)); | ||
Assert.Equal("c c c", File.ReadAllText(aCppFile)); | ||
Assert.True(Directory.Exists(Path.Combine(targetFolderPath, "A"))); | ||
var bCppFile = Path.Combine(targetFolderPath, "A", "b.cpp"); | ||
Assert.True(File.Exists(bCppFile)); | ||
Assert.Equal("c c c", File.ReadAllText(bCppFile)); | ||
Assert.False(File.Exists(Path.Combine(targetFolderPath, "x.txt"))); | ||
Assert.False(File.Exists(Path.Combine(targetFolderPath, "x.cpp"))); | ||
|
||
Directory.Delete(sourceFolderPath, true); | ||
Directory.Delete(targetFolderPath, 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
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