mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-27 14:59:16 +08:00
- Added unit tests
- Found problem: due to implementation, it actually only ignores difference between decimal and group separators, so I updated description accordingly
This commit is contained in:
parent
cfb83c7510
commit
e6b6dc8707
@ -11,7 +11,7 @@ The Calculator plugin as the name suggests is used to perform calculations on th
|
||||
|--------------|-----------|------------|------------|
|
||||
| `InputUseEnglishFormat` | `false` | Use English (United States) number format for input | Ignores your system setting and expects numbers in the format '1,000.50' |
|
||||
| `OutputUseEnglishFormat` | `false` | Use English (United States) number format for output | Ignores your system setting and returns numbers in the format '1000.50' |
|
||||
| `IgnoreRegionalFormatting` | `false` | Ignore delimiters from non-native formatting in input | Changes input to match your regional setting, treating the last non-digit symbol as decimal separator |
|
||||
| `IgnoreRegionalFormatting` | `false` | Ignore difference between decimal and group separators | Ignores difference between '.' and ',', treating the last of them as the decimal separator |
|
||||
|
||||
* The optional plugin settings are implemented via the [`ISettingProvider`](/src/modules/launcher/Wox.Plugin/ISettingProvider.cs) interface from `Wox.Plugin` project. All available settings for the plugin are defined in the [`Main`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/Main.cs) class of the plugin.
|
||||
|
||||
|
@ -179,5 +179,23 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow("2,5", "2.5", true)]
|
||||
[DataRow("2,5*10", "2.5*10", true)]
|
||||
[DataRow("2,5", "25", false)]
|
||||
[DataRow("2,5*10", "25*10", false)]
|
||||
public void Translate_Ignoring_Regional_Formatting(string input, string expectedResult, bool ignoreRegionalFormatting)
|
||||
{
|
||||
// Arrange
|
||||
var translator = NumberTranslator.Create(new CultureInfo("en-US", false), new CultureInfo("en-US", false));
|
||||
|
||||
// Act
|
||||
var result = translator.Translate(input, ignoreRegionalFormatting);
|
||||
|
||||
// Assert
|
||||
Assert.IsNotNull(result);
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
||||
|
||||
private static readonly CompositeFormat WoxPluginCalculatorInEnFormatDescription = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_calculator_in_en_format_description);
|
||||
private static readonly CompositeFormat WoxPluginCalculatorOutEnFormatDescription = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_calculator_out_en_format_description);
|
||||
private static readonly CompositeFormat WoxPluginCalculatorIgnoreRegionalDescription = System.Text.CompositeFormat.Parse(Properties.Resources.wox_plugin_calculator_ignore_regional_formatting_description);
|
||||
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
|
||||
{
|
||||
@ -72,7 +73,11 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
||||
{
|
||||
Key = IgnoreRegionalFormatting,
|
||||
DisplayLabel = Resources.wox_plugin_calculator_ignore_regional_formatting,
|
||||
DisplayDescription = Resources.wox_plugin_calculator_ignore_regional_formatting_description,
|
||||
DisplayDescription = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
WoxPluginCalculatorIgnoreRegionalDescription,
|
||||
CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
|
||||
CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator),
|
||||
Value = false,
|
||||
},
|
||||
};
|
||||
|
@ -115,7 +115,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Ignore regional formatting, using the last delimiter symbol to separate whole and decimal parts.
|
||||
/// Looks up a localized string similar to Ignore difference between decimal and group separators.
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_ignore_regional_formatting {
|
||||
get {
|
||||
@ -124,7 +124,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Changes input to match your regional setting, treating the last non-digit symbol as decimal separator.
|
||||
/// Looks up a localized string similar to Ignores difference between '{0}' and '{1}', treating the last of them as the decimal separator.
|
||||
/// </summary>
|
||||
public static string wox_plugin_calculator_ignore_regional_formatting_description {
|
||||
get {
|
||||
|
@ -168,9 +168,10 @@
|
||||
<value>When using direct activation, appending '=' to the expression will replace the input with the calculated result (e.g. '=5*3-2=' will change the query to '=13').</value>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_ignore_regional_formatting" xml:space="preserve">
|
||||
<value>Ignore regional formatting, using the last delimiter symbol to separate whole and decimal parts</value>
|
||||
<value>Ignore difference between decimal and group separators</value>
|
||||
</data>
|
||||
<data name="wox_plugin_calculator_ignore_regional_formatting_description" xml:space="preserve">
|
||||
<value>Changes input to match your regional setting, treating the last non-digit symbol as decimal separator</value>
|
||||
<value>Ignores difference between '{0}' and '{1}', treating the last of them as the decimal separator</value>
|
||||
<comment>{0} and {1} are placeholders and will be replaced in code</comment>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user