| 1310 | self.run_grapheme_break_tests(testdata) |
| 1311 | |
| 1312 | def run_grapheme_break_tests(self, testdata): |
| 1313 | for line in testdata: |
| 1314 | line, _, comment = line.partition('#') |
| 1315 | line = line.strip() |
| 1316 | if not line: |
| 1317 | continue |
| 1318 | comment = comment.strip() |
| 1319 | |
| 1320 | chunks = [] |
| 1321 | breaks = [] |
| 1322 | pos = 0 |
| 1323 | for field in line.replace('×', ' ').split(): |
| 1324 | if field == '÷': |
| 1325 | chunks.append('') |
| 1326 | breaks.append(pos) |
| 1327 | else: |
| 1328 | chunks[-1] += chr(int(field, 16)) |
| 1329 | pos += 1 |
| 1330 | self.assertEqual(chunks.pop(), '', line) |
| 1331 | input = ''.join(chunks) |
| 1332 | with self.subTest(line): |
| 1333 | result = list(unicodedata.iter_graphemes(input)) |
| 1334 | self.assertEqual(list(map(str, result)), chunks, comment) |
| 1335 | self.assertEqual([x.start for x in result], breaks[:-1], comment) |
| 1336 | self.assertEqual([x.end for x in result], breaks[1:], comment) |
| 1337 | for i in range(1, len(breaks) - 1): |
| 1338 | result = list(unicodedata.iter_graphemes(input, breaks[i])) |
| 1339 | self.assertEqual(list(map(str, result)), chunks[i:], comment) |
| 1340 | self.assertEqual([x.start for x in result], breaks[i:-1], comment) |
| 1341 | self.assertEqual([x.end for x in result], breaks[i+1:], comment) |
| 1342 | |
| 1343 | def test_reference_loops(self): |
| 1344 | # Test that reference loops involving GraphemeBreakIterator or |