mirror of
https://github.com/ppy/osu.git
synced 2026-05-16 17:03:01 +08:00
7f5f368dea
Closes https://github.com/ppy/osu/issues/37553. You can probably tell by the title that this is going to be a good one. As previously mentioned in https://github.com/ppy/osu/pull/35395, framework-side `TextBox` uses a bunch of `NumberFormat` properties from `CurrentCulture` to contextually allow decimal points or minus signs in a textbox. In some languages, namely (of the ones we support): Finnish, Croatian, Lithuanian, Norsk, Slovenian, and Swedish, `NumberFormat.NegativeSign` is not `U+002D HYPHEN MINUS`, but instead `U+2212 MINUS SIGN`. Therefore, in `FormSliderBar`, when `ToStandardFormattedString()` is attempted to be used to set the textbox value, the hardcoded `U+002D HYPHEN MINUS` is rejected on cultures that expect `U+2212 MINUS SIGN`, and thus due to a feedback loop, all negative values are no longer settable. This applies the obvious fix of applying `NumberFormat.NegativeSign`.
68 lines
2.9 KiB
C#
68 lines
2.9 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 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%")]
|
||
[SetCulture("")] // invariant culture
|
||
public string TestInteger(int input, bool percent, int decimalDigits)
|
||
{
|
||
return input.ToStandardFormattedString(decimalDigits, percent);
|
||
}
|
||
|
||
[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%")]
|
||
[SetCulture("")] // invariant culture
|
||
public string TestDouble(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 TestCultureSensitivityDecimalPoint(double input, bool percent, int decimalDigits)
|
||
{
|
||
return input.ToStandardFormattedString(decimalDigits, percent);
|
||
}
|
||
|
||
[Test]
|
||
[SetCulture("sv-SE")]
|
||
[TestCase(-1e-6, false, 6, ExpectedResult = "−0,000001")]
|
||
public string TestCultureSensitivityNegativeSign(double input, bool percent, int decimalDigits)
|
||
{
|
||
return input.ToStandardFormattedString(decimalDigits, percent);
|
||
}
|
||
}
|
||
}
|