diff --git a/Navferty.Common/Extensions/StringExtensions.cs b/Navferty.Common/Extensions/StringExtensions.cs
index d63c277..5b14629 100644
--- a/Navferty.Common/Extensions/StringExtensions.cs
+++ b/Navferty.Common/Extensions/StringExtensions.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System.Diagnostics;
+using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
@@ -6,6 +7,7 @@
namespace Navferty.Common
{
+ [DebuggerStepThrough]
public static class StringExtensions
{
//private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
@@ -25,12 +27,20 @@ public static class StringExtensions
: newValue.Trim();
return newValue;
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static int CountChars(this string value, char c)
- {
- return value.Count(x => x == c);
- }
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int CountChars(this string value, char c)
+ => value.Count(x => x == c);
+
+ /// Removes only ASCII Space char (0x32)
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static string RemoveSpacesFast(this string source)
+ => source.Replace(" ", string.Empty);
+
+ /// Removes all Unicode character which is categorized as white space.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static string RemoveSpacesEx(this string source)
+ => string.Concat(source.Where(c => !char.IsWhiteSpace(c)));
}
}
diff --git a/NavfertyExcelAddIn.UnitTests/ParseNumerics/DecimalParserTests.cs b/NavfertyExcelAddIn.UnitTests/ParseNumerics/DecimalParserTests.cs
index 939df4e..67ad989 100644
--- a/NavfertyExcelAddIn.UnitTests/ParseNumerics/DecimalParserTests.cs
+++ b/NavfertyExcelAddIn.UnitTests/ParseNumerics/DecimalParserTests.cs
@@ -9,27 +9,45 @@ namespace NavfertyExcelAddIn.UnitTests.ParseNumerics
[TestClass]
public class DecimalParserTests
{
- [DataRow("0", 0)]
- [DataRow("123", 123)]
- [DataRow("1.1", 1.1)]
- [DataRow("1,1", 1.1)]
- [DataRow("1 000", 1000)]
- [DataRow("12 00 00 . 12", 120000.12)]
- [DataRow("0.1", 0.1)]
- [DataRow(".123", 0.123)]
- [DataRow("10.000.000", 10000000)]
- [DataRow("10.000,12", 10000.12)]
- [DataRow("12,345.12", 12345.12)]
- [DataRow("12,345,000", 12345000)]
- [DataRow("1E6", 1000000)]
- [DataRow("1.2E3", 1200)]
- [DataRow("-1.3E-5", -0.000013)]
+ [DataRow("0", 0, null)]
+ [DataRow("123", 123, null)]
+ [DataRow("1.1", 1.1, null)]
+ [DataRow("1,1", 1.1, null)]
+ [DataRow("1 000", 1000, null)]
+ [DataRow("12 00 00 . 12", 120000.12, null)]
+ [DataRow("0.1", 0.1, null)]
+ [DataRow(".123", 0.123, null)]
+ [DataRow("10.000.000", 10000000, null)]
+ [DataRow("10.000,12", 10000.12, null)]
+ [DataRow("12,345.12", 12345.12, null)]
+ [DataRow("12,345,000", 12345000, null)]
+ [DataRow("1E6", 1000000, null)]
+ [DataRow("1.2E3", 1200, null)]
+ [DataRow("-1.3E-5", -0.000013, null)]
+ [DataRow("$5666", 5666, "$")]
+ [DataRow("5666$", 5666, "$")]
+ [DataRow("$56.66", 56.66, "$")]
+ [DataRow("56.66$", 56.66, "$")]
+ [DataRow("$56,66", 56.66, "$")]
+ [DataRow("56,66$", 56.66, "$")]
+ [DataRow("₽5666", 5666, "₽")]
+ [DataRow("5666₽", 5666, "₽")]
+ [DataRow("₽56.66", 56.66, "₽")]
+ [DataRow("56.66₽", 56.66, "₽")]
+ [DataRow("₽56,66", 56.66, "₽")]
+ [DataRow("56,66₽", 56.66, "₽")]
+ [DataRow("£5666", 5666, "£")]
+ [DataRow("5666£", 5666, "£")]
+ [DataRow("£56.66", 56.66, "£")]
+ [DataRow("56.66£", 56.66, "£")]
+ [DataRow("£56.66", 56.66, "£")]
+ [DataRow("56.66£", 56.66, "£")]
[TestMethod]
- public void ParseDecimal_Success(string sourceValue, double targetDoubleValue)
- {
- // DataRow can't into decimals - they are not primitive type
- var targetValue = Convert.ToDecimal(targetDoubleValue);
-
+ public void ParseDecimal_Success(string sourceValue, double targetDoubleValue, string currencySymbol)
+ {
+ var targetValue = new NumericParseResult(targetDoubleValue, currencySymbol);
+ // DataRow can't into decimals - they are not primitive type
+ //var targetValue = Convert.ToDecimal(targetDoubleValue);
Assert.AreEqual(targetValue, sourceValue.ParseDecimal());
}
@@ -37,9 +55,25 @@ public void ParseDecimal_Success(string sourceValue, double targetDoubleValue)
public void ParseDecimal_MissingValue()
{
var input = "no value";
-
- Assert.AreEqual(null, input.ParseDecimal());
+ Assert.AreEqual(null, input.ParseDecimal());
}
+ [TestMethod]
+ public void ParseDecimal_UnknownCurrency()
+ {
+ var input = "56.66%";
+ Assert.AreEqual(null, input.ParseDecimal());
+ }
+
+ [TestMethod]
+ public void ParseDecimal_MultipleCurrencyInOneString()
+ {
+ Assert.AreEqual(null, "56.66£₽".ParseDecimal());
+ Assert.AreEqual(null, "56.66₽£".ParseDecimal());
+ Assert.AreEqual(null, "₽£56.66".ParseDecimal());
+ }
+
+
+
}
}
diff --git a/NavfertyExcelAddIn.UnitTests/ParseNumerics/NumericParserTests.cs b/NavfertyExcelAddIn.UnitTests/ParseNumerics/NumericParserTests.cs
index dfdfa30..7665f6e 100644
--- a/NavfertyExcelAddIn.UnitTests/ParseNumerics/NumericParserTests.cs
+++ b/NavfertyExcelAddIn.UnitTests/ParseNumerics/NumericParserTests.cs
@@ -25,7 +25,7 @@ public void BeforeEachTest()
}
[TestMethod]
- public void ParsedSuccessfully() // TODO naming
+ public void ParsedSuccessfully() // TODO naming
{
var selection = new Mock(MockBehavior.Strict);
var values = new object[,] { { 1, "1", "abc" }, { "123.123", "321 , 321", null } };
@@ -46,9 +46,17 @@ public void ParsedSuccessfully() // TODO naming
ws.Setup(x => x.Parent).Returns(wb.Object);
var areas = new Mock(MockBehavior.Strict);
- areas.Setup(x => x.GetEnumerator()).Returns(new[] { selection.Object }.GetEnumerator());
- selection.Setup(x => x.Areas).Returns(areas.Object);
-
+ areas.Setup(x => x.GetEnumerator()).Returns(new[] { selection.Object }.GetEnumerator());
+ selection.Setup(x => x.Areas).Returns(areas.Object);
+
+
+ var cells = new Mock(MockBehavior.Default);
+ cells.Setup(x => x.GetEnumerator()).Returns(new[] { selection.Object }.GetEnumerator());
+ //selection.SetupSet(x => x.get_Cells = It.Is