From 076ccd19770ac631d60d0366db3d4658308ce999 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 17 Jul 2026 19:31:27 +0000 Subject: [PATCH] Add StringExtensions unit tests Co-authored-by: johnstrand <11484777+johnstrand@users.noreply.github.com> --- .../Extensions/StringExtensionsTests.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/GameUtils.Tests/Extensions/StringExtensionsTests.cs diff --git a/tests/GameUtils.Tests/Extensions/StringExtensionsTests.cs b/tests/GameUtils.Tests/Extensions/StringExtensionsTests.cs new file mode 100644 index 0000000..404fa2c --- /dev/null +++ b/tests/GameUtils.Tests/Extensions/StringExtensionsTests.cs @@ -0,0 +1,56 @@ +using System; +using GameUtils.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace GameUtils.Tests.Extensions; + +[TestClass] +public class StringExtensionsTests +{ + [TestMethod] + [DataRow("hello", 0, true, 'h')] + [DataRow("hello", 4, true, 'o')] + [DataRow("hello", -1, false, '\0')] + [DataRow("hello", 5, false, '\0')] + [DataRow("", 0, false, '\0')] + public void TryGet_ReturnsExpectedResult(string str, int index, bool expectedReturn, char expectedChar) + { + var result = str.TryGet(index, out char c); + Assert.AreEqual(expectedReturn, result); + Assert.AreEqual(expectedChar, c); + } + + [TestMethod] + public void TryGet_NullString_ThrowsArgumentNullException() + { + string str = null!; + Assert.ThrowsExactly(() => str.TryGet(0, out _)); + } + + [TestMethod] + [DataRow("hello", 3, "hellohellohello")] + [DataRow("a", 5, "aaaaa")] + [DataRow("abc", 1, "abc")] + [DataRow("test", 0, "")] + [DataRow("", 5, "")] + [DataRow("", 0, "")] + public void Repeat_ReturnsExpectedResult(string str, int count, string expectedResult) + { + var result = str.Repeat(count); + Assert.AreEqual(expectedResult, result); + } + + [TestMethod] + public void Repeat_NullString_ThrowsArgumentNullException() + { + string str = null!; + Assert.ThrowsExactly(() => str.Repeat(5)); + } + + [TestMethod] + public void Repeat_NegativeCount_ThrowsArgumentOutOfRangeException() + { + string str = "test"; + Assert.ThrowsExactly(() => str.Repeat(-1)); + } +}