Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    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);
    }