MCPcopy Index your code
hub / github.com/python/cpython / test_named_unicode_escapes

Method test_named_unicode_escapes

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

Source from the content-addressed store, hash-verified

861 self.assertRaises(re.PatternError, re.compile, '[\\%c]' % c)
862
863 def test_named_unicode_escapes(self):
864 # test individual Unicode named escapes
865 self.assertTrue(re.match(r'\N{LESS-THAN SIGN}', '<'))
866 self.assertTrue(re.match(r'\N{less-than sign}', '<'))
867 self.assertIsNone(re.match(r'\N{LESS-THAN SIGN}', '>'))
868 self.assertTrue(re.match(r'\N{SNAKE}', '\U0001f40d'))
869 self.assertTrue(re.match(r'\N{ARABIC LIGATURE UIGHUR KIRGHIZ YEH WITH '
870 r'HAMZA ABOVE WITH ALEF MAKSURA ISOLATED FORM}',
871 '\ufbf9'))
872 self.assertTrue(re.match(r'[\N{LESS-THAN SIGN}-\N{GREATER-THAN SIGN}]',
873 '='))
874 self.assertIsNone(re.match(r'[\N{LESS-THAN SIGN}-\N{GREATER-THAN SIGN}]',
875 ';'))
876
877 # test errors in \N{name} handling - only valid names should pass
878 self.checkPatternError(r'\N', 'missing {', 2)
879 self.checkPatternError(r'[\N]', 'missing {', 3)
880 self.checkPatternError(r'\N{', 'missing character name', 3)
881 self.checkPatternError(r'[\N{', 'missing character name', 4)
882 self.checkPatternError(r'\N{}', 'missing character name', 3)
883 self.checkPatternError(r'[\N{}]', 'missing character name', 4)
884 self.checkPatternError(r'\NSNAKE}', 'missing {', 2)
885 self.checkPatternError(r'[\NSNAKE}]', 'missing {', 3)
886 self.checkPatternError(r'\N{SNAKE',
887 'missing }, unterminated name', 3)
888 self.checkPatternError(r'[\N{SNAKE]',
889 'missing }, unterminated name', 4)
890 self.checkPatternError(r'[\N{SNAKE]}',
891 "undefined character name 'SNAKE]'", 1)
892 self.checkPatternError(r'\N{SPAM}',
893 "undefined character name 'SPAM'", 0)
894 self.checkPatternError(r'[\N{SPAM}]',
895 "undefined character name 'SPAM'", 1)
896 self.checkPatternError(r'\N{KEYCAP NUMBER SIGN}',
897 "undefined character name 'KEYCAP NUMBER SIGN'", 0)
898 self.checkPatternError(r'[\N{KEYCAP NUMBER SIGN}]',
899 "undefined character name 'KEYCAP NUMBER SIGN'", 1)
900 self.checkPatternError(br'\N{LESS-THAN SIGN}', r'bad escape \N', 0)
901 self.checkPatternError(br'[\N{LESS-THAN SIGN}]', r'bad escape \N', 1)
902
903 def test_word_boundaries(self):
904 # See http://bugs.python.org/issue10713

Callers

nothing calls this directly

Calls 4

checkPatternErrorMethod · 0.95
assertTrueMethod · 0.80
assertIsNoneMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected