Пример #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!")
            }));
        }
Пример #2
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);
        }
Пример #3
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));
        }
Пример #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));
        }
 public static DefaultTextManager SetupDefault()
 {
     var manager = new DefaultTextManager();
     //manager.PrepareAssemblyTextSources();
     TextManagerResolver = () => manager;
     return manager;
 }
Пример #6
0
        public static DefaultTextManager SetupDefault()
        {
            var manager = new DefaultTextManager();

            //manager.PrepareAssemblyTextSources();
            TextManagerResolver = () => manager;
            return(manager);
        }
Пример #7
0
        public void CreateOrGetTextSpan_ShouldCreateANewTextSpan_WhenItHasNotInitializedYet()
        {
            // Given
            var underTest = new DefaultTextManager("Hello World!");
            var start     = new TextPosition(0, 0);
            var stop      = new TextPosition(0, 12);

            // When
            var result = underTest.CreateOrGetTextSpan(start, stop);

            // Then
            Assert.That(result, Is.EqualTo(new TextSpan(start, stop)));
        }
Пример #8
0
        public void GetValue_ShouldReturnSelectedTextBySpan_WhenSpanStartAndStopAreInSameLines()
        {
            // Given
            var underTest = new DefaultTextManager("Hello World!");
            var start     = new TextPosition(0, 0);
            var stop      = new TextPosition(0, 5);
            var textSpan  = underTest.CreateOrGetTextSpan(start, stop);

            // When
            var result = underTest.GetValue(textSpan);

            // Then
            Assert.That(result, Is.EqualTo("Hello"));
        }
Пример #9
0
        public void CreateOrGetTextSpan_ShouldGetAnExistingTextSpan_WhenItHasAlreadyBeenDefined()
        {
            // Given
            var underTest = new DefaultTextManager("Hello World!");
            var start     = new TextPosition(0, 0);
            var stop      = new TextPosition(0, 12);
            var textSpan  = underTest.CreateOrGetTextSpan(start, stop);

            // When
            var result = underTest.CreateOrGetTextSpan(start, stop);

            // Then
            Assert.That(result, Is.SameAs(textSpan));
        }
        public FormattedCode Format(string sourceCode)
        {
            DefaultTextManager text;

            byte[] byteArray;
            int[]  strArray;
            int[]  lineArray;
            int    index;
            int    posLineStart;
            int    posChar;

            UiExceptionHelper.CheckNotNull(sourceCode, "sourceCode");

            sourceCode = PreProcess(sourceCode);

            text      = new DefaultTextManager();
            text.Text = sourceCode;

            strArray  = new int[text.LineCount];
            lineArray = new int[text.LineCount];

            index        = 0;
            posLineStart = 0;
            posChar      = 0;

            foreach (char c in sourceCode)
            {
                if (c == '\n')
                {
                    strArray[index]  = posLineStart;
                    lineArray[index] = index;
                    posLineStart     = posChar + 1;
                    index++;
                }

                posChar++;
            }

            if (index <= text.LineCount - 1)
            {
                strArray[index]  = posLineStart;
                lineArray[index] = index;
            }

            byteArray = new byte[text.LineCount];

            return(new FormattedCode(sourceCode, strArray, byteArray, lineArray));
        }
        public FormattedCode Format(string sourceCode)
        {
            DefaultTextManager text;
            byte[] byteArray;
            int[] strArray;
            int[] lineArray;
            int index;
            int posLineStart;
            int posChar;

            UiExceptionHelper.CheckNotNull(sourceCode, "sourceCode");

            sourceCode = PreProcess(sourceCode);

            text = new DefaultTextManager();
            text.Text = sourceCode;

            strArray = new int[text.LineCount];
            lineArray = new int[text.LineCount];

            index = 0;
            posLineStart = 0;
            posChar = 0;

            foreach (char c in sourceCode)
            {
                if (c == '\n')
                {
                    strArray[index] = posLineStart;
                    lineArray[index] = index;
                    posLineStart = posChar + 1;
                    index++;
                }

                posChar++;
            }

            if (index <= text.LineCount - 1)
            {
                strArray[index] = posLineStart;
                lineArray[index] = index;
            }

            byteArray = new byte[text.LineCount];

            return (new FormattedCode(sourceCode, strArray, byteArray, lineArray));
        }
Пример #12
0
        public void GetValue_ShouldReturnSelectedTextBySpan_WhenSpanStartAndStopAreInDifferentLines()
        {
            // Given
            var text = multiLineText("Hello World!",
                                     "How is it going?",
                                     "We are programming on a very exciting project.",
                                     "Come and join us!");

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

            // When
            var result = underTest.GetValue(textSpan);

            // Then
            Assert.That(result, Is.EqualTo(multiLineText("World!", "How is")));
        }
 public void SetUp()
 {
     _textBlocks = new DefaultTextManager();            
 }       
Пример #14
0
 public void SetUp()
 {
     _textBlocks = new DefaultTextManager();
 }