Skip to content

Commit

Permalink
Added tests for using variable_name in patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
hbarthels committed Jul 20, 2020
1 parent 4354ba7 commit 4725bad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/common.py
Expand Up @@ -24,6 +24,7 @@ class SpecialSymbol(Symbol):
b = Symbol('b')
c = Symbol('c')
d = Symbol('d')
a_x = Symbol('a', variable_name='x')
s = SpecialSymbol('s')
_ = Wildcard.dot()
_s = Wildcard.symbol()
Expand Down
27 changes: 27 additions & 0 deletions tests/test_matching.py
Expand Up @@ -637,6 +637,33 @@ def test_mixed_associative_commutative_vars(self, match, expression, pattern, is
else:
assert len(result) == 0

@pytest.mark.parametrize(
' expression, pattern, expected_matches',
[
(a, a_x, [{'x': a}]),
(f(a), f(a_x), [{'x': a}]),
(f(b), f(a_x), []),
(f(a, b), f(a_x, b), [{'x': a}]),
(f(a), f(a, variable_name='x'), [{'x': f(a)}]),
(f2(a), f(a, variable_name='x'), []),
(f(a, b), f(a, b, variable_name='x'), [{'x': f(a, b)}]),
(f2(f(a)), f2(f(a, variable_name='x')), [{'x': f(a)}]),
(f2(f(a, b)), f2(f(a, b, variable_name='x')), [{'x': f(a, b)}]),
]
) # yapf: disable
def test_variable_name(self, match, expression, pattern, expected_matches):
expression = expression
pattern = Pattern(pattern)
result = list(match(expression, pattern))
for expected_match in expected_matches:
assert expected_match in result, "Expression {!s} and {!s} did not yield the match {!s} but were supposed to".format(
expression, pattern, expected_match
)
for result_match in result:
assert result_match in expected_matches, "Expression {!s} and {!s} yielded the unexpected match {!s}".format(
expression, pattern, result_match
)

@pytest.mark.parametrize(
' expression, pattern, expected_matches',
[
Expand Down

0 comments on commit 4725bad

Please sign in to comment.