示例#1
0
def test_Matcher_match_returns_False_on_ParseException():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            raise ParseException(None, None, None)

    m = Matcher("foo")
    assert not m.match(DummyPyparsingThingy())
示例#2
0
def test_Matcher_match_returns_True_when_no_raise():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            pass

    m = Matcher("foo")
    assert m.match(DummyPyparsingThingy())
示例#3
0
def test_Matcher_passes_same_argument_to_matches():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            assert obj is sentinel
    sentinel = object()
    m = Matcher(sentinel)
    m.match(DummyPyparsingThingy())
示例#4
0
def test_Matcher_passes_same_argument_to_matches():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            assert obj is sentinel

    sentinel = object()
    m = Matcher(sentinel)
    m.match(DummyPyparsingThingy())
示例#5
0
def test_Matcher_match_sets_result_on_success():
    sentinel = object()
    class DummyPyparsingThingy:
        def parseString(self, obj):
            return sentinel
    m = Matcher("foo")
    m.match(DummyPyparsingThingy())
    assert m.results is sentinel
示例#6
0
def deafDistributor(actor, rest, lineinfo):
    matcher = Matcher(rest.lower())

    if matcher.match(on_pattern):
        deafOn(actor)
    elif matcher.match(off_pattern):
        deafOff(actor)
    else:
        badSyntax(actor, syntaxmessage)
示例#7
0
def test_Matcher_match_doesnt_touch_results_on_failure():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            raise ParseException(None, None, None)
    sentinel = object()
    m = Matcher("foo")
    m.results = sentinel
    m.match(DummyPyparsingThingy())
    assert m.results is sentinel
示例#8
0
文件: deaf.py 项目: ViKingIX/grailmud
def deafDistributor(actor, rest, lineinfo):
    matcher = Matcher(rest.lower())
    
    if matcher.match(on_pattern):
        deafOn(actor)
    elif matcher.match(off_pattern):
        deafOff(actor)
    else:
        badSyntax(actor, syntaxmessage)
示例#9
0
def test_Matcher_match_doesnt_touch_results_on_failure():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            raise ParseException(None, None, None)

    sentinel = object()
    m = Matcher("foo")
    m.results = sentinel
    m.match(DummyPyparsingThingy())
    assert m.results is sentinel
示例#10
0
def test_Matcher_match_sets_result_on_success():
    sentinel = object()

    class DummyPyparsingThingy:
        def parseString(self, obj):
            return sentinel

    m = Matcher("foo")
    m.match(DummyPyparsingThingy())
    assert m.results is sentinel
示例#11
0
def lookDistributor(actor, text, info):
    matcher = Matcher(text)

    if matcher.match(lookAtPattern):
        blob, = matcher.results
        try:
            target = get_from_rooms(blob, [actor.inventory, actor.room], info)
        except UnfoundError:
            unfoundObject(actor)
        else:
            lookAt(actor, target)
    else:
        lookRoom(actor)
示例#12
0
文件: look.py 项目: ViKingIX/grailmud
def lookDistributor(actor, text, info):
    matcher = Matcher(text)

    if matcher.match(lookAtPattern):
        blob, = matcher.results
        try:
            target = get_from_rooms(blob, [actor.inventory, actor.room], info)
        except UnfoundError:
            unfoundObject(actor)
        else:
            lookAt(actor, target)
    else:
        lookRoom(actor)
示例#13
0
文件: says.py 项目: ViKingIX/grailmud
def speakToWrapper(actor, text, info):
    matcher = Matcher(text)

    if matcher.match(speakToPattern):
        blob, saying = matcher.results
        try:
            target = get_from_rooms(blob, [actor.inventory, actor.room], info)
        except UnfoundError:
            unfoundObject(actor)
        else:
            speakTo(actor, target, saying)
    else:
        badSyntax(actor, "Can't find the end of the target identifier. Use "
                         "',' at its end to specify it.")
示例#14
0
def speakToWrapper(actor, text, info):
    matcher = Matcher(text)

    if matcher.match(speakToPattern):
        blob, saying = matcher.results
        try:
            target = get_from_rooms(blob, [actor.inventory, actor.room], info)
        except UnfoundError:
            unfoundObject(actor)
        else:
            speakTo(actor, target, saying)
    else:
        badSyntax(
            actor, "Can't find the end of the target identifier. Use "
            "',' at its end to specify it.")
示例#15
0
def targetDistributor(actor, text, info):
    if info.instigator is not actor:
        permissionDenied(info.instigator)
        return

    matcher = Matcher(text)

    if matcher.match(target_set_pattern):
        (name, ), blob = matcher.results
        try:
            target = get_from_rooms(blob, [actor.inventory, actor.room], info)
        except UnfoundError:
            unfoundObject(actor)
        else:
            targetSet(actor, name.lower(), target)
    elif matcher.match(target_clear_pattern):
        (name, ), = matcher.results
        targetClear(actor, name.lower())
    elif matcher.match(target_list_pattern):
        targetList(actor)
    else:
        badSyntax(actor)
示例#16
0
def targetDistributor(actor, text, info):
    if info.instigator is not actor:
        permissionDenied(info.instigator)
        return

    matcher = Matcher(text)

    if matcher.match(target_set_pattern):
        (name,), blob = matcher.results
        try:
            target = get_from_rooms(blob, [actor.inventory, actor.room], info)
        except UnfoundError:
            unfoundObject(actor)
        else:
            targetSet(actor, name.lower(), target)
    elif matcher.match(target_clear_pattern):
        (name,), = matcher.results
        targetClear(actor, name.lower())
    elif matcher.match(target_list_pattern):
        targetList(actor)
    else:
        badSyntax(actor)
示例#17
0
def test_Matcher_match_returns_False_on_ParseException():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            raise ParseException(None, None, None)
    m = Matcher("foo")
    assert not m.match(DummyPyparsingThingy())
示例#18
0
def test_Matcher_results_is_None_default():
    assert Matcher('').results is None
示例#19
0
def test_Matcher_match_returns_True_when_no_raise():
    class DummyPyparsingThingy:
        def parseString(self, obj):
            pass
    m = Matcher("foo")
    assert m.match(DummyPyparsingThingy())