From b9656c2faed38a02c5c904471cd69958e7280fa5 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 5 Jan 2024 16:46:31 -0800 Subject: [PATCH] add line_slice tests --- tests/test_jc_utils.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/test_jc_utils.py b/tests/test_jc_utils.py index bf72d2b2..28f216dd 100644 --- a/tests/test_jc_utils.py +++ b/tests/test_jc_utils.py @@ -205,6 +205,48 @@ class MyTests(unittest.TestCase): self.assertEqual(jc.utils.input_type_check('abc'), None) + def test_line_slice_string_positive_slice(self): + data = '''line1 +line2 +line3 +line4 +''' + expected = 'line2\nline3' + self.assertEqual(jc.utils.line_slice(data, 1, 3), expected) + + + def test_line_slice_string_negative_slice(self): + data = '''line1 +line2 +line3 +line4 +''' + expected = 'line2\nline3' + self.assertEqual(jc.utils.line_slice(data, 1, -1), expected) + + + def test_line_slice_iter_positive_slice(self): + data = [ + 'line1', + 'line2', + 'line3', + 'line4' + ] + expected = ['line2', 'line3'] + self.assertEqual(list(jc.utils.line_slice(data, 1, 3)), expected) + + + def test_line_slice_iter_negative_slice(self): + data = [ + 'line1', + 'line2', + 'line3', + 'line4' + ] + expected = ['line2', 'line3'] + self.assertEqual(list(jc.utils.line_slice(data, 1, -1)), expected) + + # need to mock shutil.get_terminal_size().columns or add a column parameter to test # def test_warning_message(self): # msg = [