Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
35 changes: 34 additions & 1 deletion Flow.Launcher.Test/Plugins/CalculatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
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)

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)

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)

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)

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
{
Expand All @@ -16,7 +16,8 @@
{
DecimalSeparator = DecimalSeparator.UseSystemLocale,
MaxDecimalPlaces = 10,
ShowErrorMessage = false // Make sure we return the empty results when error occurs
ShowErrorMessage = false, // Make sure we return the empty results when error occurs
UseThousandsSeparator = true // Default value
};
private readonly Engine _engine = new(new Configuration
{
Expand All @@ -41,6 +42,38 @@
engineField.SetValue(null, _engine);
}

[Test]
public void ThousandsSeparatorTest_Enabled()
{
_settings.UseThousandsSeparator = true;
_settings.DecimalSeparator = DecimalSeparator.Dot;

var result = GetCalculationResult("1000+234");
// When thousands separator is enabled, the result should contain a separator (comma in this case)
ClassicAssert.IsTrue(result.Contains(",") || result == "1234",
"Expected result to contain thousands separator or be without one if system doesn't use it");
Comment thread
Jack251970 marked this conversation as resolved.
Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the result is fixed "1,234" why do we meed the OR condition here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the result is fixed "1,234" why do we meed the OR condition here?

It is AI-generated. It has been modified.

}

[Test]
public void ThousandsSeparatorTest_Disabled()
{
_settings.UseThousandsSeparator = false;
_settings.DecimalSeparator = DecimalSeparator.Dot;

var result = GetCalculationResult("1000+234");
ClassicAssert.AreEqual("1234", result);
}

[Test]
public void ThousandsSeparatorTest_LargeNumber()
{
_settings.UseThousandsSeparator = false;
_settings.DecimalSeparator = DecimalSeparator.Dot;

var result = GetCalculationResult("1000000+234567");
ClassicAssert.AreEqual("1234567", result);
}

// Basic operations
[TestCase(@"1+1", "2")]
[TestCase(@"2-1", "1")]
Expand Down
1 change: 1 addition & 0 deletions Plugins/Flow.Launcher.Plugin.Calculator/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<system:String x:Key="flowlauncher_plugin_calculator_decimal_separator_comma">Comma (,)</system:String>
<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_use_thousands_separator">Use thousands separator</system:String>
Comment thread
Jack251970 marked this conversation as resolved.
Outdated
Comment thread
VictoriousRaptor marked this conversation as resolved.
Outdated
Comment thread
VictoriousRaptor marked this conversation as resolved.
Outdated
<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>
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Calculator/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
Title = newResult,
IcoPath = IcoPath,
Score = 300,
// Check context nullability for unit testing

Check warning on line 141 in Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

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

Check warning on line 141 in Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`nullability` is not a recognized word. (unrecognized-spelling)
SubTitle = Context == null ? string.Empty : Localize.flowlauncher_plugin_calculator_copy_number_to_clipboard(),
CopyText = newResult,
Action = c =>
Expand Down Expand Up @@ -363,7 +363,7 @@
string integerPart = parts[0];
string fractionalPart = parts.Length > 1 ? parts[1] : string.Empty;

if (integerPart.Length > 3)
if (_settings.UseThousandsSeparator && integerPart.Length > 3)
{
integerPart = ThousandGroupRegex.Replace(integerPart, groupSeparator);
}
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Flow.Launcher.Plugin.Calculator/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class Settings
public int MaxDecimalPlaces { get; set; } = 10;

public bool ShowErrorMessage { get; set; } = false;

public bool UseThousandsSeparator { get; set; } = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -66,6 +67,16 @@
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{DynamicResource flowlauncher_plugin_calculator_use_thousands_separator}"
IsChecked="{Binding Settings.UseThousandsSeparator, Mode=TwoWay}" />

<CheckBox
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{DynamicResource flowlauncher_plugin_calculator_show_error_message}"
IsChecked="{Binding Settings.ShowErrorMessage, Mode=TwoWay}" />
</Grid>
Expand Down
Loading