Co-authored-by: Albert Jiang <aj@mistral.ai> Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Laure Hugo <201583486+laure0303@users.noreply.github.com> Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai> Co-authored-by: Mert Unsal <mert.unsal@mistral.ai> Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com> Co-authored-by: Paul VEZIA <166131032+le-codeur-rapide@users.noreply.github.com> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from vibe.core.utils.text import line_contexts
|
|
|
|
|
|
class TestLineContexts:
|
|
def test_single_occurrence(self) -> None:
|
|
assert line_contexts("foo = bar + baz", "bar") == [(1, "foo = ", " + baz")]
|
|
|
|
def test_per_occurrence_distinct_context(self) -> None:
|
|
content = "x = bar + 1\ny = bar - 2\nz = bar\n"
|
|
assert line_contexts(content, "bar") == [
|
|
(1, "x = ", " + 1"),
|
|
(2, "y = ", " - 2"),
|
|
(3, "z = ", ""),
|
|
]
|
|
|
|
def test_snippet_ending_on_newline_has_empty_suffix(self) -> None:
|
|
content = "keep1\nremove\nkeep2\n"
|
|
assert line_contexts(content, "remove\n") == [(2, "", "")]
|
|
|
|
def test_leading_newline_anchors_at_match_position(self) -> None:
|
|
# The leading newline belongs to lineA, so the whole-line expansion must
|
|
# include lineA (the line the edit starts modifying) anchored at line 1.
|
|
assert line_contexts("lineA\nlineB", "\nlineB") == [(1, "lineA", "")]
|
|
|
|
def test_not_found(self) -> None:
|
|
assert line_contexts("hello\nworld", "missing") == []
|
|
|
|
def test_blank_snippet(self) -> None:
|
|
assert line_contexts("hello", "\n") == []
|