public void TestSimple() { Assert.AreEqual(true, StringHelpers.Compare("aabbcc", "bb", 2)); Assert.AreEqual(false, StringHelpers.Compare("aabbcc", "bb", 3)); }
public void Print(string text, PrintOptions options = PrintOptions.None) { if (text == null) { throw new ArgumentNullException("text"); } if (!Enum.IsDefined(typeof(PrintOptions), options)) { throw new ArgumentException("options"); } int letters = 0; for (int i = 0; i < text.Length; i++) { bool isPrinted = false; if (options == PrintOptions.WholeWordsOnly && i != 0 && !char.IsPunctuation(text[i - 1]) && !char.IsWhiteSpace(text[i - 1])) { letters++; continue; } foreach (ColoredWord cw in _coloredWords) { if (i + cw.Word.Length > text.Length || !StringHelpers.Compare(text, cw.Word, i)) { continue; } if (options == PrintOptions.WholeWordsOnly && i + cw.Word.Length != text.Length && !char.IsPunctuation(text[i + cw.Word.Length]) && !char.IsWhiteSpace(text[i + cw.Word.Length])) { continue; } if (letters != 0) { string f = text.Substring(i - letters, letters); _output.Print(f); } _output.Print(cw.Word, cw.Color); letters = 0; isPrinted = true; i += cw.Word.Length - 1; break; } if (!isPrinted) { letters++; } } if (letters != 0) { _output.Print(text.Substring(text.Length - letters)); } }
public void TestNullText() { Assert.Throws <ArgumentNullException>( () => StringHelpers.Compare(null, "bb", 2)); }
public void TestNullValue() { Assert.Throws <ArgumentNullException>( () => StringHelpers.Compare("aabbcc", null, 2)); }
public void TestInvalidStartIndex() { Assert.Throws <ArgumentOutOfRangeException>( () => StringHelpers.Compare("aabbcc", "bbc", 4)); }
public void TestEmptyText() { Assert.AreEqual(false, StringHelpers.Compare("", "bb", 0)); Assert.AreEqual(true, StringHelpers.Compare("", "", 0)); }
public void TestEmptyValue() { Assert.AreEqual(true, StringHelpers.Compare("aabbcc", "", 2)); }