Cleanup linenum matching and add some tests

This commit is contained in:
Kovid Goyal
2022-02-23 23:05:20 +05:30
parent 7800c598f6
commit cb4a9d89cf
2 changed files with 34 additions and 9 deletions

View File

@@ -1,18 +1,21 @@
#!/usr/bin/env python3
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import os
from . import BaseTest
class TestHints(BaseTest):
def test_url_hints(self):
from kittens.hints.main import parse_hints_args, functions_for, mark, convert_text
from kittens.hints.main import (
Mark, convert_text, functions_for, linenum_marks,
linenum_process_result, mark, parse_hints_args
)
args = parse_hints_args([])[0]
pattern, post_processors = functions_for(args)
def create_marks(text, cols=20):
def create_marks(text, cols=20, mark=mark):
text = convert_text(text, cols)
return tuple(mark(pattern, post_processors, text, args))
@@ -30,8 +33,27 @@ class TestHints(BaseTest):
t(f'`xyz <{u}>`_.', u)
t(f'<a href="{u}">moo', u)
def m(text, path, line, cols=20):
def adapt(pattern, postprocessors, text, *a):
return linenum_marks(text, args, Mark, ())
marks = create_marks(text, cols, mark=adapt)
data = {'groupdicts': [m.groupdict for m in marks], 'match': [m.text for m in marks]}
self.ae(linenum_process_result(data), (path, line))
args = parse_hints_args('--type=linenum'.split())[0]
m('file.c:23', 'file.c', 23)
m('file.c:23:32', 'file.c', 23)
m('file.cpp:23:1', 'file.cpp', 23)
m('a/file.c:23', 'a/file.c', 23)
m('a/file.c:23:32', 'a/file.c', 23)
m('~/file.c:23:32', os.path.expanduser('~/file.c'), 23)
def test_ip_hints(self):
from kittens.hints.main import parse_hints_args, functions_for, mark, convert_text
from kittens.hints.main import (
convert_text, functions_for, mark, parse_hints_args
)
args = parse_hints_args(['--type', 'ip'])[0]
pattern, post_processors = functions_for(args)