Esempio n. 1
0
def test_charclass():
    assert regexp.match('[a-zA-Z0-9]', 'a')
    assert regexp.match('[a-zA-Z0-9]', 'A')
    assert regexp.match('[a-zA-Z0-9]', '0')
    assert not regexp.match('[a-zA-Z0-9]', '.')

    assert regexp.match('[abc]', 'a')
    assert not regexp.match('[abc]', 'd')
    assert not regexp.match('[.]', 'a')
Esempio n. 2
0
def test_charclass_complement():
    assert not regexp.match('[^a-zA-Z0-9]', 'a')
    assert not regexp.match('[^a-zA-Z0-9]', 'A')
    assert not regexp.match('[^a-zA-Z0-9]', '0')
    assert regexp.match('[^a-zA-Z0-9]', '.')

    assert not regexp.match('[^abc]', 'a')
    assert regexp.match('[^abc]', 'd')
    assert regexp.match('[^.]', 'a')
Esempio n. 3
0
def test_escaped():
    assert regexp.match('\\.', '.')
    assert regexp.match('\\\\', '\\')
    assert regexp.match('\\.', '.')
    assert regexp.match('\\t', '\t')
    assert not regexp.match('\\\\n', '\n')
    assert not regexp.match('\\.', 'a')
 def test_match_quant11(self):
     self.assertFalse(regexp.match("col.*r$", "colors"))
 def test_match_quant10(self):
     self.assertTrue(regexp.match("col.*r", "collar"))
 def test_match_quant6(self):
     self.assertTrue(regexp.match("colou*r", "colouur"))
 def test_match_quant2(self):
     self.assertTrue(regexp.match("colou?r", "colour"))
 def test_match_pos10(self):
     self.assertFalse(regexp.match("^apple$", "apple pie"))
 def test_match_pos8(self):
     self.assertTrue(regexp.match("^apple$", "apple"))
Esempio n. 10
0
def test_concatenation():
    assert regexp.match('^a+b+$', 'aaabbb')
    assert not regexp.match('^a+b+$', 'abab')
    assert not regexp.match('^a+b+$', 'aaaa')
Esempio n. 11
0
def test_optional():
    assert regexp.match('^(foo)?$', '')
    assert regexp.match('^foo?$', 'fo')
Esempio n. 12
0
def test_plus():
    assert regexp.match('^a+$', 'aaaaaaaa')
    assert regexp.match('^(foo)+$', 'foofoofoo')
    assert not regexp.match('^a+$', '')
    assert not regexp.match('^a+$', 'bbbb')
Esempio n. 13
0
def test_star():
    assert regexp.match('^a*$', '')
    assert regexp.match('^a*$', 'aaaaaaaa')
    assert regexp.match('^(foo)*$', 'foofoofoo')
    assert not regexp.match('^a*$', 'bbbb')
Esempio n. 14
0
def test_wildcard():
    assert regexp.match('.', 'a')
    assert regexp.match('.', '8')
    assert regexp.match('.', '\t')
    assert not regexp.match('.', '')
Esempio n. 15
0
 def test_match_pos5(self):
     self.assertTrue(regexp.match(".$", "apple"))
Esempio n. 16
0
 def test_match_pos6(self):
     self.assertTrue(regexp.match("apple$", "tasty apple"))
Esempio n. 17
0
def test_union():
    assert regexp.match('^foo|bar$', 'bar')
    assert not regexp.match('^foo|bar$', 'foobar')
Esempio n. 18
0
 def test_match_pos9(self):
     self.assertFalse(regexp.match("^apple$", "tasty apple"))
Esempio n. 19
0
def test_repetition():
    assert regexp.match('^(ab){5}$', 'ab' * 5)
    assert not regexp.match('^(ab){5}$', 'ab' * 4)
    assert not regexp.match('^(ab){5}$', 'ab' * 6)

    assert regexp.match('^(ab){5,}$', 'ab' * 5)
    assert regexp.match('^(ab){5,}$', 'ab' * 6)
    assert not regexp.match('^(ab){5,}$', 'ab' * 4)

    assert regexp.match('^(ab){,5}$', 'ab' * 5)
    assert regexp.match('^(ab){,5}$', 'ab' * 4)
    assert not regexp.match('^(ab){,5}$', 'ab' * 6)

    assert regexp.match('^(ab){4,5}$', 'ab' * 4)
    assert regexp.match('^(ab){4,5}$', 'ab' * 5)
    assert not regexp.match('^(ab){4,5}$', 'ab' * 3)
    assert not regexp.match('^(ab){4,5}$', 'ab' * 6)
Esempio n. 20
0
 def test_match_pos12(self):
     self.assertFalse(regexp.match("^le", "apple"))
Esempio n. 21
0
def test_begin_token():
    assert regexp.match('^foo', 'foobar')
    assert regexp.match('bar', 'foobar')
    assert not regexp.match('^bar', 'foobar')
Esempio n. 22
0
 def test_match_quant3(self):
     self.assertFalse(regexp.match("colou?r", "colouur"))
Esempio n. 23
0
def test_end_token():
    assert regexp.match('bar$', 'foobar')
    assert regexp.match('foo', 'foobar')
    assert not regexp.match('foo$', 'foobar')