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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
Expand Down
17 changes: 17 additions & 0 deletions Distractive.Formatters.Tests/FormatterExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion Distractive.Formatters/Distractive.Formatters.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
Expand Down
2 changes: 1 addition & 1 deletion Distractive.Formatters/FormatterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading