38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import unittest
|
|
|
|
from ai_search_agent.parsers import extract_json_object, extract_markdown_links, extract_urls, trim_text
|
|
|
|
|
|
class ParserTests(unittest.TestCase):
|
|
def test_extract_markdown_links_deduplicates(self) -> None:
|
|
text = """
|
|
[Example](https://example.com)
|
|
[Example Again](https://example.com)
|
|
[Docs](https://docs.example.com/path)
|
|
"""
|
|
results = extract_markdown_links(text)
|
|
|
|
self.assertEqual(
|
|
[item.url for item in results],
|
|
["https://example.com", "https://docs.example.com/path"],
|
|
)
|
|
|
|
def test_extract_urls(self) -> None:
|
|
text = "See https://a.example.com, https://b.example.com/docs."
|
|
self.assertEqual(
|
|
extract_urls(text),
|
|
["https://a.example.com", "https://b.example.com/docs"],
|
|
)
|
|
|
|
def test_trim_text(self) -> None:
|
|
self.assertEqual(trim_text("abc", 5), "abc")
|
|
self.assertTrue(trim_text("abcdef", 3).startswith("abc"))
|
|
|
|
def test_extract_json_object(self) -> None:
|
|
text = "prefix {\"summary\": \"ok\"} suffix"
|
|
self.assertEqual(extract_json_object(text), "{\"summary\": \"ok\"}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|