Beispiel #1
0
        public void FirstLast()
        {
            var range = XElement.Parse(xml);

            var cdata = range.DescendantNodes()
                        .Where(e => e.NodeType == XmlNodeType.CDATA)
                        .First() as XCData;

            var phrase = new Phrase(cdata);

            Assert.IsNotNull(phrase);
            Assert.IsFalse(phrase.IsEmpty);
            Assert.IsTrue(phrase.ContainsMultipleWords);
            Assert.IsFalse(phrase.StartsWithSpace);
            Assert.IsFalse(phrase.EndsWithSpace);

            var word = phrase.ExtractFirstWord();

            Assert.IsNotNull(word);
            Assert.AreEqual("One ", word);

            word = phrase.ExtractFirstWord();
            Assert.IsNotNull(word);
            Assert.AreEqual("two ", word);

            word = phrase.ExtractLastWord();
            Assert.IsNotNull(word);
            Assert.AreEqual(" four", word);

            word = phrase.ExtractLastWord();
            Assert.IsNotNull(word);
            Assert.AreEqual("three", word);

            word = phrase.ExtractLastWord();
            Assert.IsNotNull(word);
            Assert.AreEqual(string.Empty, word);
        }