Skip to content

Commit b0e57a8

Browse files
dgunningclaude
andcommitted
test(search): add end-to-end snippet assertions for #860
Adds full-path tests that drive DocumentSearch.search() over a real Document and assert SearchResult.snippet highlights the correct characters (text and regex modes), complementing the existing helper-level tests. Ported from the equivalent PR #860. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e090e80 commit b0e57a8

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

tests/issues/regression/test_issue_860_search_snippet_offsets.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,39 @@
66
wrong characters.
77
"""
88

9-
from edgar.documents.search import DocumentSearch
9+
from edgar.documents.document import Document
10+
from edgar.documents.nodes import DocumentNode, ParagraphNode, TextNode
11+
from edgar.documents.search import DocumentSearch, SearchMode
12+
13+
14+
def _document_with_text(text: str) -> Document:
15+
"""Build a minimal one-paragraph document for end-to-end search tests."""
16+
root = DocumentNode()
17+
paragraph = ParagraphNode()
18+
paragraph.add_child(TextNode(content=text))
19+
root.add_child(paragraph)
20+
return Document(root=root)
21+
22+
23+
def test_text_search_snippet_highlights_match_after_truncated_prefix():
24+
"""End-to-end: text search highlights the right characters in .snippet."""
25+
text = f"{'a' * 60} target {'b' * 60}"
26+
result = DocumentSearch(_document_with_text(text)).search("target")[0]
27+
28+
assert result.context[result.start_offset:result.end_offset] == "target"
29+
assert "**target**" in result.snippet
30+
31+
32+
def test_regex_search_snippet_highlights_match_after_truncated_prefix():
33+
"""End-to-end: regex search highlights the right characters in .snippet."""
34+
text = f"{'a' * 60} target phrase {'b' * 60}"
35+
result = DocumentSearch(_document_with_text(text)).search(
36+
r"target\s+phrase",
37+
mode=SearchMode.REGEX,
38+
)[0]
39+
40+
assert result.context[result.start_offset:result.end_offset] == "target phrase"
41+
assert "**target phrase**" in result.snippet
1042

1143

1244
def test_get_context_with_offsets_adjusts_for_truncation():

0 commit comments

Comments
 (0)