Пример #1
0
 def test_no_context(self):
     res = list(
         hound.get_lines_with_context("The match",
                                      1,
                                      lines_before=["Line 1", "Line 2"],
                                      lines_after=["Line 4", "Line 5"]))
     self.assertEqual(res, [(1, hound.LINE_KIND_MATCH, "The match")])
Пример #2
0
 def test_no_context(self):
     res = list(
         hound.get_lines_with_context(
             "The match", 1, lines_before=["Line 1", "Line 2"], lines_after=["Line 4", "Line 5"]
         )
     )
     self.assertEqual(res, [(1, hound.LINE_KIND_MATCH, "The match")])
Пример #3
0
 def test_after_context(self):
     res = list(
         hound.get_lines_with_context("The match",
                                      3,
                                      lines_before=["Line 1", "Line 2"],
                                      lines_after=["Line 4", "Line 5"],
                                      requested_after=3))
     self.assertEqual(res, [(3, hound.LINE_KIND_MATCH, "The match"),
                            (4, hound.LINE_KIND_CONTEXT, "Line 4"),
                            (5, hound.LINE_KIND_CONTEXT, "Line 5")])
Пример #4
0
 def test_context_request_less_than_available(self):
     # Ask for a context of 3 while we have 2 before and 2 after.
     res = list(
         hound.get_lines_with_context("The match",
                                      3,
                                      lines_before=["Line 1", "Line 2"],
                                      lines_after=["Line 4", "Line 5"],
                                      requested_context=3))
     self.assertEqual(res, [(2, hound.LINE_KIND_CONTEXT, "Line 2"),
                            (3, hound.LINE_KIND_MATCH, "The match"),
                            (4, hound.LINE_KIND_CONTEXT, "Line 4")])
Пример #5
0
 def test_context_request_less_than_available_prefer_before(self):
     # Ask for a context of 4 while we have 2 before and 2
     # after. We prefer showing 2 "before lines" and 1 "after
     # line", instead of 1 "before line" and 2 "after lines".
     res = list(
         hound.get_lines_with_context("The match",
                                      3,
                                      lines_before=["Line 1", "Line 2"],
                                      lines_after=["Line 4", "Line 5"],
                                      requested_context=4))
     self.assertEqual(res, [(1, hound.LINE_KIND_CONTEXT, "Line 1"),
                            (2, hound.LINE_KIND_CONTEXT, "Line 2"),
                            (3, hound.LINE_KIND_MATCH, "The match"),
                            (4, hound.LINE_KIND_CONTEXT, "Line 4")])
Пример #6
0
 def test_after_context(self):
     res = list(
         hound.get_lines_with_context(
             "The match", 3, lines_before=["Line 1", "Line 2"], lines_after=["Line 4", "Line 5"], requested_after=3
         )
     )
     self.assertEqual(
         res,
         [
             (3, hound.LINE_KIND_MATCH, "The match"),
             (4, hound.LINE_KIND_CONTEXT, "Line 4"),
             (5, hound.LINE_KIND_CONTEXT, "Line 5"),
         ],
     )
Пример #7
0
 def test_context_request_less_than_available(self):
     # Ask for a context of 3 while we have 2 before and 2 after.
     res = list(
         hound.get_lines_with_context(
             "The match", 3, lines_before=["Line 1", "Line 2"], lines_after=["Line 4", "Line 5"], requested_context=3
         )
     )
     self.assertEqual(
         res,
         [
             (2, hound.LINE_KIND_CONTEXT, "Line 2"),
             (3, hound.LINE_KIND_MATCH, "The match"),
             (4, hound.LINE_KIND_CONTEXT, "Line 4"),
         ],
     )
Пример #8
0
 def test_context_request_less_than_available_prefer_before(self):
     # Ask for a context of 4 while we have 2 before and 2
     # after. We prefer showing 2 "before lines" and 1 "after
     # line", instead of 1 "before line" and 2 "after lines".
     res = list(
         hound.get_lines_with_context(
             "The match", 3, lines_before=["Line 1", "Line 2"], lines_after=["Line 4", "Line 5"], requested_context=4
         )
     )
     self.assertEqual(
         res,
         [
             (1, hound.LINE_KIND_CONTEXT, "Line 1"),
             (2, hound.LINE_KIND_CONTEXT, "Line 2"),
             (3, hound.LINE_KIND_MATCH, "The match"),
             (4, hound.LINE_KIND_CONTEXT, "Line 4"),
         ],
     )