Ejemplo n.º 1
0
    def test_flags(self):
        """Test whether we can set the flags correctly.

        In this case, we disable all flags, which includes disabling
        Unicode mode. When we disable Unicode mode, we can match
        arbitrary possibly invalid UTF-8 bytes, such as \xFF.
        (When Unicode mode is enabled, \xFF won't match .)
        """
        pattern = b"."
        haystack = b"\xFF"
        res = RureSet(pattern, flags=CASEI)
        self.assertTrue(res.is_match(haystack))
Ejemplo n.º 2
0
 def test_compile_error_size_limit(self):
     try:
         RureSet(b"\\w{100}", size_limit=0)
     except CompiledTooBigError as err:
         self.assertIn("exceeds size", err.message.lower())
Ejemplo n.º 3
0
 def test_compile_error(self):
     try:
         RureSet(b"(")
     except RegexSyntaxError as err:
         self.assertIn("unclosed group", err.message.lower())
Ejemplo n.º 4
0
 def test_set_len(self):
     res = RureSet(b"baz", b"bar", b"foo")
     self.assertEqual(len(res), 3)
Ejemplo n.º 5
0
 def test_matches(self):
     haystack = b"foobar"
     res = RureSet(b"baz", b"bar", b"foo")
     self.assertEqual(res.matches(haystack), [False, True, True])
Ejemplo n.º 6
0
 def test_is_match(self):
     haystack = b"snowman: \xE2\x98\x83"
     res = RureSet(b"\\p{So}")
     self.assertIsNotNone(res.is_match(haystack))
Ejemplo n.º 7
0
 def test_type_check(self):
     with self.assertRaises(TypeError):
         RureSet(b"baz", u"bar", b"foo")
Ejemplo n.º 8
0
 def test_compile_error(self):
     try:
         RureSet(b"(")
     except RegexSyntaxError as err:
         self.assertIn("Unclosed parenthesis", err.message)