diff --git a/Distractive.Formatters.Tests/Distractive.Formatters.Tests.csproj b/Distractive.Formatters.Tests/Distractive.Formatters.Tests.csproj index 279a085..5aa2062 100644 --- a/Distractive.Formatters.Tests/Distractive.Formatters.Tests.csproj +++ b/Distractive.Formatters.Tests/Distractive.Formatters.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 enable false diff --git a/Distractive.Formatters.Tests/FormatterExtensionsTests.cs b/Distractive.Formatters.Tests/FormatterExtensionsTests.cs index 155de9e..a5d78c8 100644 --- a/Distractive.Formatters.Tests/FormatterExtensionsTests.cs +++ b/Distractive.Formatters.Tests/FormatterExtensionsTests.cs @@ -16,5 +16,22 @@ public void ExtensionTests() Assert.Equal("หนึ่ง", 1L.ToThaiWords()); Assert.Equal("หนึ่ง", 1.ToThaiWords()); } + + [Theory] + [InlineData(42, "สี่สิบสอง")] + [InlineData(101, "หนึ่งร้อยหนึ่ง")] + [InlineData(121, "หนึ่งร้อยยี่สิบเอ็ด")] + [InlineData(1001, "หนึ่งพันหนึ่ง")] + public void ToThaiWords_IntWithBoolParameter_ShouldNotCauseStackOverflow(int value, string expected) + { + // This test ensures that the ToThaiWords(int, bool) method + // doesn't cause stack overflow by calling itself recursively + string result = value.ToThaiWords(true); + Assert.Equal(expected, result); + + // Also verify it matches the long version behavior + string longResult = ((long)value).ToThaiWords(true); + Assert.Equal(longResult, result); + } } } diff --git a/Distractive.Formatters/Distractive.Formatters.csproj b/Distractive.Formatters/Distractive.Formatters.csproj index 317048a..c81d1d7 100644 --- a/Distractive.Formatters/Distractive.Formatters.csproj +++ b/Distractive.Formatters/Distractive.Formatters.csproj @@ -1,6 +1,6 @@  - net6.0;netstandard2.0;netstandard2.1 + net8.0;net6.0;netstandard2.0;netstandard2.1 enable 11 False diff --git a/Distractive.Formatters/FormatterExtensions.cs b/Distractive.Formatters/FormatterExtensions.cs index d00bb73..5809cdf 100644 --- a/Distractive.Formatters/FormatterExtensions.cs +++ b/Distractive.Formatters/FormatterExtensions.cs @@ -34,7 +34,7 @@ public static string ToBahtText(this decimal value, public static string ToThaiWords(this long value, bool useEtWithTensOnly) => _formatters[useEtWithTensOnly ? 1 : 0].Format(value); - public static string ToThaiWords(this int value, bool useEtWithTensOnly) => ToThaiWords(value, useEtWithTensOnly); + public static string ToThaiWords(this int value, bool useEtWithTensOnly) => ToThaiWords((long)value, useEtWithTensOnly); public static string ToBahtText(this decimal value, bool useEtWithTensOnly) => _formatters[useEtWithTensOnly ? 1 : 0].GetBahtText(value);