summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test
diff options
context:
space:
mode:
authorTal Einat <taleinat@gmail.com>2019-07-11 14:20:14 (GMT)
committerGitHub <noreply@github.com>2019-07-11 14:20:14 (GMT)
commit9b5ce62cac27fec9dea473865d79c2c654312957 (patch)
treedc55645a8581162532bbeda67e8830db9512f396 /Lib/idlelib/idle_test
parent79042ac4348ccc09344014f20dd49401579f8795 (diff)
downloadcpython-9b5ce62cac27fec9dea473865d79c2c654312957.zip
cpython-9b5ce62cac27fec9dea473865d79c2c654312957.tar.gz
cpython-9b5ce62cac27fec9dea473865d79c2c654312957.tar.bz2
bpo-36390: simplify classifyws(), rename it and add unit tests (GH-14500)
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r--Lib/idlelib/idle_test/test_editor.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/Lib/idlelib/idle_test/test_editor.py b/Lib/idlelib/idle_test/test_editor.py
index 12bc847..4af4ff0 100644
--- a/Lib/idlelib/idle_test/test_editor.py
+++ b/Lib/idlelib/idle_test/test_editor.py
@@ -42,5 +42,66 @@ class EditorFunctionTest(unittest.TestCase):
self.assertEqual(func(dummy, inp), out)
+class TestGetLineIndent(unittest.TestCase):
+ def test_empty_lines(self):
+ for tabwidth in [1, 2, 4, 6, 8]:
+ for line in ['', '\n']:
+ with self.subTest(line=line, tabwidth=tabwidth):
+ self.assertEqual(
+ editor.get_line_indent(line, tabwidth=tabwidth),
+ (0, 0),
+ )
+
+ def test_tabwidth_4(self):
+ # (line, (raw, effective))
+ tests = (('no spaces', (0, 0)),
+ # Internal space isn't counted.
+ (' space test', (4, 4)),
+ ('\ttab test', (1, 4)),
+ ('\t\tdouble tabs test', (2, 8)),
+ # Different results when mixing tabs and spaces.
+ (' \tmixed test', (5, 8)),
+ (' \t mixed test', (5, 6)),
+ ('\t mixed test', (5, 8)),
+ # Spaces not divisible by tabwidth.
+ (' \tmixed test', (3, 4)),
+ (' \t mixed test', (3, 5)),
+ ('\t mixed test', (3, 6)),
+ # Only checks spaces and tabs.
+ ('\nnewline test', (0, 0)))
+
+ for line, expected in tests:
+ with self.subTest(line=line):
+ self.assertEqual(
+ editor.get_line_indent(line, tabwidth=4),
+ expected,
+ )
+
+ def test_tabwidth_8(self):
+ # (line, (raw, effective))
+ tests = (('no spaces', (0, 0)),
+ # Internal space isn't counted.
+ (' space test', (8, 8)),
+ ('\ttab test', (1, 8)),
+ ('\t\tdouble tabs test', (2, 16)),
+ # Different results when mixing tabs and spaces.
+ (' \tmixed test', (9, 16)),
+ (' \t mixed test', (9, 10)),
+ ('\t mixed test', (9, 16)),
+ # Spaces not divisible by tabwidth.
+ (' \tmixed test', (3, 8)),
+ (' \t mixed test', (3, 9)),
+ ('\t mixed test', (3, 10)),
+ # Only checks spaces and tabs.
+ ('\nnewline test', (0, 0)))
+
+ for line, expected in tests:
+ with self.subTest(line=line):
+ self.assertEqual(
+ editor.get_line_indent(line, tabwidth=8),
+ expected,
+ )
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)