Exemplo 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))
Exemplo 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())
Exemplo n.º 3
0
 def test_compile_error(self):
     try:
         RureSet(b"(")
     except RegexSyntaxError as err:
         self.assertIn("unclosed group", err.message.lower())
Exemplo n.º 4
0
 def test_set_len(self):
     res = RureSet(b"baz", b"bar", b"foo")
     self.assertEqual(len(res), 3)
Exemplo 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])
Exemplo 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))
Exemplo n.º 7
0
 def test_type_check(self):
     with self.assertRaises(TypeError):
         RureSet(b"baz", u"bar", b"foo")
Exemplo n.º 8
0
 def test_compile_error(self):
     try:
         RureSet(b"(")
     except RegexSyntaxError as err:
         self.assertIn("Unclosed parenthesis", err.message)