Beispiel #1
0
        public void Should_be_able_to_combine_text()
        {
            ParseText input = new StringText("abcdefg");

            var first  = input.GetSubText(new TextSpan(0, 3));
            var second = input.GetSubText(new TextSpan(4, 3));

            var composite = new CompositeText(new[] { first, second });

            var text = composite.ToString();

            Assert.That(text, Is.EqualTo("abcefg"));
        }
Beispiel #2
0
        public void Should_be_able_to_combine_slices()
        {
            ParseText input = new StringText("abcdefg");

            var first  = input.GetSubText(new TextSpan(0, 3));
            var second = input.GetSubText(new TextSpan(4, 3));

            TextSlice firstSlice  = new ParseTextSlice(first, new TextSpan(0, first.Length));
            TextSlice secondSlice = new ParseTextSlice(second, new TextSpan(0, second.Length));

            var composite = new CompositeTextSlice(firstSlice, secondSlice);

            var text = composite.Text.ToString();

            Assert.That(text, Is.EqualTo("abcefg"));
        }
Beispiel #3
0
        public void Should_parse_text_from_the_string()
        {
            var input = new StringText("Hello, World.");

            var parser = new SymbolParser(char.IsLetter, char.IsLetterOrDigit);

            var result = parser.Parse(input, new TextSpan(0, input.Length));

            Assert.IsTrue(result.HasValue);

            var text = input.GetSubText(result.Value);

            Assert.AreEqual("Hello", text.ToString());
        }