mirror of
https://github.com/ppy/osu.git
synced 2026-05-24 11:30:17 +08:00
a29a5ab7e6
I had previously made it invariant in https://github.com/ppy/osu/pull/32837, and in another instance of past me being an asshole, I can't actually find the reasoning for this at this time. That said, you'd be excused for thinking "why does this matter"? Well, this will fix https://github.com/ppy/osu/issues/35381, because that failure only occurs when the user's culture is set to one that doesn't use a decimal point (.) but rather a decimal comma (,). This messes with framework, which uses the *current* culture to check for decimal separator rather than invariant: https://github.com/ppy/osu-framework/blob/d3226a7842487de43a0d989e1bb59a9ebbc479af/osu.Framework/Graphics/UserInterface/TextBox.cs#L106-L111 An alternative would be to change framework instead to always accept the invariant decimal separator. God I hate this culture crap.
69 lines
3.0 KiB
C#
69 lines
3.0 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
using System.Globalization;
|
|
using NUnit.Framework;
|
|
using osu.Game.Extensions;
|
|
|
|
namespace osu.Game.Tests.Extensions
|
|
{
|
|
[TestFixture]
|
|
public class NumberFormattingExtensionsTest
|
|
{
|
|
[TestCase(-1, false, 0, ExpectedResult = "-1")]
|
|
[TestCase(0, false, 0, ExpectedResult = "0")]
|
|
[TestCase(1, false, 0, ExpectedResult = "1")]
|
|
[TestCase(500, false, 10, ExpectedResult = "500")]
|
|
[TestCase(-1, true, 0, ExpectedResult = "-1%")]
|
|
[TestCase(0, true, 0, ExpectedResult = "0%")]
|
|
[TestCase(1, true, 0, ExpectedResult = "1%")]
|
|
[TestCase(50, true, 0, ExpectedResult = "50%")]
|
|
public string TestInteger(int input, bool percent, int decimalDigits)
|
|
{
|
|
return input.ToStandardFormattedString(decimalDigits, percent, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
[TestCase(-1, false, 0, ExpectedResult = "-1")]
|
|
[TestCase(-1e-6, false, 0, ExpectedResult = "0")]
|
|
[TestCase(-1e-6, false, 6, ExpectedResult = "-0.000001")]
|
|
[TestCase(0, false, 10, ExpectedResult = "0")]
|
|
[TestCase(0, false, 0, ExpectedResult = "0")]
|
|
[TestCase(double.NegativeZero, false, 0, ExpectedResult = "0")]
|
|
[TestCase(1e-6, false, 0, ExpectedResult = "0")]
|
|
[TestCase(1e-6, false, 6, ExpectedResult = "0.000001")]
|
|
[TestCase(1, false, 0, ExpectedResult = "1")]
|
|
[TestCase(1.528, false, 2, ExpectedResult = "1.53")]
|
|
[TestCase(500, false, 10, ExpectedResult = "500")]
|
|
[TestCase(-0.1, true, 0, ExpectedResult = "-10%")]
|
|
[TestCase(0, true, 0, ExpectedResult = "0%")]
|
|
[TestCase(0.4, true, 0, ExpectedResult = "40%")]
|
|
[TestCase(0.48333, true, 2, ExpectedResult = "48%")]
|
|
[TestCase(0.48333, true, 4, ExpectedResult = "48.33%")]
|
|
[TestCase(1, true, 0, ExpectedResult = "100%")]
|
|
public string TestDouble(double input, bool percent, int decimalDigits)
|
|
{
|
|
return input.ToStandardFormattedString(decimalDigits, percent, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
[Test]
|
|
[SetCulture("fr-FR")]
|
|
[TestCase(0.4, true, 2, ExpectedResult = "40%")]
|
|
[TestCase(1e-6, false, 6, ExpectedResult = "0,000001")]
|
|
[TestCase(0.48333, true, 4, ExpectedResult = "48,33%")]
|
|
public string TestCultureSensitivityWhenNoneSpecified(double input, bool percent, int decimalDigits)
|
|
{
|
|
return input.ToStandardFormattedString(decimalDigits, percent);
|
|
}
|
|
|
|
[Test]
|
|
[SetCulture("fr-FR")]
|
|
[TestCase(0.4, true, 2, ExpectedResult = "40%")]
|
|
[TestCase(1e-6, false, 6, ExpectedResult = "0.000001")]
|
|
[TestCase(0.48333, true, 4, ExpectedResult = "48.33%")]
|
|
public string TestCultureInsensitivityWhenInvariantSpecified(double input, bool percent, int decimalDigits)
|
|
{
|
|
return input.ToStandardFormattedString(decimalDigits, percent, CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
}
|