コード例 #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))
コード例 #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())
コード例 #3
0
 def test_compile_error(self):
     try:
         RureSet(b"(")
     except RegexSyntaxError as err:
         self.assertIn("unclosed group", err.message.lower())
コード例 #4
0
 def test_set_len(self):
     res = RureSet(b"baz", b"bar", b"foo")
     self.assertEqual(len(res), 3)
コード例 #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])
コード例 #6
0
 def test_is_match(self):
     haystack = b"snowman: \xE2\x98\x83"
     res = RureSet(b"\\p{So}")
     self.assertIsNotNone(res.is_match(haystack))
コード例 #7
0
 def test_type_check(self):
     with self.assertRaises(TypeError):
         RureSet(b"baz", u"bar", b"foo")
コード例 #8
0
 def test_compile_error(self):
     try:
         RureSet(b"(")
     except RegexSyntaxError as err:
         self.assertIn("Unclosed parenthesis", err.message)