@@ -672,6 +672,11 @@ def test_in_wstr(self):
672672 stdscr .addstr (0 , 0 , 'abz' )
673673 self .assertEqual (stdscr .in_wstr (0 , 0 , 0 ), '' )
674674 self .assertEqual (stdscr .in_wstr (0 ), '' )
675+ self .assertEqual (stdscr .in_wstr (0 , 0 , 2 ** 31 ), stdscr .in_wstr (0 , 0 ))
676+ self .assertRaises (OverflowError , stdscr .in_wstr , 2 ** 1000 )
677+ self .assertRaises (ValueError , stdscr .in_wstr , - 2 )
678+ self .assertRaises (ValueError , stdscr .in_wstr , 0 , 2 , - 2 )
679+ self .assertRaises (ValueError , stdscr .in_wstr , - 2 ** 1000 )
675680
676681 def test_complexchar (self ):
677682 # A complexchar is a styled wide-character cell: str() is its text,
@@ -871,6 +876,11 @@ def test_in_wchstr(self):
871876 # The count is optional and reads to the end of the line by default.
872877 stdscr .move (0 , 0 )
873878 self .assertEqual (str (stdscr .in_wchstr ())[:3 ], 'AbC' )
879+ self .assertEqual (stdscr .in_wchstr (0 , 0 , 2 ** 31 ), stdscr .in_wchstr (0 , 0 ))
880+ self .assertRaises (OverflowError , stdscr .in_wchstr , 2 ** 1000 )
881+ self .assertRaises (ValueError , stdscr .in_wchstr , - 2 )
882+ self .assertRaises (ValueError , stdscr .in_wchstr , 0 , 2 , - 2 )
883+ self .assertRaises (ValueError , stdscr .in_wchstr , - 2 ** 1000 )
874884
875885 def test_complexstr_in_write_methods (self ):
876886 # addstr/addnstr/insstr/insnstr also accept a complexstr, written via
@@ -1188,8 +1198,13 @@ def test_read_from_window(self):
11881198 self .assertEqual (stdscr .instr (3 )[:6 ], b' AB' )
11891199 self .assertEqual (stdscr .instr (0 , 2 )[:4 ], b'BCD ' )
11901200 self .assertEqual (stdscr .instr (0 , 2 , 4 ), b'BCD ' )
1201+ # A huge count is bounded by the line, and is not used to size the
1202+ # read buffer.
1203+ self .assertEqual (stdscr .instr (0 , 0 , 2 ** 31 ), stdscr .instr (0 , 0 ))
1204+ self .assertRaises (OverflowError , stdscr .instr , 2 ** 1000 )
11911205 self .assertRaises (ValueError , stdscr .instr , - 2 )
11921206 self .assertRaises (ValueError , stdscr .instr , 0 , 2 , - 2 )
1207+ self .assertRaises (ValueError , stdscr .instr , - 2 ** 1000 )
11931208 # instr(y, x, 1) reads a single cell byte, so only a character that the
11941209 # window encoding maps to one byte is checked. inch() returns the cell
11951210 # value, which is the locale byte.
@@ -1206,6 +1221,25 @@ def test_read_from_window(self):
12061221 self .assertEqual (stdscr .instr (2 , 0 , 1 ), b )
12071222 self .assertEqual (stdscr .inch (2 , 0 ), v )
12081223
1224+ def test_read_long_line (self ):
1225+ # A pad line can be longer than a window, and a character can be
1226+ # encoded with several bytes, so instr() can read more bytes than
1227+ # there are cells. See _encodable for the character set.
1228+ width = 3000
1229+ pad = curses .newpad (1 , width )
1230+ for ch in ['z' , '\u00e9 ' , '\u20ac ' , '\u0434 ' , '\uff71 ' ]:
1231+ if not self ._storable (ch ):
1232+ continue
1233+ pad .addstr (0 , 0 , ch )
1234+ if pad .getyx ()[1 ] != 1 :
1235+ continue # a wide character occupies two cells
1236+ with self .subTest (ch = ch ):
1237+ line = ch * (width - 1 ) + ' ' # the last cell is left blank
1238+ pad .addstr (0 , 0 , line [:- 1 ])
1239+ self .assertEqual (pad .instr (0 , 0 ), line .encode (pad .encoding ))
1240+ self .assertEqual (pad .in_wstr (0 , 0 ), line )
1241+ self .assertEqual (str (pad .in_wchstr (0 , 0 )), line )
1242+
12091243 def test_coordinate_errors (self ):
12101244 # Addressing a cell outside the window raises curses.error.
12111245 win = curses .newwin (5 , 10 , 0 , 0 )
0 commit comments