Finish up testing for multicell URL detection
This commit is contained in:
parent
64e3b641ce
commit
8bf8f5dc46
5 changed files with 46 additions and 37 deletions
|
|
@ -309,7 +309,7 @@ line_url_end_at(Line *self, index_type x, bool check_short, char_type sentinel,
|
|||
ans = n;
|
||||
}
|
||||
#undef is_not_ok
|
||||
if (ans < self->xnum - 1 || !next_line_starts_with_url_chars) {
|
||||
if (next_char_pos(self, ans, 1) < self->xnum || !next_line_starts_with_url_chars) {
|
||||
while (ans > x && !self->cpu_cells[ans].ch_is_idx && can_strip_from_end_of_url(self->cpu_cells[ans].ch_or_idx)) {
|
||||
n = prev_char_pos(self, ans, 1);
|
||||
if (n >= self->xnum || n < x) break;
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#include "text-cache.h"
|
||||
|
||||
// TODO: URL detection with multicell
|
||||
|
||||
typedef union CellAttrs {
|
||||
struct {
|
||||
uint16_t decoration : 3;
|
||||
|
|
|
|||
|
|
@ -3714,7 +3714,7 @@ extend_url(Screen *screen, Line *line, index_type *x, index_type *y, char_type s
|
|||
while (count++ < 10) {
|
||||
bool in_hostname = last_hostname_char_pos >= line->xnum;
|
||||
has_newline = !line->cpu_cells[line->xnum-1].next_char_was_wrapped;
|
||||
if (*x != line->xnum - 1 || (!newlines_allowed && has_newline)) break;
|
||||
if (next_char_pos(line, *x, 1) < line->xnum || (!newlines_allowed && has_newline)) break;
|
||||
bool next_line_starts_with_url_chars = false;
|
||||
line = screen_visual_line(screen, *y + 2 * scale);
|
||||
if (line) {
|
||||
|
|
|
|||
|
|
@ -681,7 +681,7 @@ def set_link(url=None, id=None):
|
|||
self.ae(s.current_url_text(), 'ab')
|
||||
|
||||
# URL detection
|
||||
s = self.create_screen(cols=40)
|
||||
s = self.create_screen(cols=60)
|
||||
|
||||
s.reset()
|
||||
url = 'http://moo.com'
|
||||
|
|
@ -689,3 +689,4 @@ def set_link(url=None, id=None):
|
|||
s.detect_url(0, 0)
|
||||
self.ae(s.current_url_text(), url)
|
||||
asu((0, 0, len(url)*2 - 1), (1, 0, len(url)*2 - 1))
|
||||
# More tests for URL detection are in screen.py in detect_url()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
from kitty.rgb import color_names
|
||||
from kitty.window import pagerhist
|
||||
|
||||
from . import BaseTest, parse_bytes
|
||||
from . import BaseTest, draw_multicell, parse_bytes
|
||||
|
||||
|
||||
class TestScreen(BaseTest):
|
||||
|
|
@ -1112,37 +1112,8 @@ def ac(idx, count):
|
|||
ac(9, 10)
|
||||
|
||||
def test_detect_url(self):
|
||||
s = self.create_screen(cols=30)
|
||||
|
||||
def ae(expected, x=3, y=0):
|
||||
s.detect_url(x, y)
|
||||
url = ''.join(s.text_for_marked_url())
|
||||
self.assertEqual(expected, url)
|
||||
|
||||
def t(url, x=0, y=0, before='', after='', expected=''):
|
||||
s.reset()
|
||||
s.cursor.x = x
|
||||
s.cursor.y = y
|
||||
s.draw(before + url + after)
|
||||
ae(expected or url, x=x + 1 + len(before), y=y)
|
||||
|
||||
|
||||
t('http://moo.com')
|
||||
t('http://moo.com/something?else=+&what-')
|
||||
t('http://moo.com#fragme')
|
||||
for (st, e) in '() {} [] <>'.split():
|
||||
t('http://moo.com', before=st, after=e)
|
||||
for trailer in ')-=':
|
||||
t('http://moo.com' + trailer)
|
||||
for trailer in '{}([<>': # )]>
|
||||
t('http://moo.com', after=trailer)
|
||||
t('http://moo.com', x=s.columns - 9)
|
||||
t('https://wraps-by-one-char.com', before='[', after=']')
|
||||
t('http://[::1]:8080')
|
||||
t('https://wr[aps-by-one-ch]ar.com')
|
||||
t('http://[::1]:8080/x', after='[') # ]
|
||||
t('http://[::1]:8080/x]y34', expected='http://[::1]:8080/x')
|
||||
t('https://wraps-by-one-char.com[]/x', after='[') # ]
|
||||
detect_url(self)
|
||||
detect_url(self, scale=2)
|
||||
|
||||
def test_prompt_marking(self):
|
||||
# ]]]]]]]]]]]]]]]]}}}}}}}}}}}}}}}}))))))))))))))))))))))
|
||||
|
|
@ -1376,3 +1347,42 @@ def q(send, expected=None):
|
|||
q({'transparent_background_color2': '?'}, {'transparent_background_color2': (Color(255, 0, 0), 126)})
|
||||
q({'transparent_background_color2': '#ffffff@-1'})
|
||||
q({'transparent_background_color2': '?'}, {'transparent_background_color2': (Color(255, 255, 255), 255)})
|
||||
|
||||
|
||||
def detect_url(self, scale=1):
|
||||
s = self.create_screen(cols=30 * scale)
|
||||
|
||||
def ae(expected, x=3, y=0):
|
||||
s.detect_url(x * scale, y * scale)
|
||||
url = ''.join(s.text_for_marked_url())
|
||||
self.assertEqual(expected, url)
|
||||
|
||||
def t(url, x=0, y=0, before='', after='', expected=''):
|
||||
s.reset()
|
||||
s.cursor.x = x
|
||||
s.cursor.y = y
|
||||
text = before + url + after
|
||||
if scale == 1:
|
||||
s.draw(text)
|
||||
else:
|
||||
draw_multicell(s, text, scale=scale)
|
||||
ae(expected or url, x=x + 1 + len(before), y=y)
|
||||
|
||||
|
||||
t('http://moo.com')
|
||||
t('http://moo.com/something?else=+&what-')
|
||||
t('http://moo.com#fragme')
|
||||
for (st, e) in '() {} [] <>'.split():
|
||||
t('http://moo.com', before=st, after=e)
|
||||
for trailer in ')-=':
|
||||
t('http://moo.com' + trailer)
|
||||
for trailer in '{}([<>': # )]>
|
||||
t('http://moo.com', after=trailer)
|
||||
if scale == 1:
|
||||
t('http://moo.com', x=s.columns - 9)
|
||||
t('https://wraps-by-one-char.com', before='[', after=']')
|
||||
t('http://[::1]:8080')
|
||||
t('https://wr[aps-by-one-ch]ar.com')
|
||||
t('http://[::1]:8080/x', after='[') # ]
|
||||
t('http://[::1]:8080/x]y34', expected='http://[::1]:8080/x')
|
||||
t('https://wraps-by-one-char.com[]/x', after='[') # ]
|
||||
|
|
|
|||
Loading…
Reference in a new issue