Skip to content

Commit

Permalink
Merge pull request #20 from junghoon-vans/fix/resolve-error-that-cann…
Browse files Browse the repository at this point in the history
…ot-find-variable-name-with-whitespace

fix: Resolve error that cannot find variable name with whitespace
  • Loading branch information
junghoon-vans authored Nov 24, 2022
2 parents abb4532 + 4517025 commit b45e502
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
3 changes: 2 additions & 1 deletion tests/data/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Substitution Test
=================

replace: |status|
replace: |status|, with space: |with whitespace|

.. |status| replace:: false
.. |with whitespace| replace:: false
9 changes: 6 additions & 3 deletions tests/utils/test_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ def substitution() -> Substitution:


def test_find_substitution(substitution: Substitution):
content = substitution.find("status")
print(content)
none_whitespace = substitution.find("status")
with_whitespace = substitution.find("with whitespace")

print(none_whitespace)
print(with_whitespace)

with pytest.raises(KeyError):
substitution.find("state")
substitution.find("not exist name")


def test_create_substitution():
Expand Down
10 changes: 2 additions & 8 deletions varst/utils/substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ def find(self, name) -> str:
KeyError: If substitution is not in file.
"""
pattern = re.compile(
fr"""
\.\.[ ]+ # explicit markup start
\| # substitution indicator
({name})\| # substitution name
""", re.VERBOSE,
)
pattern = fr"""\.\.[ ]+\|({name})\|"""

for content in self.rst_file.contents:
if pattern.match(content):
if re.match(pattern, content):
return content
raise KeyError(name)

Expand Down

0 comments on commit b45e502

Please sign in to comment.