Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add IndentSearcher test.
  • Loading branch information
terryjreedy committed May 22, 2023
commit cb348d8eb8d2258885452283eee55ec691efca51
3 changes: 1 addition & 2 deletions Lib/idlelib/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,6 @@ class IndentSearcher:

def __init__(self, text):
self.text = text
self.tabwidth = tabwidth
self.i = self.finished = 0
self.blkopenline = self.indentedline = None

Expand Down Expand Up @@ -1642,7 +1641,7 @@ def tokeneater(self, type, token, start, end, line,
def run(self):
"""Return 2 lines containing block opener and and indent.

Either or both may instead be None.
Either the indent line or both may be None.
"""
try:
tokens = tokenize.generate_tokens(self.readline)
Expand Down
33 changes: 31 additions & 2 deletions Lib/idlelib/idle_test/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest
from collections import namedtuple
from test.support import requires
from tkinter import Tk
from tkinter import Tk, Text

Editor = editor.EditorWindow

Expand All @@ -31,7 +31,7 @@ def test_init(self):
e._close()


class TestGetLineIndent(unittest.TestCase):
class GetLineIndentTest(unittest.TestCase):
def test_empty_lines(self):
for tabwidth in [1, 2, 4, 6, 8]:
for line in ['', '\n']:
Expand Down Expand Up @@ -181,6 +181,35 @@ def test_indent_and_newline_event(self):
eq(get('1.0', 'end'), ' def f1(self, a,\n \n return a + b\n')


class IndentSearcherTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
cls.root.withdraw()
cls.text = Text(cls.root)

@classmethod
def tearDownClass(cls):
cls.root.destroy()
del cls.root

def test_searcher(self):
text = self.text
searcher = (self.text)
test_info = (# text, (block, indent))
("", (None, None)),
("if 1:\n", ('if 1:\n', None)),
("if 1:\n 2\n 3\n", ('if 1:\n', ' 2\n')),
)
for code, expected_pair in test_info:
with self.subTest(code=code):
insert(text, code)
actual_pair = editor.IndentSearcher(text).run()
self.assertEqual(actual_pair, expected_pair)


class RMenuTest(unittest.TestCase):

@classmethod
Expand Down