mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-31 06:25:20 +00:00
[PT Run] Calculator plugin: Various improvements (#18159)
* crash fixes and error result * small changes and test fixes * improve exceptions and message * double array crash fix * overflowexception * improve error handling * varous improvements * varous improvements * fix spelling * fix spelling * Revert #16980 * add description * error improvemenet * Update tests * spelling fixes * small changes * add settings * last changes * fix description * update dev docs * spell check
This commit is contained in:
@@ -3,6 +3,22 @@ The Calculator plugin as the name suggests is used to perform calculations on th
|
||||
|
||||

|
||||
|
||||
## Optional plugin settings
|
||||
|
||||
* We have the following settings that the user can configure to change the behavior of the plugin:
|
||||
|
||||
| Key | Default value | Name | Description |
|
||||
|--------------|-----------|------------|------------|
|
||||
| `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' |
|
||||
|
||||
* 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.
|
||||
|
||||
## Technical details
|
||||
|
||||
### [`BracketHelper`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/BracketHelper.cs)
|
||||
- This helper validates the bracket usage in the input string.
|
||||
|
||||
### [`CalculateHelper`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateHelper.cs)
|
||||
- The [`CalculateHelper.cs`](src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateHelper.cs) class checks to see if the user entered query is a valid input to the calculator and only if the input is valid does it perform the operation.
|
||||
- It does so by matching the user query to a valid regex.
|
||||
@@ -18,6 +34,26 @@ var result = CalculateEngine.Interpret(query.Search, CultureInfo.CurrentUICultur
|
||||
- The class which encapsulates the result of the computation.
|
||||
- It comprises of the `Result` and `RoundedResult` properties.
|
||||
|
||||
### [`ErrorHandler`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/ErrorHandler.cs)
|
||||
- The class which encapsulates the code to log errors and format the user message.
|
||||
- It returns an error result if the user searches with the activation command. This error result is shown to the user.
|
||||
|
||||
### Score
|
||||
The score of each result from the calculator plugin is `300`.
|
||||
|
||||
|
||||
## [Unit Tests](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests)
|
||||
We have a [Unit Test project](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests) that executes various test to ensure that the plugin works as expected.
|
||||
|
||||
### [`BracketHelperTests`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/BracketHelperTests.cs)
|
||||
- The [`BracketHelperTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/BracketHelperTests.cs) class contains tests to validate that brackets are handled correctly.
|
||||
|
||||
### [`ExtendedCalculatorParserTests`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/ExtendedCalculatorParserTests.cs)
|
||||
- The [`ExtendedCalculatorParserTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/ExtendedCalculatorParserTests.cs) class contains tests to validate that the input is parsed correctly and the result is correct.
|
||||
|
||||
### [`NumberTranslatorTests`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/NumberTranslatorTests.cs)
|
||||
- The [`NumberTranslatorTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/NumberTranslatorTests.cs) class contains tests to validate that each number is converted correctly based on the defined locals.
|
||||
|
||||
### [`QueryTests`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/QueryTests.cs)
|
||||
- The [`QueryTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests/QueryTests.cs) class contains tests to validate that the user gets the correct results when searching.
|
||||
|
||||
|
Reference in New Issue
Block a user