# intensional / test / test.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91``` ```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() ```