Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e107939
backout 'smart' digit grouping, mages fixes + workaround
dcog989 Sep 12, 2025
103d383
dead code, improve messages, group separator fix?
dcog989 Sep 12, 2025
190e0e1
Fix 'German' number formatting
dcog989 Sep 12, 2025
bd186e7
correct + extend description
dcog989 Sep 12, 2025
110f571
Rework solution for nested Mages
dcog989 Sep 13, 2025
6462023
Merge branch 'dev' into calculator-min-fix
dcog989 Sep 13, 2025
11f5ea5
Improve code quality
Jack251970 Sep 14, 2025
495ace1
Improve plugin description
Jack251970 Sep 14, 2025
daf35a4
Do not check bracket complete
Jack251970 Sep 14, 2025
c79e483
Merge branch 'Flow-Launcher:dev' into calculator-min-fix
dcog989 Sep 14, 2025
336e51d
IcoPath to const string
dcog989 Sep 14, 2025
e990e0f
Handle misplaced separators, Mages edge cases
dcog989 Sep 14, 2025
edc76fa
Review feedback, case insensitive, consistent separators
dcog989 Sep 14, 2025
9be8b71
review feedback, CultureInvariant, mild refactor
dcog989 Sep 14, 2025
b07420a
Use EmptyResults to improve code quality
Jack251970 Sep 15, 2025
cea1402
Improve code quality
Jack251970 Sep 15, 2025
1906d68
Add ShowErrorMessage setting
Jack251970 Sep 15, 2025
f9facda
Improve code quality
Jack251970 Sep 15, 2025
684fafd
Improve code quality
Jack251970 Sep 15, 2025
6841ad5
Add calculator unit testing
Jack251970 Sep 16, 2025
e10b925
Add workaround for log & ln function
Jack251970 Sep 16, 2025
552b654
Fix unit test result issue
Jack251970 Sep 16, 2025
8321e40
Fix test setting & Add instances to private fields
Jack251970 Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Flow.Launcher.Test/Flow.Launcher.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Calculator\Flow.Launcher.Plugin.Calculator.csproj" />
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Explorer\Flow.Launcher.Plugin.Explorer.csproj" />
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Program\Flow.Launcher.Plugin.Program.csproj" />
<ProjectReference Include="..\Plugins\Flow.Launcher.Plugin.Url\Flow.Launcher.Plugin.Url.csproj" />
Expand Down
88 changes: 88 additions & 0 deletions Flow.Launcher.Test/Plugins/CalculatorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Flow.Launcher.Plugin.Calculator;
using Mages.Core;
using NUnit.Framework;

Check warning on line 6 in Flow.Launcher.Test/Plugins/CalculatorTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NUnit` is not a recognized word. (unrecognized-spelling)
using NUnit.Framework.Legacy;

Check warning on line 7 in Flow.Launcher.Test/Plugins/CalculatorTest.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`NUnit` is not a recognized word. (unrecognized-spelling)

namespace Flow.Launcher.Test.Plugins
{
[TestFixture]
public class CalculatorPluginTest
{
private readonly Main _plugin;

public CalculatorPluginTest()
{
_plugin = new Main();

var settingField = typeof(Main).GetField("_settings", BindingFlags.NonPublic | BindingFlags.Instance);
if (settingField == null)
Assert.Fail("Could not find field '_settings' on Flow.Launcher.Plugin.Calculator.Main");
settingField.SetValue(_plugin, new Settings
{
ShowErrorMessage = false // Make sure we return the empty results when error occurs
});

var engineField = typeof(Main).GetField("MagesEngine", BindingFlags.NonPublic | BindingFlags.Static);
if (engineField == null)
Assert.Fail("Could not find static field 'MagesEngine' on Flow.Launcher.Plugin.Calculator.Main");
engineField.SetValue(null, new Engine(new Configuration
{
Scope = new Dictionary<string, object>
{
{ "e", Math.E }, // e is not contained in the default mages engine
}
}));
}

// Basic operations
[TestCase(@"1+1", "2")]
[TestCase(@"2-1", "1")]
[TestCase(@"2*2", "4")]
[TestCase(@"4/2", "2")]
[TestCase(@"2^3", "8")]
// Decimal places
[TestCase(@"10/3", "3.3333333333")]
// Parentheses
[TestCase(@"(1+2)*3", "9")]
[TestCase(@"2^(1+2)", "8")]
// Functions
[TestCase(@"pow(2,3)", "8")]
[TestCase(@"min(1,-1,-2)", "-2")]
[TestCase(@"max(1,-1,-2)", "1")]
[TestCase(@"sqrt(16)", "4")]
[TestCase(@"sin(pi)", "0.0000000000")]
[TestCase(@"cos(0)", "1")]
[TestCase(@"tan(0)", "0")]
[TestCase(@"log10(100)", "2")]
[TestCase(@"log(100)", "2")]
[TestCase(@"log2(8)", "3")]
[TestCase(@"ln(e)", "1")]
[TestCase(@"abs(-5)", "5")]
// Constants
[TestCase(@"pi", "3.1415926536")]
// Complex expressions
[TestCase(@"(2+3)*sqrt(16)-log(100)/ln(e)", "19")]
[TestCase(@"sin(pi/2)+cos(0)+tan(0)", "2")]
// Error handling (should return empty result)
[TestCase(@"10/0", "")]
[TestCase(@"sqrt(-1)", "")]
[TestCase(@"log(0)", "")]
[TestCase(@"invalid_expression", "")]
public void CalculatorTest(string expression, string result)
{
ClassicAssert.AreEqual(GetCalculationResult(expression), result);
}

private string GetCalculationResult(string expression)
{
var results = _plugin.Query(new Plugin.Query()
{
Search = expression
});
return results.Count > 0 ? results[0].Title : string.Empty;
}
}
}
3 changes: 2 additions & 1 deletion Plugins/Flow.Launcher.Plugin.Calculator/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:system="clr-namespace:System;assembly=mscorlib">

<system:String x:Key="flowlauncher_plugin_calculator_plugin_name">Calculator</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_plugin_description">Perform mathematical calculations (including hexadecimal values). Use ',' or '.' as thousand separator or decimal place.</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_plugin_description">Perform mathematical calculations, including hex values and advanced functions such as 'min(1,2,3)', 'sqrt(123)' and 'cos(123)'.</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_not_a_number">Not a number (NaN)</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_expression_not_complete">Expression wrong or incomplete (Did you forget some parentheses?)</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_copy_number_to_clipboard">Copy this number to the clipboard</system:String>
Expand All @@ -15,4 +15,5 @@
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_dot">Dot (.)</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_max_decimal_places">Max. decimal places</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_failed_to_copy">Copy failed, please try later</system:String>
<system:String x:Key="flowlauncher_plugin_calculator_show_error_message">Show error message when calculation fails</system:String>
</ResourceDictionary>
Loading
Loading