public void SucceedGivenExistingDirectoryPath()
        {
            var pathTree = new PathTree();

            Assert.True(pathTree.TryAdd(TestDataPath, out string errorMessage));
            AllExistingPaths.ForEach(path => Assert.True(pathTree.FindNode(path).IsTarget));
        }
        public void MergePassedPaths()
        {
            string currentDirectoryBackup = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(TestDataPath);
            try
            {
                var pathTree = new PathTree();
                Assert.True(pathTree.TryAdd("Hoge/Hoge.txt", out string errorMessage1));
                Assert.True(pathTree.TryAdd(Path.Combine(TestDataPath, "Hoge"), out string errorMessage2));
                Assert.Equal(pathTree.FindNode("Hoge/Hoge.txt"), pathTree.FindNode(Path.Combine(TestDataPath, "Hoge/Hoge.txt")));
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDirectoryBackup);
            }
        }
        public void SucceedGivenExistingFilePath()
        {
            var pathTree = new PathTree();

            Assert.True(pathTree.TryAdd(Ja_UTF8_CRLF_TxtPath, out string errorMessage));
            Assert.False(pathTree.FindNode(TestDataPath).IsTarget);
            Assert.True(pathTree.FindNode(Ja_UTF8_CRLF_TxtPath).IsTarget);
        }
예제 #4
0
 public void KeepLastEmptyLineOnContentEdit()
 {
     RefreshWorkData();
     foreach (var path in new[] { Ja_UTF8_CRLF_TxtPath, Ja_UTF8_CRLF_EndsWithEmptyLine_TxtPath })
     {
         var fileInfo     = new TextFileInfo(path);
         int srcLineCount = fileInfo.ReadAllLines().Count;
         var pathTree     = new PathTree();
         pathTree.TryAdd(path, out string errorMessage);
         var commands = new List <Command>();
         if (Command.TryParse("s/ほげ/ホゲ/g", out var command))
         {
             commands.Add(command);
         }
         var runner = new CommandRunner(commands);
         runner.Run(pathTree, CommandRunnerActionKind.Replace);
         int lineCount = fileInfo.ReadAllLines().Count;
         Assert.Equal(srcLineCount, lineCount);
     }
 }
예제 #5
0
 public void KeepCharactorEncodingOnContentEdit()
 {
     RefreshWorkData();
     foreach (var path in new[] { Ja_UTF8_CRLF_TxtPath, Ja_UTF8WithBom_CRLF_TxtPath, Ja_SJIS_CRLF_TxtPath, Ja_EUCJP_LF_TxtPath })
     {
         var srcInfo  = new TextFileInfo(path);
         var pathTree = new PathTree();
         pathTree.TryAdd(path, out string errorMessage);
         var commands = new List <Command>();
         if (Command.TryParse("s/ほげ/ホゲ/g", out var command))
         {
             commands.Add(command);
         }
         var runner = new CommandRunner(commands);
         runner.Run(pathTree, CommandRunnerActionKind.Replace);
         var editedInfo = new TextFileInfo(path);
         Assert.Equal(srcInfo.Encoding, editedInfo.Encoding);
         Assert.Equal(srcInfo.NewLine, editedInfo.NewLine);
     }
 }
예제 #6
0
        public void ReplaceDirectoryNameAndDescendant()
        {
            RefreshWorkData();
            string path     = Path.Combine(WorkDataPath, "Hoge");
            var    pathTree = new PathTree();

            pathTree.TryAdd(path, out string errorMessage);
            var commands = new List <Command>();

            if (Command.TryParse("s/Hoge/Piyo/g", out var command))
            {
                commands.Add(command);
            }
            var runner = new CommandRunner(commands);

            runner.Run(pathTree, CommandRunnerActionKind.Replace);
            Assert.False(Directory.Exists(Path.Combine(WorkDataPath, "Hoge")));
            Assert.True(Directory.Exists(Path.Combine(WorkDataPath, "Piyo")));
            Assert.False(File.Exists(Path.Combine(WorkDataPath, "Piyo/Hoge.txt")));
            Assert.Equal("Piyo", File.ReadAllText(Path.Combine(WorkDataPath, "Piyo/Piyo.txt")));
        }
예제 #7
0
        public void WorkWithSedRegex()
        {
            RefreshWorkData();
            string path     = Ja_UTF8_CRLF_TxtPath;
            var    pathTree = new PathTree();

            pathTree.TryAdd(path, out string errorMessage);
            var commands = new List <Command>();

            if (Command.TryParse(@"s/ほ\(げ\)/ホ\1/g", out var command))
            {
                commands.Add(command);
            }
            var runner = new CommandRunner(commands);

            runner.Run(pathTree, CommandRunnerActionKind.Replace);
            var fileInfo = new TextFileInfo(path);
            var lines    = fileInfo.ReadAllLines();

            Assert.Contains(lines, l => l.Contains("ホげ"));
        }
        public void FailGivenNotExistingPath()
        {
            var pathTree = new PathTree();

            Assert.False(pathTree.TryAdd(NotExistingPath, out string errorMessage));
        }