Skip to content

Commit

Permalink
Completed basic support for tostring.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Jul 21, 2024
1 parent 839f9fa commit 5b41a7d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Hussy.Net/Display/ToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ public static partial class Hussy
/// <typeparam name="T">Specifies the type of the <paramref name="input"/> to convert.</typeparam>
/// <returns>
/// The <see cref="string"/> representation of the specified
/// <paramref name="input"/> instance.
/// <paramref name="input"/> instance. A value of
/// <see langword="null"/> will return a <see cref="string"/>
/// containing the word <see langword="null"/>.
/// </returns>
public static string Ts<T>(this T input) =>
input.ToString();
public static string Ts<T>(this T input)
{
var result = input?.ToString();
return result ?? "null";
}
}
22 changes: 22 additions & 0 deletions test/Hussy.Net.Tests/Display/ToStringTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Hussy.Net.Tests.Display;

public class ToStringTests
{
[Fact]
public void ToString_NullInput_ReturnsNullLiteral()
{
const string expectedResult = "null";
int? testValue = null;
var actualResult = testValue.Ts();
Assert.Equal(expectedResult, actualResult);
}

[Fact]
public void ToString_ValidInput_ReturnsInputAsString()
{
const string expectedResult = "32";
var testValue = 32;
var actualResult = testValue.Ts();
Assert.Equal(expectedResult, actualResult);
}
}

0 comments on commit 5b41a7d

Please sign in to comment.