Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai> Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com> Co-authored-by: Hdandria <henri.dandria@mistral.ai> Co-authored-by: Ivana Dunisijevic <ivana.dunisijevic@mistral.ai> Co-authored-by: Jean Burellier <sheplu@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: Val <102326092+vdeva@users.noreply.github.com> Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: renovate-mistral[bot] <253709520+renovate-mistral[bot]@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from vibe.core.utils.text import snippet_start_line, snippet_start_lines
|
|
|
|
|
|
class TestSnippetStartLine:
|
|
def test_finds_line_number(self) -> None:
|
|
assert snippet_start_line("a\nb\nc\nd\n", "c") == 3
|
|
|
|
def test_first_line(self) -> None:
|
|
assert snippet_start_line("hello\nworld", "hello") == 1
|
|
|
|
def test_multiline_snippet(self) -> None:
|
|
assert snippet_start_line("a\nb\nc", "\nb\n") == 2
|
|
|
|
def test_first_occurrence_when_repeated(self) -> None:
|
|
assert snippet_start_line("x\nx\nx", "x") == 1
|
|
|
|
def test_leading_newline_anchors_first_content_line(self) -> None:
|
|
assert snippet_start_line("bar\nx\nbar", "\nbar") == 3
|
|
|
|
def test_returns_none_when_exact_snippet_absent(self) -> None:
|
|
assert snippet_start_line("a\nb\nfoo", "foo\n") is None
|
|
|
|
def test_not_found(self) -> None:
|
|
assert snippet_start_line("hello\nworld", "missing") is None
|
|
|
|
def test_blank_snippet(self) -> None:
|
|
assert snippet_start_line("hello", "\n") is None
|
|
|
|
|
|
class TestSnippetStartLines:
|
|
def test_single_occurrence(self) -> None:
|
|
assert snippet_start_lines("a\nb\nc", "b") == [2]
|
|
|
|
def test_all_occurrences(self) -> None:
|
|
assert snippet_start_lines("x\ny\nx\nz\nx", "x") == [1, 3, 5]
|
|
|
|
def test_repeated_on_same_line(self) -> None:
|
|
assert snippet_start_lines("x x x", "x") == [1, 1, 1]
|
|
|
|
def test_non_overlapping(self) -> None:
|
|
assert snippet_start_lines("aaaa", "aa") == [1, 1]
|
|
|
|
def test_multiline_snippet_occurrences(self) -> None:
|
|
assert snippet_start_lines("a\nb\nc\na\nb", "a\nb") == [1, 4]
|
|
|
|
def test_not_found(self) -> None:
|
|
assert snippet_start_lines("hello\nworld", "missing") == []
|
|
|
|
def test_blank_snippet(self) -> None:
|
|
assert snippet_start_lines("hello", "\n") == []
|