public void GetEditedContent_ForReplace_ReturnsNewContent()
        {
            // Arrange
            var text = "Hello, World";

            var change = new SourceChange(2, 2, "heyo");

            // Act
            var result = change.GetEditedContent(text, 1);

            // Act
            Assert.Equal("Hheyolo, World", result);
        }
        public void GetEditedContent_ForDelete_ReturnsNewContent()
        {
            // Arrange
            var text = "Hello, World";

            var change = new SourceChange(2, 2, string.Empty);

            // Act
            var result = change.GetEditedContent(text, 1);

            // Act
            Assert.Equal("Hlo, World", result);
        }
        public void GetEditedContent_Span_ReturnsNewContent()
        {
            // Arrange
            var builder = new SpanBuilder(new SourceLocation(0, 0, 0));

            builder.Accept(new RawTextSymbol(new SourceLocation(0, 0, 0), "Hello, "));
            builder.Accept(new RawTextSymbol(new SourceLocation(7, 0, 7), "World"));

            var span = new Span(builder);

            var change = new SourceChange(2, 2, "heyo");

            // Act
            var result = change.GetEditedContent(span);

            // Act
            Assert.Equal("Heheyoo, World", result);
        }
        protected override PartialParseResultInternal CanAcceptChange(SyntaxNode target, SourceChange change)
        {
            if (AcceptedCharacters == AcceptedCharactersInternal.NonWhitespace)
            {
                var originalText  = change.GetOriginalText(target);
                var editedContent = change.GetEditedContent(target);

                if (!ContainsWhitespace(originalText) && !ContainsWhitespace(editedContent))
                {
                    // Did not modify whitespace, directive format should be the same.
                    // Return provisional so extensible IR/code gen pieces can see the full directive text
                    // once the user stops editing the document.
                    return(PartialParseResultInternal.Accepted | PartialParseResultInternal.Provisional);
                }
            }

            return(PartialParseResultInternal.Rejected);
        }
        public void GetEditedContent_SyntaxNode_ReturnsNewContent()
        {
            // Arrange
            var builder = SyntaxListBuilder <SyntaxToken> .Create();

            builder.Add(SyntaxFactory.Token(SyntaxKind.Marker, "Hello, "));
            builder.Add(SyntaxFactory.Token(SyntaxKind.Marker, "World"));

            var node = SyntaxFactory.MarkupTextLiteral(builder.ToList()).CreateRed();

            var change = new SourceChange(2, 2, "heyo");

            // Act
            var result = change.GetEditedContent(node);

            // Act
            Assert.Equal("Heheyoo, World", result);
        }
Esempio n. 6
0
        public void GetEditedContent_Span_ReturnsNewContent()
        {
            // Arrange
            var builder = new SpanBuilder(new SourceLocation(0, 0, 0));

            builder.Accept(SyntaxFactory.Token(SyntaxKind.Unknown, "Hello, "));
            builder.Accept(SyntaxFactory.Token(SyntaxKind.Unknown, "World"));

            var span = new Span(builder);

            var change = new SourceChange(2, 2, "heyo");

            // Act
            var result = change.GetEditedContent(span);

            // Act
            Assert.Equal("Heheyoo, World", result);
        }