forked from Librelancer/Librelancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Librelancer#166 from Librelancer/2024.06.1
Hotfix: Fix locale regression in ini parsing
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using LibreLancer.Ini; | ||
using System.Text; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace LibreLancer.Tests.Ini; | ||
|
||
public class LocaleTests | ||
{ | ||
void RunWithLocale(string locale, Action action) | ||
{ | ||
var currentLocale = CultureInfo.CurrentCulture; | ||
var locale2 = CultureInfo.GetCultureInfo(locale); | ||
CultureInfo.CurrentCulture = locale2; | ||
action(); | ||
CultureInfo.CurrentCulture = currentLocale; | ||
} | ||
|
||
[Theory] | ||
[InlineData("en-US")] | ||
[InlineData("de-DE")] | ||
[InlineData("es-ES")] | ||
public void TestDecimalSeparator(string locale) | ||
{ | ||
RunWithLocale(locale, () => | ||
{ | ||
var parser = new LancerTextIniParser(); | ||
var s = new MemoryStream("[Section]\nValue = 1.1"u8.ToArray()); | ||
|
||
var p = parser.ParseIniFile("[data]", s, true, false).ToArray(); | ||
p.Should().HaveCount(1); | ||
p[0].Name.Should().Be("Section"); | ||
p[0].Should().HaveCount(1); | ||
p[0][0].Name.Should().Be("Value"); | ||
p[0][0].Should().HaveCount(1); | ||
p[0][0][0].Should().BeOfType<SingleValue>(); | ||
p[0][0][0].ToSingle().Should().Be(1.1f); | ||
}); | ||
} | ||
} |