Hints kitten: add support for IPs (v4 and v6)

It selects v4 and v6 IPs with a simple regex that doesn't actually
check for the validity of the IPs.
This commit is contained in:
Sighery
2020-10-04 22:04:00 +02:00
parent d3d2930bd2
commit b4415c90f9
2 changed files with 36 additions and 1 deletions

View File

@@ -30,3 +30,30 @@ class TestHints(BaseTest):
t('link:{}[xxx]'.format(u), u)
t('`xyz <{}>`_.'.format(u), u)
t('<a href="{}">moo'.format(u), u)
def test_ip_hints(self):
from kittens.hints.main import parse_hints_args, functions_for, mark, convert_text
args = parse_hints_args(['--type', 'ip'])[0]
pattern, post_processors = functions_for(args)
def create_marks(text, cols=60):
text = convert_text(text, cols)
return tuple(mark(pattern, post_processors, text, args))
testcases = (
('100.64.0.0', ['100.64.0.0']),
('2001:0db8:0000:0000:0000:ff00:0042:8329', ['2001:0db8:0000:0000:0000:ff00:0042:8329']),
('2001:db8:0:0:0:ff00:42:8329', ['2001:db8:0:0:0:ff00:42:8329']),
('2001:db8::ff00:42:8329', ['2001:db8::ff00:42:8329']),
('2001:DB8::FF00:42:8329', ['2001:DB8::FF00:42:8329']),
('0000:0000:0000:0000:0000:0000:0000:0001', ['0000:0000:0000:0000:0000:0000:0000:0001']),
('::1', ['::1']),
# The regex doesn't check for validity
('255.255.255.256', ['255.255.255.256']),
)
for testcase, expected in testcases:
with self.subTest(testcase=testcase, expected=expected):
marks = create_marks(testcase)
ips = [m.text for m in marks]
self.ae(ips, expected)