Commit 78191224 authored by Terry Jan Reedy's avatar Terry Jan Reedy

Issue 21284: Idle: make test_formatparagraph pass even when a user changes the

reformat width in the configuration menu.
parent 99a0c8b0
...@@ -32,7 +32,7 @@ class FormatParagraph: ...@@ -32,7 +32,7 @@ class FormatParagraph:
def close(self): def close(self):
self.editwin = None self.editwin = None
def format_paragraph_event(self, event): def format_paragraph_event(self, event, limit=None):
"""Formats paragraph to a max width specified in idleConf. """Formats paragraph to a max width specified in idleConf.
If text is selected, format_paragraph_event will start breaking lines If text is selected, format_paragraph_event will start breaking lines
...@@ -41,9 +41,12 @@ class FormatParagraph: ...@@ -41,9 +41,12 @@ class FormatParagraph:
If no text is selected, format_paragraph_event uses the current If no text is selected, format_paragraph_event uses the current
cursor location to determine the paragraph (lines of text surrounded cursor location to determine the paragraph (lines of text surrounded
by blank lines) and formats it. by blank lines) and formats it.
The length limit parameter is for testing with a known value.
""" """
maxformatwidth = idleConf.GetOption( if limit == None:
'main', 'FormatParagraph', 'paragraph', type='int') limit = idleConf.GetOption(
'main', 'FormatParagraph', 'paragraph', type='int')
text = self.editwin.text text = self.editwin.text
first, last = self.editwin.get_selection_indices() first, last = self.editwin.get_selection_indices()
if first and last: if first and last:
...@@ -53,9 +56,9 @@ class FormatParagraph: ...@@ -53,9 +56,9 @@ class FormatParagraph:
first, last, comment_header, data = \ first, last, comment_header, data = \
find_paragraph(text, text.index("insert")) find_paragraph(text, text.index("insert"))
if comment_header: if comment_header:
newdata = reformat_comment(data, maxformatwidth, comment_header) newdata = reformat_comment(data, limit, comment_header)
else: else:
newdata = reformat_paragraph(data, maxformatwidth) newdata = reformat_paragraph(data, limit)
text.tag_remove("sel", "1.0", "end") text.tag_remove("sel", "1.0", "end")
if newdata != data: if newdata != data:
......
...@@ -293,7 +293,7 @@ class FormatEventTest(unittest.TestCase): ...@@ -293,7 +293,7 @@ class FormatEventTest(unittest.TestCase):
# Set cursor ('insert' mark) to '1.0', within text. # Set cursor ('insert' mark) to '1.0', within text.
text.insert('1.0', self.test_string) text.insert('1.0', self.test_string)
text.mark_set('insert', '1.0') text.mark_set('insert', '1.0')
self.formatter('ParameterDoesNothing') self.formatter('ParameterDoesNothing', limit=70)
result = text.get('1.0', 'insert') result = text.get('1.0', 'insert')
# find function includes \n # find function includes \n
expected = ( expected = (
...@@ -305,7 +305,7 @@ class FormatEventTest(unittest.TestCase): ...@@ -305,7 +305,7 @@ class FormatEventTest(unittest.TestCase):
# Select from 1.11 to line end. # Select from 1.11 to line end.
text.insert('1.0', self.test_string) text.insert('1.0', self.test_string)
text.tag_add('sel', '1.11', '1.end') text.tag_add('sel', '1.11', '1.end')
self.formatter('ParameterDoesNothing') self.formatter('ParameterDoesNothing', limit=70)
result = text.get('1.0', 'insert') result = text.get('1.0', 'insert')
# selection excludes \n # selection excludes \n
expected = ( expected = (
...@@ -319,7 +319,7 @@ class FormatEventTest(unittest.TestCase): ...@@ -319,7 +319,7 @@ class FormatEventTest(unittest.TestCase):
# Select 2 long lines. # Select 2 long lines.
text.insert('1.0', self.multiline_test_string) text.insert('1.0', self.multiline_test_string)
text.tag_add('sel', '2.0', '4.0') text.tag_add('sel', '2.0', '4.0')
self.formatter('ParameterDoesNothing') self.formatter('ParameterDoesNothing', limit=70)
result = text.get('2.0', 'insert') result = text.get('2.0', 'insert')
expected = ( expected = (
" The second line's length is way over the max width. It goes on and\n" " The second line's length is way over the max width. It goes on and\n"
...@@ -334,7 +334,7 @@ class FormatEventTest(unittest.TestCase): ...@@ -334,7 +334,7 @@ class FormatEventTest(unittest.TestCase):
# Set cursor ('insert') to '1.0', within block. # Set cursor ('insert') to '1.0', within block.
text.insert('1.0', self.multiline_test_comment) text.insert('1.0', self.multiline_test_comment)
self.formatter('ParameterDoesNothing') self.formatter('ParameterDoesNothing', limit=70)
result = text.get('1.0', 'insert') result = text.get('1.0', 'insert')
expected = ( expected = (
"# The first line is under the max width. The second line's length is\n" "# The first line is under the max width. The second line's length is\n"
...@@ -348,7 +348,7 @@ class FormatEventTest(unittest.TestCase): ...@@ -348,7 +348,7 @@ class FormatEventTest(unittest.TestCase):
# Select line 2, verify line 1 unaffected. # Select line 2, verify line 1 unaffected.
text.insert('1.0', self.multiline_test_comment) text.insert('1.0', self.multiline_test_comment)
text.tag_add('sel', '2.0', '3.0') text.tag_add('sel', '2.0', '3.0')
self.formatter('ParameterDoesNothing') self.formatter('ParameterDoesNothing', limit=70)
result = text.get('1.0', 'insert') result = text.get('1.0', 'insert')
expected = ( expected = (
"# The first line is under the max width.\n" "# The first line is under the max width.\n"
......
...@@ -186,6 +186,8 @@ Extension Modules ...@@ -186,6 +186,8 @@ Extension Modules
IDLE IDLE
---- ----
- Issue 21284: Paragraph reformat test passes after user changes reformat width.
- Issue #17654: Ensure IDLE menus are customized properly on OS X for - Issue #17654: Ensure IDLE menus are customized properly on OS X for
non-framework builds and for all variants of Tk. non-framework builds and for all variants of Tk.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment