mirror of
https://github.com/wagesj45/CapyKit.git
synced 2024-11-14 04:03:36 -06:00
66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
using CapyKit.Extensions;
|
|
using NUnit.Framework;
|
|
|
|
namespace Tests
|
|
{
|
|
[TestFixture]
|
|
internal class StringExtensionTests
|
|
{
|
|
private const string Replacement = "Replaced";
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
// No setup required for this test fixture.
|
|
}
|
|
|
|
#region IfNullOrEmpty
|
|
|
|
[TestCase("")]
|
|
public void IfNullOrEmpty_ShouldReturnReplacementWhenValueIsNullOrEmpty(string value)
|
|
{
|
|
var result = value.IfNullOrEmpty(Replacement);
|
|
|
|
Assert.AreEqual(Replacement, result);
|
|
}
|
|
|
|
[TestCase("Not Empty")]
|
|
[TestCase(" ")] // Whitespace is not considered empty
|
|
public void IfNullOrEmpty_ShouldReturnOriginalStringWhenValueIsNotNullNorEmpty(string value)
|
|
{
|
|
var result = value.IfNullOrEmpty(Replacement);
|
|
|
|
Assert.AreEqual(value, result);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IfNullOrWhiteSpace
|
|
|
|
[TestCase("")]
|
|
[TestCase(" ")] // Whitespace is considered empty
|
|
public void IfNullOrWhiteSpace_ShouldReturnReplacementWhenValueIsNullOrWhitespace(string value)
|
|
{
|
|
var result = value.IfNullOrWhiteSpace(Replacement);
|
|
|
|
Assert.AreEqual(Replacement, result);
|
|
}
|
|
|
|
[TestCase("Not Empty")]
|
|
[TestCase("\tTab")] // Non-whitespace character is not considered empty
|
|
public void IfNullOrWhiteSpace_ShouldReturnOriginalStringWhenValueIsNotNullNorWhitespace(string value)
|
|
{
|
|
var result = value.IfNullOrWhiteSpace(Replacement);
|
|
|
|
Assert.AreEqual(value, result);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|