Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions PowerKit.Tests/CharExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using FluentAssertions;
using PowerKit.Extensions;
using Xunit;

namespace PowerKit.Tests;

public class CharExtensionsTests
{
[Fact]
public void Repeat_Test()
{
// Act & assert
'a'.Repeat(3).Should().Be("aaa");
'x'.Repeat(1).Should().Be("x");
'z'.Repeat(0).Should().Be("");
}

[Fact]
public void AsString_Test()
{
// Act & assert
'a'.AsString().Should().Be("a");
' '.AsString().Should().Be(" ");
}
}
23 changes: 23 additions & 0 deletions PowerKit/Extensions/CharExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#nullable enable
using System.Diagnostics.CodeAnalysis;

namespace PowerKit.Extensions;

#if !POWERKIT_INCLUDE_COVERAGE
[ExcludeFromCodeCoverage]
#endif
internal static class CharExtensions
{
extension(char c)
{
/// <summary>
/// Returns a string that contains the character repeated the specified number of times.
/// </summary>
public string Repeat(int count) => new(c, count);

/// <summary>
/// Returns a string that contains only this character.
/// </summary>
public string AsString() => c.Repeat(1);
}
}