Fix operator precedence in POV smart conjugation

The {s} conjugation check had incorrect operator precedence that
evaluated the ch/sh suffix check independently of the prev_text
existence check. This could lead to confusing logic flow even
though it didn't crash due to len() handling empty strings safely.

Fixed by wrapping both suffix conditions in parentheses so they're
both guarded by the prev_text truthiness check.
This commit is contained in:
Jared Miller 2026-02-13 23:53:42 -05:00
parent afe99ceff5
commit 2a546a3171
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 31 additions and 3 deletions

View file

@ -66,9 +66,8 @@ def render_pov(
else: else:
# Check previous character for smart conjugation # Check previous character for smart conjugation
prev_text = "".join(result) prev_text = "".join(result)
if ( if prev_text and (
prev_text prev_text[-1:] in "sxz"
and prev_text[-1:] in "sxz"
or (len(prev_text) >= 2 and prev_text[-2:] in ("ch", "sh")) or (len(prev_text) >= 2 and prev_text[-2:] in ("ch", "sh"))
): ):
result.append("es") result.append("es")

View file

@ -191,3 +191,32 @@ def test_you_capitalized_after_comma(jared, goku):
template = "{attacker} strikes, and {defender} fall{s}" template = "{attacker} strikes, and {defender} fall{s}"
result = render_pov(template, viewer=goku, attacker=jared, defender=goku) result = render_pov(template, viewer=goku, attacker=jared, defender=goku)
assert result == "Jared strikes, and You fall" assert result == "Jared strikes, and You fall"
def test_s_conjugation_after_ch(jared, goku, vegeta):
"""{s} after 'ch' should add 'es' for third person."""
template = "{attacker} punch{s} {defender}"
result = render_pov(template, viewer=vegeta, attacker=jared, defender=goku)
assert result == "Jared punches Goku"
def test_s_conjugation_after_sh(jared, goku, vegeta):
"""{s} after 'sh' should add 'es' for third person."""
template = "{attacker} smash{s} into {defender}"
result = render_pov(template, viewer=vegeta, attacker=jared, defender=goku)
assert result == "Jared smashes into Goku"
def test_s_conjugation_you_after_ch(jared, goku):
"""{s} should not add suffix for 'You' regardless of word ending."""
template = "{attacker} punch{s} {defender}"
result = render_pov(template, viewer=jared, attacker=jared, defender=goku)
assert result == "You punch Goku"
def test_s_conjugation_at_template_start():
"""{s} at start of template should not crash when checking prev_text."""
template = "{s}test"
result = render_pov(template, viewer=None, attacker=None, defender=None)
# Without entity, last_was_you defaults to False, so should add 's'
assert result == "stest"