patch 8.1.1809: more functions can be used as a method
Problem: More functions can be used as a method.
Solution: Add has_key(), split(), str2list(), etc.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 3b7b901..890b86f 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -995,7 +995,8 @@
#define FEARG_2 2 // base is the second argument
/*
- * Methods that call the internal function with the base as the first argument.
+ * Methods that call the internal function with the base as one of the
+ * arguments.
*/
static funcentry_T base_methods[] =
{
@@ -1011,6 +1012,7 @@
{"extend", 1, 2, 0, f_extend},
{"filter", 1, 1, 0, f_filter},
{"get", 1, 2, 0, f_get},
+ {"has_key", 1, 1, 0, f_has_key},
{"index", 1, 3, 0, f_index},
{"insert", 1, 2, 0, f_insert},
{"items", 0, 0, 0, f_items},
@@ -1024,7 +1026,17 @@
{"repeat", 1, 1, 0, f_repeat},
{"reverse", 0, 0, 0, f_reverse},
{"sort", 0, 2, 0, f_sort},
+ {"split", 0, 2, 0, f_split},
+ {"str2list", 0, 1, 0, f_str2list},
{"string", 0, 0, 0, f_string},
+ {"strlen", 0, 0, 0, f_strlen},
+ {"strtrans", 0, 0, 0, f_strtrans},
+ {"strwidth", 0, 0, 0, f_strwidth},
+ {"substitute", 3, 3, 0, f_substitute},
+ {"synIDattr", 1, 2, 0, f_synIDattr},
+ {"synIDtrans", 0, 0, 0, f_synIDtrans},
+ {"system", 0, 1, 0, f_system},
+ {"systemlist", 0, 2, 0, f_systemlist},
{"type", 0, 0, 0, f_type},
{"uniq", 0, 2, 0, f_uniq},
{"values", 0, 0, 0, f_values},
diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim
index aae8b36..027cdc8 100644
--- a/src/testdir/test_diffmode.vim
+++ b/src/testdir/test_diffmode.vim
@@ -668,13 +668,13 @@
diffthis
redraw
- call assert_equal(synIDattr(diff_hlID(-1, 1), "name"), "")
+ call diff_hlID(-1, 1)->synIDattr("name")->assert_equal("")
- call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange")
- call assert_equal(synIDattr(diff_hlID(1, 2), "name"), "DiffText")
- call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "")
- call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "DiffAdd")
- call assert_equal(synIDattr(diff_hlID(4, 1), "name"), "")
+ call diff_hlID(1, 1)->synIDattr("name")->assert_equal("DiffChange")
+ call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText")
+ call diff_hlID(2, 1)->synIDattr("name")->assert_equal("")
+ call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd")
+ call diff_hlID(4, 1)->synIDattr("name")->assert_equal("")
wincmd w
call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange")
diff --git a/src/testdir/test_method.vim b/src/testdir/test_method.vim
index cc0fe5d..93918c8 100644
--- a/src/testdir/test_method.vim
+++ b/src/testdir/test_method.vim
@@ -46,6 +46,7 @@
call assert_equal(2, d->get('two'))
call assert_fails("let x = d->index(2)", 'E897:')
call assert_fails("let x = d->insert(0)", 'E899:')
+ call assert_true(d->has_key('two'))
call assert_equal([['one', 1], ['two', 2], ['three', 3]], d->items())
call assert_fails("let x = d->join()", 'E714:')
call assert_equal(['one', 'two', 'three'], d->keys())
@@ -65,6 +66,16 @@
call assert_equal([1, 2, 3], d->values())
endfunc
+func Test_string()
+ call assert_equal(['1', '2', '3'], '1 2 3'->split())
+ call assert_equal([1, 2, 3], '1 2 3'->split()->map({i, v -> str2nr(v)}))
+ call assert_equal([65, 66, 67], 'ABC'->str2list())
+ call assert_equal(3, 'ABC'->strlen())
+ call assert_equal('a^Mb^[c', "a\rb\ec"->strtrans())
+ call assert_equal(4, "aあb"->strwidth())
+ call assert_equal('axc', 'abc'->substitute('b', 'x', ''))
+endfunc
+
func Test_append()
new
eval ['one', 'two', 'three']->append(1)
diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim
index 562a44c..a316ce7 100644
--- a/src/testdir/test_syntax.vim
+++ b/src/testdir/test_syntax.vim
@@ -517,8 +517,8 @@
call assert_equal([], synstack(1, 1))
norm f/
- call assert_equal(['cComment', 'cCommentStart'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
- call assert_equal(['Comment', 'Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")'))
+ eval synstack(line("."), col("."))->map('synIDattr(v:val, "name")')->assert_equal(['cComment', 'cCommentStart'])
+ eval synstack(line("."), col("."))->map('synIDattr(synIDtrans(v:val), "name")')->assert_equal(['Comment', 'Comment'])
norm fA
call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")'))
diff --git a/src/testdir/test_system.vim b/src/testdir/test_system.vim
index 25061ea..f09f509 100644
--- a/src/testdir/test_system.vim
+++ b/src/testdir/test_system.vim
@@ -4,13 +4,13 @@
if !executable('echo') || !executable('cat') || !executable('wc')
return
endif
- let out = system('echo 123')
+ let out = 'echo 123'->system()
" On Windows we may get a trailing space.
if out != "123 \n"
call assert_equal("123\n", out)
endif
- let out = systemlist('echo 123')
+ let out = 'echo 123'->systemlist()
" On Windows we may get a trailing space and CR.
if out != ["123 \r"]
call assert_equal(['123'], out)
diff --git a/src/version.c b/src/version.c
index 80e0ce1..83c11ab 100644
--- a/src/version.c
+++ b/src/version.c
@@ -774,6 +774,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1809,
+/**/
1808,
/**/
1807,