Skip to content

Commit d252893

Browse files
authored
Add Add() method to ContainerSpan class (#904)
1 parent 750fdd1 commit d252893

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.IO;
5+
using FluentAssertions;
6+
using Xunit;
7+
8+
namespace System.CommandLine.Rendering.Tests
9+
{
10+
public class ContainerSpanTests
11+
{
12+
[Fact]
13+
public void Container_span_supports_add_method()
14+
{
15+
var span = new ContainerSpan(new ContentSpan("content"));
16+
span.Add(new ContentSpan(" with child"));
17+
18+
span.ContentLength.Should().Be("content with child".Length);
19+
}
20+
}
21+
}

src/System.CommandLine.Rendering/ContainerSpan.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,17 @@ public override void WriteTo(TextWriter writer, OutputMode outputMode)
6060
_children[i].WriteTo(writer, outputMode);
6161
}
6262
}
63+
64+
public void Add(TextSpan child)
65+
{
66+
if (child == null)
67+
{
68+
throw new ArgumentNullException(nameof(child));
69+
}
70+
71+
_children.Add(child);
72+
73+
RecalculateChildPositions();
74+
}
6375
}
6476
}

0 commit comments

Comments
 (0)