Beispiel #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')
Beispiel #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')
Beispiel #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"))
Beispiel #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')
Beispiel #11
0
def test_optional():
    assert regexp.match('^(foo)?$', '')
    assert regexp.match('^foo?$', 'fo')
Beispiel #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')
Beispiel #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')
Beispiel #14
0
def test_wildcard():
    assert regexp.match('.', 'a')
    assert regexp.match('.', '8')
    assert regexp.match('.', '\t')
    assert not regexp.match('.', '')
 def test_match_pos5(self):
     self.assertTrue(regexp.match(".$", "apple"))
 def test_match_pos6(self):
     self.assertTrue(regexp.match("apple$", "tasty apple"))
Beispiel #17
0
def test_union():
    assert regexp.match('^foo|bar$', 'bar')
    assert not regexp.match('^foo|bar$', 'foobar')
 def test_match_pos9(self):
     self.assertFalse(regexp.match("^apple$", "tasty apple"))
Beispiel #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)
 def test_match_pos12(self):
     self.assertFalse(regexp.match("^le", "apple"))
Beispiel #21
0
def test_begin_token():
    assert regexp.match('^foo', 'foobar')
    assert regexp.match('bar', 'foobar')
    assert not regexp.match('^bar', 'foobar')
 def test_match_quant3(self):
     self.assertFalse(regexp.match("colou?r", "colouur"))
Beispiel #23
0
def test_end_token():
    assert regexp.match('bar$', 'foobar')
    assert regexp.match('foo', 'foobar')
    assert not regexp.match('foo$', 'foobar')