diff -r 13e154067de3 Lib/idlelib/RstripExtension.py --- a/Lib/idlelib/RstripExtension.py Wed Jul 03 23:07:37 2013 +0200 +++ b/Lib/idlelib/RstripExtension.py Thu Jul 04 15:45:17 2013 -0400 @@ -27,3 +27,9 @@ text.delete('%i.%i' % (cur, cut), '%i.0 lineend' % cur) undo.undo_block_stop() + +if __name__ == "__main__": + from test import support; support.use_resources = ['gui'] + import unittest + unittest.main('idlelib.idle_test.test_rstripextension', verbosity=2, + exit=False) diff -r 13e154067de3 Lib/idlelib/idle_test/mock_idle.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/idle_test/mock_idle.py Thu Jul 04 15:45:17 2013 -0400 @@ -0,0 +1,18 @@ +from idlelib.idle_test.mock_tk import Text + +class mockEditorWindow: + + def __init__(self): + self.text = Text() + self.undo = mockUndoDelegator() + + def get_selection_indices(self): + first = self.text.index('sel.first') + last = self.text.index('sel.last') + return first, last + +class mockUndoDelegator: + def undo_block_start(*args): + pass + def undo_block_stop(*args): + pass diff -r 13e154067de3 Lib/idlelib/idle_test/mock_tk.py --- a/Lib/idlelib/idle_test/mock_tk.py Wed Jul 03 23:07:37 2013 +0200 +++ b/Lib/idlelib/idle_test/mock_tk.py Thu Jul 04 15:45:17 2013 -0400 @@ -61,3 +61,110 @@ showerror = Mbox_func() # None showinfo = Mbox_func() # None showwarning = Mbox_func() # None + +class Text: + def __init__(self): + self.data = [''] + + def bind(*args): + pass + + def setData(self, text): + # Used splitlines and retained newline because Tkinter docs + # say that referring to indexes "out of bounds" refer to the newline + # character at the end of a line or the last line. + self.data = text.splitlines(True) + + def getData(self): + return ''.join(self.data) + + def _decode(self, position): # private helper + """ + Takes Text index (eg. '2.5') and returns index in self.data. + """ + position = str(position) # Tkinter allows floats to be passed in + if position == 'end': + return len(self.data) - 1, len(self.data[len(self.data)-1]) + line, col = position.split('.') + line = int(line) + if line > len(self.data): # Out of bounds equals "line beyond the last" + self.data.append('\n') + line = len(self.data) - 1 + self.data[line-1] += '\n' + return line, 0 + lineLength = len(self.data[line-1]) + if col == '0 lineend': + col = lineLength - 1 + elif int(col) >= lineLength: + col = lineLength - 1 + elif int(col) < lineLength: + col = int(col) + return line - 1, col + + def get(self, start, end=None): + startline, startcol = self._decode(start) + if startline > len(self.data): + startline = len(self.data) - 1 + if end is None: + return self.data[startline][startcol] + else: + endline, endcol = self._decode(end) + if startline == endline: + return self.data[startline][startcol:endcol] + else: + lines = [self.data[startline][startcol:]] + for i in range(startline+1, endline): + lines.append(self.data[i]) + lines.append(self.data[endline][:endcol]) + return ''.join(lines) + + def delete(self, start, end=None): + startline, startcol = self._decode(start) + if end is None: + self.data[startline] = self.data[startline][:startcol] + + self.data[startline][startcol+1:] + return + else: + endline, endcol = self._decode(end) + if startline == endline: + self.data[startline] = self.data[startline][:startcol] + + self.data[endline][endcol:] + else: + self.data[startline] = self.data[startline][:startcol] + + self.data[endline][endcol:] + for i in range(startline+1, endline): + del self.data[startline+1] + return + + def index(self, position): + if position == 'end': + return str(len(self.data)) + '.' + str(len(self.data[-1])) + if position == 'sel.first': + return '1.0' + if position == 'sel.last': + return 'end' + # TODO: support other index types (eg. line.column, line.end, ...). + + def insert(self, position, text): + text = text.splitlines(True) + line, col = self._decode(position) + splitline = [self.data[line][:col], self.data[line][col:]] + self.data[line] = splitline[0] + text[0] + for i in range(1, len(text)): + self.data.insert(line+i, text[i]) + self.data[line+len(text)-1] += splitline[1] + + def tag_remove(self, *args): + pass + + def mark_set(self, *args): + pass + + def undo_block_start(self, *args): + pass + + def undo_block_stop(self, *args): + pass + + def see(self, *args): + pass