Exemplo n.º 1
0
            public void ShouldHandleHugeAmountTextSpans_WhenBatchModeIsActive(Int32 lines)
            {
                // Given
                var textBuilder = new StringBuilder();
                var line        = "one,two,three,four";

                for (var i = 0; i < lines; i++)
                {
                    textBuilder.AppendLine(line);
                }

                var underTest = new TextDocument(textBuilder.ToString());
                var ranges    = new List <TextRange>();

                for (var i = 0; i < lines; i++)
                {
                    var offset = (line.Length + Environment.NewLine.Length) * i;
                    ranges.Add(underTest.CreateOrGetTextRange(offset + 0, offset + 3));
                    underTest.CreateOrGetTextRange(offset + 4, offset + 7);
                }

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

                underTest.BeginTransaction();
                foreach (var range in ranges)
                {
                    underTest.ChangeText(range, "onetwo");
                }
                underTest.EndTransaction();
                watch.Stop();

                // Then
                Console.WriteLine(watch.Elapsed);
            }
Exemplo n.º 2
0
            public void ShouldUpdateOverlappingTextRanges_AfterItChangedText()
            {
                // Given
                var underTest = new TextDocument("0123456789");

                var words = new[]
                {
                    underTest.CreateOrGetTextRange(0, 4),
                    underTest.CreateOrGetTextRange(2, 10),
                };

                // When
                underTest.ChangeText(words[0], "9");
                var result = underTest.TextRanges
                             .Where(range => range != underTest.TextRange)
                             .Select(textRange => underTest.GetText(textRange)).ToArray();

                // Then
                Assert.That(result, Is.EquivalentTo(new[] { "9", "9456789" }));
            }