Skip to content

Commit

Permalink
Add overload to ContainerSpan.Add() to accept a string which becomes …
Browse files Browse the repository at this point in the history
…a ContentSpan (dotnet#908)
  • Loading branch information
SteveL-MSFT authored May 20, 2020
1 parent d252893 commit 425cf56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ public void Container_span_supports_add_method()

span.ContentLength.Should().Be("content with child".Length);
}

[Fact]
public void Container_span_supports_add_string_method()
{
var span = new ContainerSpan(new ContentSpan("content"));
span.Add(" with string");

span.ContentLength.Should().Be("content with string".Length);
}
}
}
12 changes: 12 additions & 0 deletions src/System.CommandLine.Rendering/ContainerSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,17 @@ public void Add(TextSpan child)

RecalculateChildPositions();
}

public void Add(string text)
{
if (string.IsNullOrEmpty(text))
{
return;
}

_children.Add(new ContentSpan(text));

RecalculateChildPositions();
}
}
}

0 comments on commit 425cf56

Please sign in to comment.