Esempio n. 1
0
        public void SetValue_ShouldSetSelectedTextBySpanToGivenValue_WhenSpanStartAndStopAreInSameLinesAndThereIsNoConflictBetweenSpans()
        {
            // Given
            var text = multiLineText("Hello World!",
                                     "How is it going?",
                                     "We are working on a very exciting project.",
                                     "Come and join us!");

            var underTest = new DefaultTextManager(text);
            var start     = new TextPosition(0, 0);
            var stop      = new TextPosition(0, 5);
            var textSpan  = underTest.CreateOrGetTextSpan(start, stop);

            // When
            underTest.SetValue("Hi", textSpan);
            var result = new
            {
                Span = underTest.GetValue(textSpan),
                Text = underTest.GetText()
            };

            // Then
            Assert.That(result, Is.EqualTo(new
            {
                Span = "Hi",
                Text = multiLineText("Hi World!",
                                     "How is it going?",
                                     "We are working on a very exciting project.",
                                     "Come and join us!")
            }));
        }
Esempio n. 2
0
        public void SetValue_ShouldSetSelectedTextBySpanToGivenValueAndUpdateTextRangesInTheSameLine_WhenSpanStartAndStopAreInDifferentLinesAndColumnsAndThereAreMultipleSpansWithoutConflict()
        {
            // Given
            var text = multiLineText("Hello World!",
                                     "How is it going?",
                                     "We are working on a very exciting project.",
                                     "Come and join us!");

            var underTest = new DefaultTextManager(text);

            var firstSpan  = underTest.CreateOrGetTextSpan(new TextPosition(0, 0), new TextPosition(1, 3));
            var secondSpan = underTest.CreateOrGetTextSpan(new TextPosition(1, 4), new TextPosition(1, 6));

            // When
            underTest.SetValue("Where", firstSpan);
            var result = new {
                Spans = new[] { underTest.GetValue(firstSpan), underTest.GetValue(secondSpan) },
                Text  = underTest.GetText()
            };

            // Then
            Assert.That(result.Spans, Is.EquivalentTo(new[] { "Where", "is" }));

            var expectedText = multiLineText("Where is it going?",
                                             "We are working on a very exciting project.",
                                             "Come and join us!");

            Assert.That(result.Text, Is.EqualTo(expectedText));
        }
Esempio n. 3
0
        public void SetValue_ShouldHandleHugeAmountTextSpans(Int32 lines)
        {
            // Given
            var textBuilder = new StringBuilder();

            for (var i = 0; i < lines; i++)
            {
                textBuilder.AppendLine("one,two,three,four");
            }

            var underTest = new DefaultTextManager(textBuilder.ToString());
            var spans     = new List <TextSpan>();

            for (var i = 0; i < lines; i++)
            {
                spans.Add(underTest.CreateOrGetTextSpan(new TextPosition(i, 0), new TextPosition(i, 3)));
                underTest.CreateOrGetTextSpan(new TextPosition(i, 4), new TextPosition(i, 7));
            }

            // When
            var watch = Stopwatch.StartNew();

            foreach (var span in spans)
            {
                underTest.SetValue("onetwo", span);
            }
            watch.Stop();

            // Then
            Console.WriteLine(watch.Elapsed);
        }
Esempio n. 4
0
        public void SetValue_ShouldSetSelectedTextBySpanToGivenValue_WhenSpanStartAndStopAreInSameLinesAndColumnsAndThereAreMultipleSpansWithoutConflict()
        {
            // Given
            var text = multiLineText("Hello World!",
                                     "How is it going?",
                                     "We are working on a very exciting project.",
                                     "Come and join us!");

            var underTest = new DefaultTextManager(text);

            var helloSpan = underTest.CreateOrGetTextSpan(new TextPosition(0, 0), new TextPosition(0, 5));
            var worldSpan = underTest.CreateOrGetTextSpan(new TextPosition(0, 6), new TextPosition(0, 11));

            // When
            underTest.SetValue("WORLD", worldSpan);
            var result = new
            {
                Spans = new[] { underTest.GetValue(helloSpan), underTest.GetValue(worldSpan) },
                Text  = underTest.GetText()
            };

            // Then
            Assert.That(result.Spans, Is.EquivalentTo(new[] { "Hello", "WORLD" }));

            var expectedText = multiLineText("Hello WORLD!",
                                             "How is it going?",
                                             "We are working on a very exciting project.",
                                             "Come and join us!");

            Assert.That(result.Text, Is.EqualTo(expectedText));
        }