Exemple #1
0
        /// <summary>
        /// replaces characters that git allows (i.e. double quotes) with Windows equivalents where possible.
        /// </summary>
        /// <param name="path">the path to check</param>
        /// <returns>a valid Windows-safe version of the file path</returns>
        public string FixInvalidFileNameCharsInPath(string path)
        {
            var findChars    = new string[] { "\"" }; // just double quotes for now but I suspect the list will grow over time
            var replaceChars = new string[] { "" };

            return(DWPSUtils.ReplaceTokens(path, findChars, replaceChars, false));
        }
Exemple #2
0
 public void ReplaceTokens_Invalid(string[] tokens, string[] replacements)
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var result = DWPSUtils.ReplaceTokens("this is a test", tokens, replacements);
     });
 }
Exemple #3
0
        public void ReplaceTokens_SingleCharacterKeepDuplicates()
        {
            var sourceText  = "||1|2|||3|";
            var tokens      = new string[] { "|" };
            var replaceWith = new string[] { "_" };
            var expected    = "__1_2___3_";

            var result = DWPSUtils.ReplaceTokens(sourceText, tokens, replaceWith, false);

            Assert.AreEqual(result, expected);
        }
Exemple #4
0
        public void ReplaceTokens_SingleCharacter()
        {
            var sourceText  = "PURpleThe pUrple fox swam through purplePURPLE water to paint the deck puRple";
            var tokens      = new string[] { "purple" };
            var replaceWith = new string[] { "red" };
            var expected    = "redThe red fox swam through red water to paint the deck red";

            var result = DWPSUtils.ReplaceTokens(sourceText, tokens, replaceWith, true);

            Assert.AreEqual(result, expected);
        }
Exemple #5
0
        public void ReplaceTokens_RemovingCharacters()
        {
            var sourceText  = "The red fox swam through red water to paint the deck red";
            var tokens      = new string[] { " ", "i", "o" };
            var replaceWith = new string[] { "_", "", "" };
            var expected    = "The_red_fx_swam_thrugh_red_water_t_pant_the_deck_red";

            var result = DWPSUtils.ReplaceTokens(sourceText, tokens, replaceWith, true);

            Assert.AreEqual(result, expected);
        }
Exemple #6
0
        public void ReplaceTokens_ReplaceContainsToken()
        {
            var sourceText  = "The red fox swam through red water to paint the deck red";
            var tokens      = new string[] { " ", "i", "o" };
            var replaceWith = new string[] { "\\ /", "dig", "OO" };
            var expected    = "The\\ /red\\ /fOOx\\ /swam\\ /thrOOugh\\ /red\\ /water\\ /tOO\\ /padignt\\ /the\\ /deck\\ /red";

            var result = DWPSUtils.ReplaceTokens(sourceText, tokens, replaceWith, true);

            Assert.AreEqual(result, expected);
        }
Exemple #7
0
        public void ReplaceTokens_Basic()
        {
            var source    = " This    is      a Test! ";
            var tokens    = new string[] { " " };
            var reptokens = new string[] { "_" };

            var result = DWPSUtils.ReplaceTokens(source, tokens, reptokens);

            Assert.IsTrue(result == source.Replace(" ", "_"));

            result = DWPSUtils.ReplaceTokens(source, tokens, reptokens, true);
            Assert.AreEqual("_This_is_a_Test!_", result);
        }
Exemple #8
0
        public void ReplaceTokens_Empty(string text)
        {
            var result = DWPSUtils.ReplaceTokens(text, null, null);

            Assert.IsTrue(result == string.Empty);
        }