@@ -1107,6 +1107,39 @@ def test_issue6243(self):
11071107 curses .ungetch (1025 )
11081108 self .stdscr .getkey ()
11091109
1110+ def test_in_wch (self ):
1111+ stdscr = self .stdscr
1112+
1113+ if not hasattr (stdscr , 'in_wch' ):
1114+ raise unittest .SkipTest ('requires curses.window.in_wch' )
1115+
1116+ if curses .has_colors ():
1117+ curses .init_pair (1 , curses .COLOR_RED , 0 )
1118+ expected_pair = 1
1119+ color_attr = curses .color_pair (expected_pair )
1120+ else :
1121+ expected_pair = 0
1122+ color_attr = 0
1123+
1124+ def _norm (ch , attr , color ):
1125+ # for some reason, curses returns some color bits here?
1126+ return ch , attr & ~ curses .A_COLOR , color
1127+
1128+ for ch in ('a' , '\xe9 ' , '\u20ac ' , '\U0001f643 ' ):
1129+ expected = (ch , curses .A_BOLD , expected_pair )
1130+
1131+ stdscr .insstr (0 , 0 , ch , color_attr | curses .A_BOLD )
1132+ self .assertEqual (_norm (* stdscr .in_wch ()), expected )
1133+
1134+ stdscr .addstr (0 , 0 , ch , color_attr | curses .A_BOLD )
1135+ self .assertEqual (_norm (* stdscr .in_wch (0 , 0 )), expected )
1136+
1137+ # in_wch can return multiple characters in the case of zero width
1138+ # curses at max returns 5 characters in a cchar_t
1139+ stdscr .addstr (0 , 0 , 'a' + '\u200b ' * 10 )
1140+ expected = ('a\u200b \u200b \u200b \u200b ' , 0 , 0 )
1141+ self .assertEqual (stdscr .in_wch (0 , 0 ), expected )
1142+
11101143 @requires_curses_func ('unget_wch' )
11111144 @unittest .skipIf (getattr (curses , 'ncurses_version' , (99 ,)) < (5 , 8 ),
11121145 "unget_wch is broken in ncurses 5.7 and earlier" )
0 commit comments