public void Base64StringTest() { string enc = S3.ToBytes().Base64Encode(); string dec = StringTool.ToString(enc.Base64Decode()); Assert.AreEqual(S3, dec); }
public void WordCountTest() { Assert.AreEqual(2, StringTool.WordCount(S3, "이")); Assert.AreEqual(4, StringTool.WordCount(S1, "F")); Assert.AreEqual(4, StringTool.WordCount(S1, "f")); Assert.AreEqual(0, StringTool.WordCount(S1, "f", false)); }
public void ToStream_ToString_With_Encoding() { using (var ms = S3.ToStream(Encoding.UTF8)) { string str2 = StringTool.ToString(ms, Encoding.UTF8); Assert.AreEqual(S3, str2); } }
public void ConvertToStringToByteToStream() { var hexBytes = Encoding.UTF8.GetBytes(OriginalString); var hexBytes2 = OriginalString.ToBytes(Encoding.UTF8); Assert.AreEqual(hexBytes, hexBytes2); var hexBytes3 = StringTool.ToStream(OriginalString, Encoding.UTF8).ToBytes(); Assert.AreEqual(hexBytes2, hexBytes3); }
public void Can_Get_LongestCommonSequence() { const string str1 = S1 + S2 + S3 + S3; const string str2 = S2 + S1 + S1 + S3; string sequence; var index = StringTool.GetLongestCommonSequence(str1, str2, out sequence); Assert.IsTrue(index > 0); Assert.IsNotEmpty(sequence); Assert.AreEqual(S1 + S3, sequence); Console.WriteLine("Longest common sequence=" + sequence); }
public void Can_Get_LongestCommonSubstring() { const string str1 = S1 + S2 + S3 + S3; const string str2 = S2 + S1 + S1 + S3; string substring; var index = StringTool.GetLongestCommonSubstring(str1, str2, out substring); Assert.IsTrue(index > 0); Assert.IsNotEmpty(substring); Assert.AreEqual(S3, substring); Console.WriteLine("Longest common substring=" + substring); }
public void SplitTest() { string original = "ABC,def,EF;FF||ABCDEF|ADFDSAF||DAFSADFASDF"; var splitedStr = StringTool.Split(original, ' ', ','); Assert.AreEqual(3, splitedStr.Length); Assert.AreEqual("ABC", splitedStr[0]); var splitedStr2 = original.Split("def", false); Assert.AreEqual(2, splitedStr2.Length); Assert.AreEqual("ABC,", splitedStr2[0]); }
public void CanHexDumpString() { var dumpString = HexTextTool.GetHexDumpString(HexBytes); Assert.IsNotEmpty(dumpString); var dumpString2 = HexTextTool.GetHexDumpString(StringTool.ToStream(OriginalString, Encoding.UTF8)); Assert.IsNotEmpty(dumpString2); //Console.WriteLine(dumpString); //Console.WriteLine(); //Console.WriteLine(dumpString2); Assert.AreEqual(dumpString, dumpString2); }
public void ReplaceTest() { int count = 100; var sb = new StringBuilder(S3.Length * count); for (int i = 0; i < count; i++) { sb.AppendLine(S3); } string largeStr = sb.ToString(); Assert.AreEqual(count * 2, StringTool.WordCount(largeStr, "동해물")); string replaced = largeStr.Replace("동해물", "서해물", true); Assert.AreEqual(0, StringTool.WordCount(replaced, "동해물")); Assert.AreEqual(count * 2, StringTool.WordCount(replaced, "서해물")); }
public void CharAsUnicode() { string result = StringTool.AsUnicode('a'); Assert.AreEqual(@"\u0061", result); result = StringTool.AsUnicode('<'); Assert.AreEqual(@"\u003c", result); result = StringTool.AsUnicode('>'); Assert.AreEqual(@"\u003e", result); result = StringTool.AsUnicode('\''); Assert.AreEqual(@"\u0027", result); result = StringTool.AsUnicode('\u0000'); Assert.AreEqual(@"\u0000", result); result = StringTool.AsUnicode('\t'); Assert.AreEqual(@"\u0009", result); }
public void ToStream_ToString() { Assert.AreEqual(S3, StringTool.ToString(S3.ToStream())); Assert.AreEqual(S3, StringTool.ToString(S3.ToStream(Encoding.UTF8), Encoding.UTF8)); }
public void JoinTest() { Assert.AreEqual("abc;def;ghi", StringTool.Join(";", "abc", "def", "ghi")); }
public void QuotedStrTest() { Assert.AreEqual("NULL", StringTool.QuotedStr(null)); Assert.AreEqual("''", string.Empty.QuotedStr()); Assert.AreEqual("'AAA''AAA'", "AAA'AAA".QuotedStr()); }