# Path: delphin/vpm.py
# _LR_OPS = set(['<>', '>>', '==', '=>'])
# _RL_OPS = set(['<>', '<<', '==', '<='])
# _SUBSUME_OPS = set(['<>', '<<', '>>'])
# _EQUAL_OPS = set(['==', '<=', '=>'])
# _ALL_OPS = _LR_OPS.union(_RL_OPS)
# class VPMSyntaxError(PyDelphinSyntaxError):
# class VPM(object):
# def load(source, semi=None):
# def _load(fh, semi):
#     def __init__(self, typemap, propmap, semi=None):
#     def apply(self, var, props, reverse=False):
# def _valmatch(vs, ss, op, varsort, semi, section):


from io import StringIO as S
from delphin import vpm
import pytest

    assert vpm.load(S('event <> e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event >> e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event << e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event == e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event => e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event <= e')).apply('e2', {}, reverse=True) == ('e2', {})

    assert vpm.load(S('* >> a')).apply('event2', {}) == ('a2', {})
    assert vpm.load(S('semarg << *')).apply('event2', {}) == ('event2', {})
    # assert vpm.load(S('semarg << *')).apply('a2', {}, reverse=True) == ('semarg2', {})
    assert vpm.load(S('semarg << *')).apply('a2', {}, reverse=True) == ('a2', {})


def test_type_map_multi_rule_no_semi():
    assert vpm.load(S('event <> e\nref-ind <> x')).apply('event2', {}) == ('e2', {})
    assert vpm.load(S('event <> e\nref-ind <> x')).apply('ref-ind4', {}) == ('x4', {})

    assert vpm.load(S('event >> e\nevent >> wrong')).apply('event2', {}) == ('e2', {})
    assert vpm.load(S('event >> e\ne >> wrong')).apply('event2', {}) == ('e2', {})
    assert vpm.load(S('event << wrong\nevent >> e')).apply('event2', {}) == ('e2', {})

    assert vpm.load(S('event >> e\nevent << u')).apply('event2', {}) == ('e2', {})
    # It turns out variable type mappings shouldn't apply in reverse..
    # assert vpm.load(S('event >> e\nevent << u')).apply('e2', {}, reverse=True) == ('e2', {})
    # assert vpm.load(S('event >> e\nevent << u')).apply('u2', {}, reverse=True) == ('event2', {})
    assert vpm.load(S('event >> e\nevent << u')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event >> e\nevent << u')).apply('u2', {}, reverse=True) == ('u2', {})

    assert vpm.load(S('* <> *\n* >> wrong\nwrong << *')).apply('a2', {}) == ('a2', {})

# Path: delphin/vpm.py
# _LR_OPS = set(['<>', '>>', '==', '=>'])
# _RL_OPS = set(['<>', '<<', '==', '<='])
# _SUBSUME_OPS = set(['<>', '<<', '>>'])
# _EQUAL_OPS = set(['==', '<=', '=>'])
# _ALL_OPS = _LR_OPS.union(_RL_OPS)
# class VPMSyntaxError(PyDelphinSyntaxError):
# class VPM(object):
# def load(source, semi=None):
# def _load(fh, semi):
#     def __init__(self, typemap, propmap, semi=None):
#     def apply(self, var, props, reverse=False):
# def _valmatch(vs, ss, op, varsort, semi, section):


# Path: tests/vpm_test.py
from io import StringIO as S
from delphin import vpm
import pytest


    assert vpm.load(S('event <> e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event >> e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event << e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event == e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event => e')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event <= e')).apply('e2', {}, reverse=True) == ('e2', {})

    assert vpm.load(S('* >> a')).apply('event2', {}) == ('a2', {})
    assert vpm.load(S('semarg << *')).apply('event2', {}) == ('event2', {})
    # assert vpm.load(S('semarg << *')).apply('a2', {}, reverse=True) == ('semarg2', {})
    assert vpm.load(S('semarg << *')).apply('a2', {}, reverse=True) == ('a2', {})


def test_type_map_multi_rule_no_semi():
    assert vpm.load(S('event <> e\nref-ind <> x')).apply('event2', {}) == ('e2', {})
    assert vpm.load(S('event <> e\nref-ind <> x')).apply('ref-ind4', {}) == ('x4', {})

    assert vpm.load(S('event >> e\nevent >> wrong')).apply('event2', {}) == ('e2', {})
    assert vpm.load(S('event >> e\ne >> wrong')).apply('event2', {}) == ('e2', {})
    assert vpm.load(S('event << wrong\nevent >> e')).apply('event2', {}) == ('e2', {})

    assert vpm.load(S('event >> e\nevent << u')).apply('event2', {}) == ('e2', {})
    # It turns out variable type mappings shouldn't apply in reverse..
    # assert vpm.load(S('event >> e\nevent << u')).apply('e2', {}, reverse=True) == ('e2', {})
    # assert vpm.load(S('event >> e\nevent << u')).apply('u2', {}, reverse=True) == ('event2', {})
    assert vpm.load(S('event >> e\nevent << u')).apply('e2', {}, reverse=True) == ('e2', {})
    assert vpm.load(S('event >> e\nevent << u')).apply('u2', {}, reverse=True) == ('u2', {})

    assert vpm.load(S('* <> *\n* >> wrong\nwrong << *')).apply('a2', {}) == ('a2', {})

    assert vpm.load(S('* <> *\n* >> wrong\nwrong << *')).apply('a2', {}, reverse=True) == ('a2', {})