diff --git a/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs b/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs new file mode 100644 index 0000000000..347da5d26c --- /dev/null +++ b/src/System.CommandLine.Rendering.Tests/ContainerSpanTests.cs @@ -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); + } + } +} diff --git a/src/System.CommandLine.Rendering/ContainerSpan.cs b/src/System.CommandLine.Rendering/ContainerSpan.cs index cb19ff563b..933204b4e4 100644 --- a/src/System.CommandLine.Rendering/ContainerSpan.cs +++ b/src/System.CommandLine.Rendering/ContainerSpan.cs @@ -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(); + } } }