mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Add tests for verb conjugation
This commit is contained in:
parent
24a6d2cfab
commit
adb370b1d3
4 changed files with 46 additions and 9 deletions
|
|
@ -40,9 +40,11 @@ The `FuncParser` also accepts a direct dict mapping of `{'name': callable, ...}`
|
|||
|
||||
|
||||
"""
|
||||
import re
|
||||
import dataclasses
|
||||
import inspect
|
||||
import random
|
||||
from functools import partial
|
||||
from django.conf import settings
|
||||
from ast import literal_eval
|
||||
from simpleeval import simple_eval
|
||||
|
|
@ -50,6 +52,7 @@ from evennia.utils import logger
|
|||
from evennia.utils.utils import (
|
||||
make_iter, callables_from_module, variable_from_module, pad, crop, justify)
|
||||
from evennia.utils import search
|
||||
from evennia.utils.verb_conjugation.conjugate import verb_actor_stance_components
|
||||
|
||||
_CLIENT_DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
|
||||
_MAX_NESTING = 20
|
||||
|
|
@ -520,8 +523,9 @@ class FuncParser:
|
|||
# return explicit return
|
||||
return exec_return
|
||||
|
||||
# add the last bit to the finished string and return
|
||||
# add the last bit to the finished string
|
||||
fullstr += infuncstr
|
||||
|
||||
return fullstr
|
||||
|
||||
def parse_to_any(self, string, raise_errors=False, **reserved_kwargs):
|
||||
|
|
@ -1116,10 +1120,13 @@ def funcparser_callable_conjugate(*args, you_obj=None, you_target=None, **kwargs
|
|||
Others will see "With a grin, CharName jumps."
|
||||
|
||||
"""
|
||||
|
||||
if not args:
|
||||
return ''
|
||||
if not (you_obj and you_target):
|
||||
raise ParsingError("No you_obj/target supplied to $conj callable")
|
||||
return ''
|
||||
|
||||
you_str, them_str = verb_actor_stance_components(args[0])
|
||||
return you_str if you_obj == you_target else them_str
|
||||
|
||||
|
||||
# these are made available as callables by adding 'evennia.utils.funcparser' as
|
||||
|
|
@ -1163,4 +1170,5 @@ FUNCPARSER_CALLABLES = {
|
|||
# referencing
|
||||
"you": funcparser_callable_you,
|
||||
"You": funcparser_callable_You,
|
||||
"conj": funcparser_callable_conjugate,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -267,6 +267,14 @@ class TestFuncParser(TestCase):
|
|||
ret = parser.parse("This is a $foo(foo=moo) string", foo="bar")
|
||||
self.assertEqual("This is a _test(test=foo, foo=bar) string", ret)
|
||||
|
||||
class _DummyObj:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def get_display_name(self, looker=None):
|
||||
return self.name
|
||||
|
||||
|
||||
class TestDefaultCallables(TestCase):
|
||||
"""
|
||||
Test default callables.
|
||||
|
|
@ -276,9 +284,11 @@ class TestDefaultCallables(TestCase):
|
|||
def setUp(self):
|
||||
from django.conf import settings
|
||||
self.parser = funcparser.FuncParser(settings.INLINEFUNC_MODULES)
|
||||
self.obj1 = _DummyObj("Char1")
|
||||
self.obj2 = _DummyObj("Char2")
|
||||
|
||||
@parameterized.expand([
|
||||
("Test py1 $py('')", "Test py1 ''"),
|
||||
("Test py1 $eval('')", "Test py1 "),
|
||||
])
|
||||
def test_callable(self, string, expected):
|
||||
"""
|
||||
|
|
@ -288,6 +298,21 @@ class TestDefaultCallables(TestCase):
|
|||
ret = self.parser.parse(string, raise_errors=True)
|
||||
self.assertEqual(expected, ret)
|
||||
|
||||
@parameterized.expand([
|
||||
("$You() $conj(smile) at him.", "You smile at him.", "Char1 smiles at him."),
|
||||
])
|
||||
def test_conjugate(self, string, expected_you, expected_them):
|
||||
"""
|
||||
Test callables with various input strings
|
||||
|
||||
"""
|
||||
ret = self.parser.parse(string, you_obj=self.obj1, you_target=self.obj1,
|
||||
raise_errors=True)
|
||||
self.assertEqual(expected_you, ret)
|
||||
ret = self.parser.parse(string, you_obj=self.obj1, you_target=self.obj2,
|
||||
raise_errors=True)
|
||||
self.assertEqual(expected_them, ret)
|
||||
|
||||
|
||||
class TestOldDefaultCallables(TestCase):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -322,7 +322,6 @@ def verb_is_present_participle(verb):
|
|||
return tense == "present participle"
|
||||
|
||||
|
||||
|
||||
def verb_is_past(verb, person="", negated=False):
|
||||
"""
|
||||
Checks whether the verb is in the past tense.
|
||||
|
|
@ -380,8 +379,9 @@ def verb_actor_stance_components(verb):
|
|||
if "participle" in tense or "plural" in tense:
|
||||
return (verb, verb)
|
||||
if tense == "infinitive" or "present" in tense:
|
||||
return (verb_present(verb, person="2"),
|
||||
verb_present(verb, person="3"))
|
||||
you_str = verb_present(verb, person="2") or verb
|
||||
them_str = verb_present(verb, person="3") or verb + "s"
|
||||
else:
|
||||
return (verb_past(verb, person="2"),
|
||||
verb_past(verb, person="3"))
|
||||
you_str = verb_past(verb, person="2") or verb
|
||||
them_str = verb_past(verb, person="3") or verb + "s"
|
||||
return (you_str, them_str)
|
||||
|
|
|
|||
|
|
@ -228,6 +228,10 @@ class TestVerbConjugate(TestCase):
|
|||
("doing", ("doing", "doing")),
|
||||
("are", ("are", "is")),
|
||||
("had", ("had", "had")),
|
||||
("grin", ("grin", "grins")),
|
||||
("smile", ("smile", "smiles")),
|
||||
("vex", ("vex", "vexes")),
|
||||
("thrust", ("thrust", "thrusts")),
|
||||
])
|
||||
def test_verb_actor_stance_components(self, verb, expected):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue