Source

intensional / test / test.py

Full commit
from testharness import import_from_parent, test_run

import_from_parent()
from intensional import *

def test_Re():
    tests = 'some string with things in it ok?'
    testpat = Re(r'\b(s\w*)\b')
    testpat1 = Re(r'\b(s\w*)\b')
    assert testpat is testpat1   # test memoization
    if tests in testpat:
        print _[1]
        assert _[1] == 'some'
        assert _._match.end(1) == 4
    
    found = testpat.findall(tests)
    assert found == ['some', 'string']
    
def test_Any():
    ext = Any(1,2,3)
    assert 2 in ext
    assert 33 not in ext
    print ext
    a2 = Any(12, Test('x.startswith("k")'))
    assert 12 in a2
    assert "kaboom" in a2
    assert "laboom" not in a2
    assert 33 not in a2
    
def test_Every():
    e = Every(1)
    assert 1 in e
    assert 4 not in e
    e2 = Every(Test('x > 12'), Test('x > 33'))
    assert 44 in e2
    assert 55 in e2
    assert 0 not in e2
    assert 18 not in e2
    
    e3 = Every(Test('x.startswith("r")'), Test('len(x) <= 5'))
    
    assert 'roger' in e3
    assert 'roof'  in e3
    assert 'roofer' not in e3
    
    # diffent way of stating e3
    e3a = Every(Test('x.startswith("r") and len(x) <= 5'))

    assert 'roger' in e3a
    assert 'roof'  in e3a
    assert 'roofer' not in e3a

    # yet another way of stating e3
    e3b = Test('x.startswith("r") and len(x) <= 5')

    assert 'roger' in e3b
    assert 'roof'  in e3b
    assert 'roofer' not in e3b
    
    # any way to link to Python all and any?

def test_ButNot():

    a2 = Any(12, Test('x.startswith("k")'))
    assert 12 in a2
    assert "kaboom" in a2
    assert "laboom" not in a2
    assert 33 not in a2
    
    bn = ButNot(a2, Any(12, 'kookoo'))
    assert 'kookoo' in a2
    assert 'kookoo' not in bn
    assert 'kaboom' in bn
    assert 'laboom' not in bn
    assert 12 in a2
    assert 12 not in bn
    
def test_Glob():
    assert "alpha" in Glob("a*")
    assert "beta" not in Glob("a*")
    
def test_Test():
    mytest = Test('x.startswith("a")')
    print mytest
    assert 'a' in mytest
    assert 'alpha' in mytest
    assert 'sljd' not in mytest
    
    
if __name__ == '__main__':
    test_run()