コード例 #1
0
ファイル: test-xmlre.py プロジェクト: gothub/pyxb-d1
 def testMatchCharClassExpr (self):
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchCharClassExpr, 'missing open', 0)
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchCharClassExpr, '[missing close', 0)
     first_five = unicode.CodePointSet( (ord('A'), ord('E')) )
     text = r'[ABCDE]'
     (charset, position) = xmlre._MatchCharClassExpr(text, 0)
     self.assertEqual(position, len(text))
     self.assertEqual(charset, first_five)
     text = r'[^ABCDE]'
     (charset, position) = xmlre._MatchCharClassExpr(text, 0)
     self.assertEqual(position, len(text))
     self.assertEqual(charset.negate(), first_five)
     text = r'[A-Z-[GHI]]'
     expected = unicode.CodePointSet( (ord('A'), ord('Z')) )
     expected.subtract( (ord('G'), ord('I') ))
     (charset, position) = xmlre._MatchCharClassExpr(text, 0)
     self.assertEqual(position, len(text))
     self.assertEqual(charset, expected)
     text = r'[\p{L}-\p{Lo}]'
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchCharClassExpr, text, 0)
     text = r'[\p{L}-[\p{Lo}]]'
     (charset, position) = xmlre._MatchCharClassExpr(text, 0)
     expected = unicode.CodePointSet(unicode.PropertyMap['L'])
     expected.subtract(unicode.PropertyMap['Lo'])
     self.assertEqual(position, len(text))
     self.assertEqual(charset, expected)
コード例 #2
0
ファイル: test-xmlre.py プロジェクト: gothub/pyxb-d1
 def testCharOrSCE (self):
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchCharClassEsc, '[', 0)
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchCharClassEsc, ']', 0)
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchCharClassEsc, '-', 0)
     (charset, position) = xmlre._MatchCharClassEsc(r'\t', 0)
     self.assertEqual(2, position)
     self.assertEqual(unicode.CodePointSet("\t"), charset)
コード例 #3
0
ファイル: test-xmlre.py プロジェクト: gothub/pyxb-d1
 def testMatchPosCharGroup (self):
     text = 'A]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 1)
     self.assertEqual(charset, unicode.CodePointSet(ord('A')))
     text = r'\n]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 2)
     self.assertEqual(charset, unicode.CodePointSet(10))
     text = r'-]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 1)
     self.assertEqual(charset, unicode.CodePointSet(ord('-')))
     text = 'A-Z]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 3)
     self.assertEqual(charset, unicode.CodePointSet((ord('A'), ord('Z'))))
     text = r'\t-\r]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 5)
     self.assertEqual(charset, unicode.CodePointSet((9, 13)))
     text = r'\t-A]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 4)
     self.assertEqual(charset, unicode.CodePointSet((9, ord('A'))))
     text = r'Z-\]]'
     (charset, has_sub, position) = xmlre._MatchPosCharGroup(text, 0)
     self.assertEqual(position, 4)
     self.assertEqual(charset, unicode.CodePointSet((ord('Z'), ord(']'))))
     text = 'Z-A]'
     self.assertRaises(xmlre.RegularExpressionError, xmlre._MatchPosCharGroup, text, 0)