Skip to content
Merged
Prev Previous commit
Next Next commit
Add tests for GB12 and GB13. Remove redundant parameter in run_graphe…
…me_break_tests().
  • Loading branch information
serhiy-storchaka committed Dec 26, 2025
commit a95c3cb0209b30c93012a02269a921492f29a6a6
15 changes: 10 additions & 5 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,14 @@ def graphemes(*args):
'\u200D\U0001F48B\u200D\U0001F9D1\U0001F3FC'),
['\U0001F9D1\U0001F3FE\u200D\u2764\uFE0F'
'\u200D\U0001F48B\u200D\U0001F9D1\U0001F3FC'])
# GB11
self.assertEqual(graphemes('\U0001F1FA\U0001F1E6'),
['\U0001F1FA\U0001F1E6'])
# GB12
self.assertEqual(graphemes(
'\U0001F1FA\U0001F1E6\U0001F1FA\U0001F1F3'),
['\U0001F1FA\U0001F1E6', '\U0001F1FA\U0001F1F3'])
# GB13
self.assertEqual(graphemes(
'a\U0001F1FA\U0001F1E6\U0001F1FA\U0001F1F3'),
['a', '\U0001F1FA\U0001F1E6', '\U0001F1FA\U0001F1F3'])


class Unicode_3_2_0_FunctionsTest(UnicodeFunctionsTest):
Expand Down Expand Up @@ -1085,9 +1090,9 @@ def test_grapheme_break(self):
self.skipTest(f"Failed to download {TESTDATAURL}: {exc}")

with testdata:
self.run_grapheme_break_tests(testdata, unicodedata)
self.run_grapheme_break_tests(testdata)

def run_grapheme_break_tests(self, testdata, ucd):
def run_grapheme_break_tests(self, testdata):
for line in testdata:
line, _, comment = line.partition('#')
line = line.strip()
Expand Down
7 changes: 4 additions & 3 deletions Modules/unicodedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,9 @@ grapheme_break(int prev_gcb, int curr_gcb, enum ExtPictState ep_state,
/* GB6 */
if (prev_gcb == GCB_L &&
(curr_gcb == GCB_L ||
curr_gcb == GCB_V ||
curr_gcb == GCB_LV ||
curr_gcb == GCB_LVT))
curr_gcb == GCB_V ||
curr_gcb == GCB_LV ||
curr_gcb == GCB_LVT))
{
return false;
}
Expand Down Expand Up @@ -1819,6 +1819,7 @@ grapheme_break(int prev_gcb, int curr_gcb, enum ExtPictState ep_state,
return false;
}

/* GB12 and GB13 */
if (prev_gcb == GCB_Regional_Indicator && curr_gcb == prev_gcb) {
return ri_flag;
}
Expand Down