vim-patch:8.2.1741: pathshorten() only supports using one character

Problem:    pathshorten() only supports using one character.
Solution:   Add an argument to control the length. (closes vim/vim#7006)
6a33ef0deb

Cherry-pick a line in test from patch 8.2.0634.
Use Nvim's config paths in docs.

shorten_dir() returning a pointer looks a bit confusing here, as it is
actually the same pointer passed to it, and it doesn't really reduce
much code, so change it back to void.

Assigning rettv->vval.v_string = NULL is not needed if a pointer is
within 64 bits. While this is usually the case, I'm not sure if it can
be taken for granted.
This commit is contained in:
zeertzjq
2022-02-06 16:29:12 +08:00
parent 8215c05945
commit d65ee12914
6 changed files with 66 additions and 19 deletions

View File

@@ -376,6 +376,25 @@ func Test_pathshorten()
call assert_equal('~.f/bar', pathshorten('~.foo/bar'))
call assert_equal('.~f/bar', pathshorten('.~foo/bar'))
call assert_equal('~/f/bar', pathshorten('~/foo/bar'))
call assert_fails('call pathshorten([])', 'E730:')
" test pathshorten with optional variable to set preferred size of shortening
call assert_equal('', pathshorten('', 2))
call assert_equal('foo', pathshorten('foo', 2))
call assert_equal('/foo', pathshorten('/foo', 2))
call assert_equal('fo/', pathshorten('foo/', 2))
call assert_equal('fo/bar', pathshorten('foo/bar', 2))
call assert_equal('fo/ba/foobar', pathshorten('foo/bar/foobar', 2))
call assert_equal('/fo/ba/foobar', pathshorten('/foo/bar/foobar', 2))
call assert_equal('.fo/bar', pathshorten('.foo/bar', 2))
call assert_equal('~fo/bar', pathshorten('~foo/bar', 2))
call assert_equal('~.fo/bar', pathshorten('~.foo/bar', 2))
call assert_equal('.~fo/bar', pathshorten('.~foo/bar', 2))
call assert_equal('~/fo/bar', pathshorten('~/foo/bar', 2))
call assert_fails('call pathshorten([],2)', 'E730:')
call assert_notequal('~/fo/bar', pathshorten('~/foo/bar', 3))
call assert_equal('~/foo/bar', pathshorten('~/foo/bar', 3))
call assert_equal('~/f/bar', pathshorten('~/foo/bar', 0))
endfunc
func Test_strpart()