@@ -371,6 +371,39 @@ def test_issue6243(self):
371371 curses .ungetch (1025 )
372372 self .stdscr .getkey ()
373373
374+ def test_in_wch (self ):
375+ stdscr = self .stdscr
376+
377+ if not hasattr (stdscr , 'in_wch' ):
378+ raise unittest .SkipTest ('requires curses.window.in_wch' )
379+
380+ if curses .has_colors ():
381+ curses .init_pair (1 , curses .COLOR_RED , 0 )
382+ expected_pair = 1
383+ color_attr = curses .color_pair (expected_pair )
384+ else :
385+ expected_pair = 0
386+ color_attr = 0
387+
388+ def _norm (ch , attr , color ):
389+ # for some reason, curses returns some color bits here?
390+ return ch , attr & ~ curses .A_COLOR , color
391+
392+ for ch in ('a' , '\xe9 ' , '\u20ac ' , '\U0001f643 ' ):
393+ expected = (ch , curses .A_BOLD , expected_pair )
394+
395+ stdscr .insstr (0 , 0 , ch , color_attr | curses .A_BOLD )
396+ self .assertEqual (_norm (* stdscr .in_wch ()), expected )
397+
398+ stdscr .addstr (0 , 0 , ch , color_attr | curses .A_BOLD )
399+ self .assertEqual (_norm (* stdscr .in_wch (0 , 0 )), expected )
400+
401+ # in_wch can return multiple characters in the case of zero width
402+ # curses at max returns 5 characters in a cchar_t
403+ stdscr .addstr (0 , 0 , 'a' + '\u200b ' * 10 )
404+ expected = ('a\u200b \u200b \u200b \u200b ' , 0 , 0 )
405+ self .assertEqual (stdscr .in_wch (0 , 0 ), expected )
406+
374407 @requires_curses_func ('unget_wch' )
375408 @unittest .skipIf (getattr (curses , 'ncurses_version' , (99 ,)) < (5 , 8 ),
376409 "unget_wch is broken in ncurses 5.7 and earlier" )
0 commit comments