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); }
public void GetOrigninalText_SpanIsOwner_ReturnsContent_ZeroLengthSpan() { // Arrange var builder = new SpanBuilder(new SourceLocation(13, 0, 0)); builder.Accept(new RawTextSymbol(new SourceLocation(13, 0, 13), "Hello, ")); builder.Accept(new RawTextSymbol(new SourceLocation(20, 0, 20), "World")); var span = new Span(builder); var change = new SourceChange(15, 0, "heyo"); // Act var result = change.GetOriginalText(span); // Act Assert.Equal(string.Empty, result); }
public void GetOffSet_SpanIsOwner_ReturnsOffset() { // Arrange var builder = new SpanBuilder(new SourceLocation(13, 0, 0)); builder.Accept(new RawTextSymbol(new SourceLocation(13, 0, 13), "Hello, ")); builder.Accept(new RawTextSymbol(new SourceLocation(20, 0, 20), "World")); var span = new Span(builder); var change = new SourceChange(15, 2, "heyo"); // Act var result = change.GetOffset(span); // Act Assert.Equal(2, result); }
public void GetOrigninalText_SpanIsOwner_ReturnsContent_ZeroLengthSpan() { // 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(null, 13); var change = new SourceChange(15, 0, "heyo"); // Act var result = change.GetOriginalText(node); // Act Assert.Equal(string.Empty, result); }
protected override PartialParseResultInternal CanAcceptChange(Span 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 GetOffSet_SpanIsOwner_ReturnsOffset() { // 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(null, 13); var change = new SourceChange(15, 2, "heyo"); // Act var result = change.GetOffset(node); // Act Assert.Equal(2, result); }
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); }
public void GetOrigninalText_SpanIsOwner_ReturnsContent_ZeroLengthSpan() { // Arrange var builder = new SpanBuilder(new SourceLocation(13, 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(15, 0, "heyo"); // Act var result = change.GetOriginalText(span); // Act Assert.Equal(string.Empty, result); }
public void GetOffSet_SpanIsOwner_ReturnsOffset() { // Arrange var builder = new SpanBuilder(new SourceLocation(13, 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(15, 2, "heyo"); // Act var result = change.GetOffset(span); // Act Assert.Equal(2, result); }
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); }
public void GetOffSet_SpanIsNotOwnerOfChange_ThrowsException(int absoluteIndex, int length) { // Arrange var builder = new SpanBuilder(new SourceLocation(13, 0, 0)); builder.Accept(new RawTextSymbol(new SourceLocation(13, 0, 13), "Hello, ")); builder.Accept(new RawTextSymbol(new SourceLocation(20, 0, 20), "World")); var span = new Span(builder); var change = new SourceChange(12, 2, "heyo"); var expected = $"The node '{span}' is not the owner of change '{change}'."; // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => { change.GetOffset(span); }); Assert.Equal(expected, exception.Message); }
public void GetOffSet_SpanIsNotOwnerOfChange_ThrowsException() { // 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(null, 13); var change = new SourceChange(12, 2, "heyo"); var expected = $"The node '{node}' is not the owner of change '{change}'."; // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => { change.GetOffset(node); }); Assert.Equal(expected, exception.Message); }
public void GetOffSet_SpanIsNotOwnerOfChange_ThrowsException() { // Arrange var builder = new SpanBuilder(new SourceLocation(13, 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(12, 2, "heyo"); var expected = $"The node '{span}' is not the owner of change '{change}'."; // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => { change.GetOffset(span); }); Assert.Equal(expected, exception.Message); }