Ejemplo n.º 1
0
 public void CheckPunctuation()
 {
     Assert.IsTrue(WordAndPunctuationHelper.IsSentenceEnding(null));
     Assert.IsTrue(string.Empty.IsSentenceEnding());
     Assert.IsTrue(".".IsSentenceEnding());
     Assert.IsFalse(" ".IsSentenceEnding());
 }
Ejemplo n.º 2
0
        public void BreakIntoWordsAndPunctuation()
        {
            var history = GetLocalHistoryText();

            var index = 0;

            while (index < history.Length)
            {
                var punctuationLength = WordAndPunctuationHelper.PunctuationLength(history, index);
                var punctuation       = history.Substring(index, punctuationLength);
                index += punctuationLength;

                var wordLength = WordAndPunctuationHelper.WordLength(history, index);
                var word       = history.Substring(index, wordLength);
                index += wordLength;

                Debug.WriteLineIf(ShowWorkings, $"{punctuation} - {word}");
            }
        }
Ejemplo n.º 3
0
        static void CheckWordsAndPunctuation(string text, params string[] parts)
        {
            Assert.IsTrue(parts.Length % 2 == 0, "Must have pairings of word and punctuation");

            var textIndex  = 0;
            var partsIndex = 0;

            while (textIndex < text.Length)
            {
                var wordLength = WordAndPunctuationHelper.WordLength(text, textIndex);
                var unexpectedPunctuationLength = WordAndPunctuationHelper.PunctuationLength(text, textIndex);
                Assert.IsTrue((wordLength == 0) || (unexpectedPunctuationLength == 0), "Must be a word or punctuation, but not both");

                var word = text.Substring(textIndex, wordLength);
                textIndex += wordLength;

                var reverseWordLength = WordAndPunctuationHelper.ReverseWordLength(text, textIndex);
                Assert.AreEqual(reverseWordLength, wordLength, "Forwards and backwards word length results should match");

                var unexpectedWordLength = WordAndPunctuationHelper.WordLength(text, textIndex);
                var punctuationLength    = WordAndPunctuationHelper.PunctuationLength(text, textIndex);
                Assert.IsTrue(unexpectedWordLength == 0, "Cannot see a word after a preceeding word without punctuation");

                var punctuation = text.Substring(textIndex, punctuationLength);
                textIndex += punctuationLength;

                var reversePunctuationLength = WordAndPunctuationHelper.ReversePunctuationLength(text, textIndex);
                Assert.AreEqual(punctuationLength, reversePunctuationLength, "Forwards and backwards puctuation results should match");

                Assert.AreEqual(parts[partsIndex + 0], word, "Expected word");
                Assert.AreEqual(parts[partsIndex + 1], punctuation, "Expected punctuation");
                partsIndex += 2;
            }

            Assert.AreEqual(parts.Length, partsIndex, "Should consume all expected parts");
        }