コード例 #1
0
 def test_z(self):
     # z should expand to ulnp
     result = chars.resolve_charstring("z")
     self.assertEqual(type(result),set)
     target = set(range(32,127))
     target.remove(32)
     self.assertEqual(result,target)
コード例 #2
0
 def test_n(self):
     # a charset specifier should
     # yield the definition of the set
     result = chars.resolve_charstring("n")
     self.assertEqual(type(result),set)
     target = set(range(48,58))
     self.assertEqual(result,target)
コード例 #3
0
 def test_ne(self):
     # we should be able to use e to exclude characters
     result = chars.resolve_charstring("ne85")
     self.assertEqual(type(result),set)
     target = set(chars.character_ranges["n"])
     target.discard(ord("8"))
     target.discard(ord("5"))
     self.assertEqual(result,target)
コード例 #4
0
 def test_Hi(self):
     # we should be able to use i to include
     # additional characters
     result = chars.resolve_charstring("Hig$")
     self.assertEqual(type(result),set)
     target = set(chars.character_ranges["H"])
     target.add(ord("g"))
     target.add(ord("$"))
     self.assertEqual(result,target)
コード例 #5
0
 def test_ar(self):
     # ar should expand to ulnrs
     result = chars.resolve_charstring("ar")
     self.assertEqual(type(result),set)
     target = set(range(32,127))
     for codepoint in chars.character_ranges["p"]:
         if codepoint not in chars.character_ranges["r"]:
             target.remove(codepoint)
     self.assertEqual(result,target)
コード例 #6
0
 def test_2(self):
     result = chars.create_character_map(chars.resolve_charstring("uneE5"))
     is_none = 0
     counts = {}
     for elem in result:
         if elem is None:
             is_none += 1
         elif elem in counts:
             counts[elem] += 1
         else:
             counts[elem] = 1
     self.assertEqual(is_none,18)
     self.assertTrue(all(map(lambda key: counts[key] == 7, counts)))
コード例 #7
0
 def test_complex2(self):
     # we should be be able to combine multiple of these features
     # we should be able to end the string with e
     result = chars.resolve_charstring("nui$#..e..ieFe")
     target = set(range(48,58))
     for codepoint in range(65,91):
         target.add(codepoint)
     # nu
     target.add(ord("$"))
     target.add(ord("#"))
     target.add(ord("e"))
     target.add(ord("i"))
     # nui$#..e..i
     target.discard(ord("F"))
     # nui$#..e..ieF
     self.assertEqual(result,target)
コード例 #8
0
 def test_complex1(self):
     # we should be be able to combine multiple of these features
     result = chars.resolve_charstring("zre1234567890i$52e..i5")
     self.assertEqual(type(result),set)
     target = set(range(32,127))
     # a
     target.remove(32)
     # z
     for codepoint in chars.character_ranges["p"]:
         if codepoint not in chars.character_ranges["r"]:
             target.remove(codepoint)
     # zr
     for codepoint in range(48,58):
         target.discard(codepoint)
     # zre1234567890
     target.add(ord("$"))
     target.add(ord("5"))
     target.add(ord("2"))
     # zre1234567890i$52
     target.discard(ord("i"))
     target.discard(ord("5"))
     # zre1234567890i$52e..i5
     self.assertEqual(result,target)
コード例 #9
0
 def test_a(self):
     # a should expand to ulnps
     result = chars.resolve_charstring("a")
     self.assertEqual(type(result),set)
     target = set(range(32,127))
     self.assertEqual(result,target)
コード例 #10
0
 def test_cn(self):
     # we should be able to combine sets
     result = chars.resolve_charstring("cn")
     self.assertEqual(type(result),set)
     target = set( list(range(65,91)) + list(range(48,58)) )
     self.assertEqual(result,target)
コード例 #11
0
 def test_none(self):
     # no information, should yield no characters
     result = chars.resolve_charstring("")
     self.assertEqual(type(result),set)
     self.assertEqual(len(result),0)
コード例 #12
0
 def test_safe_failure(self):
     with self.assertRaises(Exception):
         # we should expect that any characters
         # before i or e should be named sets
         # or shorthands
         chars.resolve_charstring("q")
     with self.assertRaises(Exception):
         # we should expect that any characters
         # before i or e should be named sets
         # or shorthands
         chars.resolve_charstring("nb")
     with self.assertRaises(Exception):
         # we should expect that any characters
         # before i or e should be named sets
         # or shorthands
         chars.resolve_charstring("ZR")
     with self.assertRaises(Exception):
         # we should expect i or e after ..
         chars.resolve_charstring("ci..t")
     with self.assertRaises(Exception):
         # we should expect that any characters
         # before i or e should be named sets
         # or shorthands
         chars.resolve_charstring("..i")
     with self.assertRaises(Exception):
         # we should expect i or e after ..
         chars.resolve_charstring("le..e..I")
     with self.assertRaises(Exception):
         # we should expect i or e after ..
         chars.resolve_charstring("unl..")
     with self.assertRaises(Exception):
         # we should expect only ASCII-printable characters
         chars.resolve_charset(chr(31))
     with self.assertRaises(Exception):
         # we should expect only ASCII-printable characters
         chars.resolve_charset(chr(127))
     with self.assertRaises(Exception):
         # we should expect only ASCII-printable characters
         chars.resolve_charstring("niā")
     with self.assertRaises(Exception):
         # we should expect only ASCII-printable characters
         chars.resolve_charstring("ā")