Skip to content

Commit dbde7a7

Browse files
committed
Add other test cases of string containing money amount
1 parent f5563c8 commit dbde7a7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

test/regex_test.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,19 @@ def test_money(data, expected):
233233
]))
234234
assert expected == bool(re.match(money_regex, data))
235235

236-
def test_string_contains_money():
236+
STRING_MONEY_REGEX_TEST_CASES = [
237+
("billed amount of $", False),
238+
("billed amount of $0.50", True),
239+
("billed amount of $123.50", True),
240+
("billed amount of $123", True),
241+
("billed amount of $123,456", True),
242+
("billed amount of $123,456,789", True),
243+
("billed amount of $123,456,789.50", True),
244+
("billed amount of $123.", True),
245+
("billed amount of $123,456,789.", True),
246+
]
247+
@pytest.mark.parametrize("data, expected", STRING_MONEY_REGEX_TEST_CASES)
248+
def test_string_contains_money(data, expected):
237249
money_regex = re.compile('|'.join([
238250
r'\b\$?(\d*\.\d{1,2})', # e.g., $.50, .50, $1.50, $.5, .5
239251
r'\b\$?(\d+)', # e.g., $500, $5, 500, 5
@@ -242,9 +254,8 @@ def test_string_contains_money():
242254
r'\b\$?(\d{1,3},\d{3})*\.?', # e.g., $123,456.5, $1,234, $12,345
243255
r'\b\$?(\d{1,3},\d{3})*\.\d{1,2}', # e.g., $123,456.5, $1,234, $12,345
244256
]))
245-
str = "billed amount of $52,221,646.74."
246-
result = re.findall(money_regex, str)#.groups()
257+
result = re.findall(money_regex, data)
247258
#print(f"test_money result: {result}")
248259
assert result
249260
assert result[0]
250-
assert re.match(money_regex, str)
261+
assert re.match(money_regex, data)

0 commit comments

Comments
 (0)