MCPcopy Create free account
hub / github.com/python/cpython / test_sre_character_literals

Method test_sre_character_literals

Lib/test/test_re.py:1459–1489  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1457 self.assertTrue(re.compile(b'^pattern$', flag))
1458
1459 def test_sre_character_literals(self):
1460 for i in [0, 8, 16, 32, 64, 127, 128, 255, 256, 0xFFFF, 0x10000, 0x10FFFF]:
1461 if i < 256:
1462 self.assertTrue(re.match(r"\%03o" % i, chr(i)))
1463 self.assertTrue(re.match(r"\%03o0" % i, chr(i)+"0"))
1464 self.assertTrue(re.match(r"\%03o8" % i, chr(i)+"8"))
1465 self.assertTrue(re.match(r"\x%02x" % i, chr(i)))
1466 self.assertTrue(re.match(r"\x%02x0" % i, chr(i)+"0"))
1467 self.assertTrue(re.match(r"\x%02xz" % i, chr(i)+"z"))
1468 if i < 0x10000:
1469 self.assertTrue(re.match(r"\u%04x" % i, chr(i)))
1470 self.assertTrue(re.match(r"\u%04x0" % i, chr(i)+"0"))
1471 self.assertTrue(re.match(r"\u%04xz" % i, chr(i)+"z"))
1472 self.assertTrue(re.match(r"\U%08x" % i, chr(i)))
1473 self.assertTrue(re.match(r"\U%08x0" % i, chr(i)+"0"))
1474 self.assertTrue(re.match(r"\U%08xz" % i, chr(i)+"z"))
1475 self.assertTrue(re.match(r"\0", "\000"))
1476 self.assertTrue(re.match(r"\08", "\0008"))
1477 self.assertTrue(re.match(r"\01", "\001"))
1478 self.assertTrue(re.match(r"\018", "\0018"))
1479 self.checkPatternError(r"\567",
1480 r'octal escape value \567 outside of '
1481 r'range 0-0o377', 0)
1482 self.checkPatternError(r"\911", 'invalid group reference 91', 1)
1483 self.checkPatternError(r"\x1", r'incomplete escape \x1', 0)
1484 self.checkPatternError(r"\x1z", r'incomplete escape \x1', 0)
1485 self.checkPatternError(r"\u123", r'incomplete escape \u123', 0)
1486 self.checkPatternError(r"\u123z", r'incomplete escape \u123', 0)
1487 self.checkPatternError(r"\U0001234", r'incomplete escape \U0001234', 0)
1488 self.checkPatternError(r"\U0001234z", r'incomplete escape \U0001234', 0)
1489 self.checkPatternError(r"\U00110000", r'bad escape \U00110000', 0)
1490
1491 def test_sre_character_class_literals(self):
1492 for i in [0, 8, 16, 32, 64, 127, 128, 255, 256, 0xFFFF, 0x10000, 0x10FFFF]:

Callers

nothing calls this directly

Calls 3

checkPatternErrorMethod · 0.95
assertTrueMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected