public void Create_Constructor_ExpectSameString() { string expect = "Randy Butternubs"; Scrub st = new Scrub(expect); Assert.IsNotNull(st.CharTransDict); Assert.IsNotNull(st.RegxTuples); Assert.IsNotNull(st.StringTransDict); Assert.AreEqual(expect, st.ToString()); Assert.IsNotNull(st.RegxMatchesDefined); }
public void Translate_EmptyEverything_ExpectSameString() { string expect = "Randy Butternubs"; Scrub st = new Scrub(expect); st.Strip("").MapChars().MapWords().RegxTranslate().Strip(""); Assert.IsNotNull(st.CharTransDict); Assert.IsNotNull(st.RegxTuples); Assert.IsNotNull(st.StringTransDict); Assert.AreEqual(expect, st.ToString()); }
public void MatchCase_RegxDefined_Matches() { string sentence = "wtf does RemoveWTF do? Is WtF Case SeNsItIvE?"; string expectedSentance = "XXX does RemoveWTF do? Is WtF Case SeNsItIvE?"; Scrub st = new Scrub(sentence); st.Set(sentence); st.RegxMatchesDefined.Add("RemoveWTF", @"(wtf)|(what the)\s+(hell|$hit)"); st.RegxDefined("RemoveWTF", "XXX"); Assert.AreEqual(expectedSentance, st.ToString()); }
public void SetString_AddStringAfter_ExpectNewString() { string expect = "Randy Butternubs"; Scrub st = new Scrub("Haystack Calhoon"); st.Set(expect); st.Strip("").MapChars().MapWords().RegxTranslate().Strip(""); Assert.IsNotNull(st.CharTransDict); Assert.IsNotNull(st.RegxTuples); Assert.IsNotNull(st.StringTransDict); Assert.AreEqual(expect, st.ToString()); }
public void Predefined_CompactWhitespace_Compacted() { string sentence = "¿¡Señor, the Chevrolet guys don't like Dodge guys, and and no one like MaZdA, Ola Senor?! "; string expectedSentance = "¿¡Señor, the Chevrolet guys don't like Dodge guys, and and no one like MaZdA, Ola Senor?! "; Scrub st = new Scrub(sentence); // Compact whitespaces to one space, note does not imply trim! // overides default empty string replace to replace with single space // note trailing space at end of string st.RegxDefined("WhitespaceCompact", " "); Assert.AreEqual(expectedSentance, st.ToString()); }
public void TestAll() { // get most of the mapped accent chars, and their non-accented equiv // must be 1 to 1 mapping and size of arrays. Easier to do lots of chars this // way then with lists string matchChar = "ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ¡¿"; string replaceChar = "SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy "; // set up a dictionary, if ignore case, set the dict up with a new comparer StringComparer comparer = StringComparer.OrdinalIgnoreCase; // default is just Ordinal Dictionary <string, string> wordDictionary = new Dictionary <string, string>(comparer) { { "chevrolet", "Ford" }, { "mAzDa", "BMW" }, { "and and", "and" }, // will never match }; // Need `System.ValueTuple` package to do this style of init // on v4.6 and below List <(string, string)> regxList = new List <(string, string)> { // Match, Replace ("BMW", "Fiat"), (@"\s+", " "), // multi whitespace to 1 space (@"^\s*|\s*$", "") // trims leading/ending spaces }; string sentence = "¿¡Señor, the Chevrolet guys don't like Dodge guys, and and no one like MaZdA, Ola Senor?! "; string expectedSentance = "Magoo the Ford guys don#t like Mercedes guys and and no one like Fiat Ola Magoo?!"; Scrub st = new Scrub(sentence); // Set dictionary up, case insensitive match st.SetStringTranslator(wordDictionary, true); // set up character translators st.SetCharTranslator(matchChar, replaceChar); // set up list of regx replaces st.SetRegxTranslator(regxList); // add a string translation after the fact st.StringTransDict.Add("dodge", "Mercedes"); // add a Regx translation after the fact st.RegxTuples.Add(("Senor", "Mr.Magoo")); // add a chracter Translation after the fact st.CharTransDict.Add('\'', '#'); // so all sorts of stuff! st.Strip("[,]").MapChars().MapWords().RegxTranslate().Strip(@"Mr\."); Assert.AreEqual(expectedSentance, st.ToString()); }