Browse Source

sum: added sum_regex_currency_first

Fabian Peter Hammerle 7 years ago
parent
commit
412bb0cd9c
2 changed files with 25 additions and 2 deletions
  1. 3 0
      finoex/__init__.py
  2. 22 2
      tests/test_sum.py

+ 3 - 0
finoex/__init__.py

@@ -96,6 +96,9 @@ class Sum(ioex.calcex.Figure):
     sum_regex_value_first = r'\$?(?P<value>{}) (?P<currency>{})'.format(
         value_regex, currency_regex,
     )
+    sum_regex_currency_first = r'(?P<currency>{}) ?(?P<value>{})'.format(
+        currency_regex, value_regex,
+    )
 
     sum_regex = [
         r'^\$?(?P<value>{}) (?P<currency>{})$'.format(

+ 22 - 2
tests/test_sum.py

@@ -119,11 +119,16 @@ def test_parse_text_fail(text):
 
 
 @pytest.mark.parametrize(('haystack', 'expected_needles'), [
-    ["Preis: 0,50 €", [{'currency': '€', 'value': '0,50'}]],
     ["Preis: 0,50 US$", [{'currency': 'US$', 'value': '0,50'}]],
+    ["Preis: 0,50 €", [{'currency': '€', 'value': '0,50'}]],
     ["Preis: 1234 ¥", [{'currency': '¥', 'value': '1234'}]],
-    ["price: 1.23 €", [{'currency': '€', 'value': '1.23'}]],
+    ["Preis: US$ 0,50", []],
+    ["Preis: € 0,50", []],
+    ["Preis: ¥1234", []],
     ["price: 1.23 US$", [{'currency': 'US$', 'value': '1.23'}]],
+    ["price: 1.23 €", [{'currency': '€', 'value': '1.23'}]],
+    ["price: US$ 1.23", []],
+    ["price: €1.23", []],
 ])
 def test_sum_regex_value_first(haystack, expected_needles):
     matches = re.finditer(
@@ -131,3 +136,18 @@ def test_sum_regex_value_first(haystack, expected_needles):
         haystack,
     )
     assert expected_needles == [m.groupdict() for m in matches]
+
+
+@pytest.mark.parametrize(('haystack', 'expected_needles'), [
+    ["Preis: US$ 0,50", [{'currency': 'US$', 'value': '0,50'}]],
+    ["Preis: € 0,50", [{'currency': '€', 'value': '0,50'}]],
+    ["Preis: ¥1234", [{'currency': '¥', 'value': '1234'}]],
+    ["price: US$ 1.23", [{'currency': 'US$', 'value': '1.23'}]],
+    ["price: €1.23", [{'currency': '€', 'value': '1.23'}]],
+])
+def test_sum_regex_currency_first(haystack, expected_needles):
+    matches = re.finditer(
+        finoex.Sum.sum_regex_currency_first,
+        haystack,
+    )
+    assert expected_needles == [m.groupdict() for m in matches]