示例#1
0
def test_Term():
    q = Term(docstring='hi')
    assert q.docstring == 'hi'

    r = Regex('r*')
    s = String('s')
    t = TypeIdentifier('t')
    a = AVM()
    cl = ConsList()
    dl = DiffList()
    c = Coreference(None)
    assert isinstance(r, Term)
    assert isinstance(s, Term)
    assert isinstance(t, Term)
    assert isinstance(a, Term)
    assert isinstance(cl, Term)
    assert isinstance(dl, Term)
    assert isinstance(c, Term)
    assert isinstance(r & s, Conjunction)
    assert (r & s).terms == [r, s]
    assert isinstance(s & t, Conjunction)
    assert isinstance(t & a, Conjunction)
    assert isinstance(a & cl, Conjunction)
    assert isinstance(cl & dl, Conjunction)
    assert isinstance(dl & c, Conjunction)
    assert isinstance(c & r, Conjunction)
    assert isinstance((r & s) & t, Conjunction)
    assert ((r & s) & t).terms == [r, s, t]
    assert isinstance(r & (s & t), Conjunction)
    assert (r & (s & t)).terms == [r, s, t]
示例#2
0
def test_format_docstring_terms():
    assert tdl.format(TypeIdentifier('a',
                                     docstring='doc')) == '"""\ndoc\n"""\na'
    assert tdl.format(String('a', docstring='doc')) == '"""\ndoc\n"""\n"a"'
    assert tdl.format(Regex('a', docstring='doc')) == '"""\ndoc\n"""\n^a$'
    assert tdl.format(Coreference('a', docstring='doc')) == '"""\ndoc\n"""\n#a'
    assert tdl.format(AVM(docstring='doc')) == '"""\ndoc\n"""\n[ ]'
    assert tdl.format(ConsList(docstring='doc')) == '"""\ndoc\n"""\n< ... >'
    assert tdl.format(DiffList(docstring='doc')) == '"""\ndoc\n"""\n<! !>'
    # escape docstrings if necessary
    assert tdl.format(
        TypeIdentifier('a', docstring='"one" ""two"" """three""" """"""""')
    ) == '"""\n"one" ""two"" ""\\"three""\\" ""\\"""\\"""\n"""\na'
示例#3
0
def test_TypeIdentifier():
    with pytest.raises(TypeError):
        t = TypeIdentifier()
    t = TypeIdentifier('t')
    # case-insensitive comparision
    assert t == TypeIdentifier('t')
    assert t == TypeIdentifier('T')
    assert t != String('t')
    assert t != Regex('t')
    assert t == 't'
    assert t == 'T'

    t = TypeIdentifier('t2', docstring='doc')
    assert t == 't2'
    assert t == TypeIdentifier('t2', docstring='foo')
示例#4
0
def test_String():
    with pytest.raises(TypeError):
        t = String()

    t = String('s')
    # case-sensitive comparison
    assert t == String('s')
    assert t != String('S')
    assert t != TypeIdentifier('s')
    assert t != Regex('s')
    assert t == 's'
    assert t != 'S'

    t = String('s2', docstring='doc')
    assert t == 's2'
    assert t == String('s2', docstring='foo')
示例#5
0
def test_Regex():
    with pytest.raises(TypeError):
        t = Regex()

    t = Regex('r')
    # case-sensitive comparison
    assert t == Regex('r')
    assert t != Regex('R')
    assert t != TypeIdentifier('r')
    assert t != String('r')
    assert t == 'r'
    assert t != 'R'

    t = Regex('r2', docstring='doc')
    assert t == 'r2'
    assert t == Regex('r2', docstring='foo')
示例#6
0
def test_format_TypeTerms():
    assert tdl.format(TypeIdentifier('a-type')) == 'a-type'
    assert tdl.format(String('a string')) == '"a string"'
    assert tdl.format(Regex('a*re[g]ex')) == '^a*re[g]ex$'
    assert tdl.format(Coreference('coref')) == '#coref'