From 2a546a317136a5084072e7ee322617436470dc1a Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Fri, 13 Feb 2026 23:53:42 -0500 Subject: [PATCH] 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. --- src/mudlib/render/pov.py | 5 ++--- tests/test_pov.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/mudlib/render/pov.py b/src/mudlib/render/pov.py index 00bc687..b964cbd 100644 --- a/src/mudlib/render/pov.py +++ b/src/mudlib/render/pov.py @@ -66,9 +66,8 @@ def render_pov( else: # Check previous character for smart conjugation prev_text = "".join(result) - if ( - prev_text - and prev_text[-1:] in "sxz" + if prev_text and ( + prev_text[-1:] in "sxz" or (len(prev_text) >= 2 and prev_text[-2:] in ("ch", "sh")) ): result.append("es") diff --git a/tests/test_pov.py b/tests/test_pov.py index e0200ee..7d4024d 100644 --- a/tests/test_pov.py +++ b/tests/test_pov.py @@ -191,3 +191,32 @@ def test_you_capitalized_after_comma(jared, goku): template = "{attacker} strikes, and {defender} fall{s}" result = render_pov(template, viewer=goku, attacker=jared, defender=goku) 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"