Skip to content

Commit

Permalink
Unicode characters now trigger needs_character
Browse files Browse the repository at this point in the history
  • Loading branch information
tiltowait committed Sep 23, 2023
1 parent fff0f1b commit 3ba6950
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion inconnu/vr/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ async def perform_roll(character: "VChar", syntax, max_hunger=5):

def needs_character(syntax: str):
"""Determines whether a roll needs a character."""
return re.search(r"[A-z_" + VCharTrait.DELIMITER + "]", syntax) is not None
if not syntax:
return False

return any(c.isalpha() or c in {"_", VCharTrait.DELIMITER} for c in syntax)


async def stringify_mentions(ctx, sentence):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_rollparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import inconnu.errors
from inconnu.models.vchar import VChar
from inconnu.vr.parse import needs_character
from inconnu.vr.rollparser import RollParser
from tests.characters import gen_char

Expand Down Expand Up @@ -137,3 +138,21 @@ def test_no_power_bonus(
p = RollParser(character, syntax, power_bonus=add_bonus)
assert p.pool_str == expected_str
assert p.pool == expected_dice


@pytest.mark.parametrize(
"syntax,needs",
[
("3", False),
("3 + 2", False),
("3 4 5", False),
("Strength", True),
("3 + Strength", True),
("Strength + Brawl hunger 3", True),
("ü", True),
("3 + .", True),
("3 + _", True),
],
)
def test_needs_character(syntax: str, needs: bool):
assert needs_character(syntax) == needs

0 comments on commit 3ba6950

Please sign in to comment.