Skip to content

Commit

Permalink
Add Add() method to ContainerSpan class (dotnet#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveL-MSFT authored May 16, 2020
1 parent 750fdd1 commit d252893
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using FluentAssertions;
using Xunit;

namespace System.CommandLine.Rendering.Tests
{
public class ContainerSpanTests
{
[Fact]
public void Container_span_supports_add_method()
{
var span = new ContainerSpan(new ContentSpan("content"));
span.Add(new ContentSpan(" with child"));

span.ContentLength.Should().Be("content with child".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 @@ -60,5 +60,17 @@ public override void WriteTo(TextWriter writer, OutputMode outputMode)
_children[i].WriteTo(writer, outputMode);
}
}

public void Add(TextSpan child)
{
if (child == null)
{
throw new ArgumentNullException(nameof(child));
}

_children.Add(child);

RecalculateChildPositions();
}
}
}

0 comments on commit d252893

Please sign in to comment.