Compare commits
10 Commits
f687a80dba
...
a90b513369
Author | SHA1 | Date |
---|---|---|
dece | a90b513369 | 2 years ago |
dece | f4bc3f7568 | 2 years ago |
dece | b1c3f6c518 | 2 years ago |
dece | 04e7a02407 | 2 years ago |
dece | 325c285675 | 2 years ago |
dece | 41aff7acba | 2 years ago |
dece | 0f35971493 | 3 years ago |
dece | e0a5ca94ec | 3 years ago |
dece | ef6b8929e3 | 3 years ago |
dece | f48a8ab606 | 3 years ago |
@ -0,0 +1,45 @@
|
||||
from bebop.metalines import RenderOptions
|
||||
import unittest
|
||||
|
||||
from ..external import substitute_external_command
|
||||
from ..page import Page
|
||||
|
||||
|
||||
URL = "gemini://example.com"
|
||||
GEMTEXT = """\
|
||||
# Test page
|
||||
|
||||
Blablabla
|
||||
|
||||
=> gemini://example.com/index.gmi Link to index
|
||||
=> gemini://example.com/sub/gemlog.gmi Link to gemlog
|
||||
"""
|
||||
PAGE = Page.from_gemtext(GEMTEXT, RenderOptions(80, "fancy", "- "))
|
||||
|
||||
|
||||
class TestExternal(unittest.TestCase):
|
||||
|
||||
def test_substitute_external_command(self):
|
||||
# Replace URLs occurences.
|
||||
command = "gmni $u | grep $u" # Grep for a page's own URL.
|
||||
result = substitute_external_command(command, URL, PAGE)
|
||||
self.assertEqual(result, "gmni {u} | grep {u}".format(u=URL))
|
||||
|
||||
# Replace link ID's with the target URL.
|
||||
command = "gmni $1 && gmni $2" # Get both links
|
||||
result = substitute_external_command(command, URL, PAGE)
|
||||
expected = (
|
||||
"gmni gemini://example.com/index.gmi"
|
||||
" && gmni gemini://example.com/sub/gemlog.gmi"
|
||||
)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
# Invalid link ID raise a ValueError.
|
||||
command = "gmni $8"
|
||||
with self.assertRaises(Exception):
|
||||
substitute_external_command(command, URL, PAGE)
|
||||
|
||||
# Replace escaped $$ with literal $.
|
||||
command = "grep ^iamaregex$$ | echo dollar $" # Do nothing with last.
|
||||
result = substitute_external_command(command, URL, PAGE)
|
||||
self.assertEqual(result, "grep ^iamaregex$ | echo dollar $")
|
Loading…
Reference in new issue