Skip to content

Commit 8af568b

Browse files
committed
Added convert_unicode_dashes utility and its corresponding tests
1 parent bb90cb4 commit 8af568b

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
from ..utility.expression_utilities import convert_unicode_dashes
3+
4+
5+
class TestConvertUnicodeDashes:
6+
7+
@pytest.mark.parametrize(
8+
"expr, expected",
9+
[
10+
# No dashes at all
11+
("x+y", []),
12+
# ASCII hyphen-minus is not a unicode dash — no substitution
13+
("x-y", []),
14+
# Empty string
15+
("", []),
16+
# HYPHEN (U+2010)
17+
("x‐y", [("‐", "-")]),
18+
# NON-BREAKING HYPHEN (U+2011)
19+
("x‑y", [("‑", "-")]),
20+
# FIGURE DASH (U+2012)
21+
("x‒y", [("‒", "-")]),
22+
# EN DASH (U+2013)
23+
("x–y", [("–", "-")]),
24+
# EM DASH (U+2014)
25+
("x—y", [("—", "-")]),
26+
# MINUS SIGN (U+2212)
27+
("x−y", [("−", "-")]),
28+
# SMALL HYPHEN-MINUS (U+FE63)
29+
("x﹣y", [("﹣", "-")]),
30+
# FULLWIDTH HYPHEN-MINUS (U+FF0D)
31+
("x-y", [("-", "-")]),
32+
# Multiple different unicode dashes in one expression
33+
("x–y−z", [("–", "-"), ("−", "-")]),
34+
# Repeated occurrences of the same dash — still one substitution pair
35+
("x−y−z", [("−", "-")]),
36+
]
37+
)
38+
def test_convert_unicode_dashes(self, expr, expected):
39+
result = convert_unicode_dashes(expr)
40+
assert result == expected

app/utility/expression_utilities.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ def transform_unicode_greek_symbols(expr):
290290
alias_substitutions += [(alias, " "+name+" ")]
291291
return alias_substitutions
292292

293+
def convert_unicode_dashes(expr):
294+
unicode_dashes = [
295+
"‐", # HYPHEN
296+
"‑", # NON-BREAKING HYPHEN
297+
"‒", # FIGURE DASH
298+
"–", # EN DASH
299+
"—", # EM DASH
300+
"−", # MINUS SIGN
301+
"﹣", # SMALL HYPHEN-MINUS
302+
"-", # FULLWIDTH HYPHEN-MINUS
303+
]
304+
return [(dash, "-") for dash in unicode_dashes if dash in expr]
305+
306+
293307
def protect_elementary_functions_substitutions(expr):
294308
alias_substitutions = []
295309
for (name, alias_list) in elementary_functions_names:

0 commit comments

Comments
 (0)