OILS / devtools / services / zulip_test.py View on Github | oils.pub

64 lines, 27 significant
1#!/usr/bin/env python3
2"""
3Test cases for Zulip markdown to CommonMark conversion.
4
5Run with: python3 devtools/services/zulip_test.py
6"""
7
8import sys
9import os
10import unittest
11
12# Add the current directory to Python path so we can import zulip
13sys.path.insert(0, os.path.dirname(__file__))
14
15from zulip import convert_zulip_to_commonmark
16
17
18class TestZulipConversion(unittest.TestCase):
19 """Test all types of Zulip markdown conversions."""
20
21 def test_conversions(self):
22 """Test all types of Zulip markdown conversions."""
23
24 # Test cases: (input, expected_output)
25 test_cases = [
26 # Topic links
27 ("Check out #**blog-ideas>My Great Post** for details.",
28 "Check out [#blog-ideas > My Great Post](https://oilshell.zulipchat.com/#narrow/channel/266575-blog-ideas/topic/My.20Great.20Post) for details."
29 ),
30
31 # Stream-only links
32 ("Post it in #**containers** stream.",
33 "Post it in [#containers](https://oilshell.zulipchat.com/#narrow/channel/308821-containers) stream."
34 ),
35
36 # Bare URLs
37 ("Visit https://oils.pub/blog/ and https://github.com/oils-for-unix/oils for more info.",
38 "Visit <https://oils.pub/blog/> and <https://github.com/oils-for-unix/oils> for more info."
39 ),
40
41 # URLs already in markdown links (should not be double-wrapped)
42 ("Check [this link](https://oils.pub/release/0.30.0/) for details.",
43 "Check [this link](https://oils.pub/release/0.30.0/) for details."
44 ),
45
46 # Mixed content
47 ("See #**oil-dev>Performance Issues** and https://oils.pub/benchmarks/",
48 "See [#oil-dev > Performance Issues](https://oilshell.zulipchat.com/#narrow/channel/121539-oil-dev/topic/Performance.20Issues) and <https://oils.pub/benchmarks/>"
49 ),
50
51 # Special characters in topics
52 ("Check #**language-design>What's Next?** for roadmap.",
53 "Check [#language-design > What's Next?](https://oilshell.zulipchat.com/#narrow/channel/384942-language-design/topic/What.27s.20Next.3F) for roadmap."
54 )
55 ]
56
57 for input_text, expected in test_cases:
58 with self.subTest(input_text=input_text):
59 result = convert_zulip_to_commonmark(input_text)
60 self.assertEqual(result, expected)
61
62
63if __name__ == '__main__':
64 unittest.main()