Exemple #1
0
    def test_alphas(self):
        MAT = SourceString('hello world')
        MAT2 = SourceString('HEllo world')

        assert MAT.match_function_pattern(pat.alphal) == 'hello'
        assert MAT2.match_function_pattern(pat.alphau) == 'HE'
        assert MAT.match_function_pattern(pat.alpha) == 'hello'
Exemple #2
0
    def test_specials(self):
        MAT = SourceString('hello.world')
        MAT2 = SourceString('-1234')

        assert MAT.match_function_pattern(*pat.identifier) == 'hello'
        assert MAT.match_function_pattern(*pat.qualified) == 'hello.world'
        assert MAT2.match_function_pattern(*pat.integer) == '-1234'
Exemple #3
0
    def test_match_function_pattern(self):
        MAT = SourceString('Test100')

        assert MAT.match_function_pattern(str.isalpha) == 'Test'
        assert MAT.match_function_pattern(str.isalpha, str.isalnum) == 'Test100'
        assert MAT.match_function_pattern(str.isdigit) == ''

        assert MAT.match_function_pattern(lambda c: c == 'T' or c in 'te') == 'Te'
        lam = (lambda c: c == 'T', lambda c: c == 'e')
        assert MAT.match_function_pattern(*lam) == 'Te'
Exemple #4
0
 def test_match_function_pattern_imp(self, string):
     MAT = SourceString(string)
     alphas = 'abcdefghijklmnopqrstuvwxyz'
     expected = ''
     for char in string:
         if not char.islower():
             break
         expected += char
     assert MAT.match_function_pattern(str.islower) == expected
Exemple #5
0
    def test_numbers(self):
        MAT = SourceString('1234.5')
        MAT2 = SourceString('-1234.5')

        assert MAT.match_function_pattern(pat.number) == '1234'
        assert MAT2.match_function_pattern(pat.number) == ''