Exemplo n.º 1
0
        public void TryMerge_WithSelf_Fails()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var self = new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor(1).ToHandle(), "One");

            DidYouKnow.That(self.TryMerge(Context, self)).Should().BeFalse();
        }
Exemplo n.º 2
0
        public void TryMerge_DoesNotMergeWhenNotNextToEachother()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var first =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor(1).ToHandle(), "One");
            var second =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor(2).ToHandle(), "Two");

            DidYouKnow.That(first.TryMerge(Context, second)).Should().BeFalse();
        }
Exemplo n.º 3
0
        public void VerifyMergeWith_ModifiesOriginalAction()
        {
            var originalAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "The text");

            originalAction.Do(Context);

            var mergeWithAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "And More");

            DidYouKnow.That(originalAction.TryMerge(Context, mergeWithAction)).Should().BeTrue();
            DidYouKnow.That(originalAction.Text).Should().Be("The textAnd More");
        }
Exemplo n.º 4
0
        public void TryMerge_WorksOnLargerStrings()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var first =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(),
                                                               "This is a long string");

            first.Do(Context);
            var second = new InsertTextCommand.InsertTextUndoableAction(
                BlockAt <TextBlock>(0).BeginCursor(first.Text.Length).ToHandle(),
                "This is also long");

            DidYouKnow.That(first.TryMerge(Context, second)).Should().BeTrue();
        }
Exemplo n.º 5
0
        public void VerifyMergeWith_DoesNotActsOnDocument()
        {
            var originalAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "The text");

            originalAction.Do(Context);

            var mergeWithAction =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt(0).EndCursor().ToHandle(), "And More");

            originalAction.TryMerge(Context, mergeWithAction);

            // the document should not be modified
            DidYouKnow.That(BlockAt <TextBlock>(0).AsText()).Should().Be("The text");
        }
Exemplo n.º 6
0
        public void TryMerge_WithBackspace_DoesNotWorkWhenInsertionIsEmpty()
        {
            var fakeInsertion =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(),
                                                               "1234");

            fakeInsertion.Do(Context);
            Context.UndoStack.Clear();

            var insertion =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(), "");

            insertion.Do(Context);
            var second =
                new DeletePreviousCharacterCommand.DeletePreviousCharacterAction(
                    BlockAt <TextBlock>(0).BeginCaret(4).AsTextCursor());

            DidYouKnow.That(insertion.TryMerge(Context, second)).Should().BeFalse();
        }
Exemplo n.º 7
0
        public void TryMerge_WithBackspaceAction_Works()
        {
            BlockAt <TextBlock>(0).GetCaretAtStart().AsTextCursor().InsertText("This is text");

            var insertion =
                new InsertTextCommand.InsertTextUndoableAction(BlockAt <TextBlock>(0).BeginCursor().ToHandle(),
                                                               "Inserted String");

            insertion.Do(Context);
            var second =
                new DeletePreviousCharacterCommand.DeletePreviousCharacterAction(
                    BlockAt <TextBlock>(0).BeginCaret(insertion.Text.Length).AsTextCursor());

            DidYouKnow.That(insertion.TryMerge(Context, second)).
            Should().BeTrue();

            DidYouKnow.That(insertion.Text).Should()
            .Be("Inserted Strin");
        }