Hi, Bram, Shougo and list.
2013/1/1(Tue) 13:02:14 UTC+9 Shougo:
> > Thanks, this looks useful.
> >
> >
> >
> > Instead of manual testing, it would be useful to have the tests in
> >
> > src/testdir. Vim is getting more and more complex, it's good to test
> >
> > every feature.
> >
> >
> >
>
> Thank you for the reply. I can add test script but I don't know how to make
> test script for Vim source code.
I wrote a test code. and found small bugs. I fixed this.
({def} may set only valid {bufnr}, {winnr}, {tabnr} spcified.)
(gettabver(1, '', 'def') and gettabver(1, '&nu', 'def') should not return
`def`.)
Attach a patch. (test89 added and code modified)
Please check.
Best regards,
--
Hirohito Higashi
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r b89e2bdcc6e5 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt Sun Dec 16 12:50:40 2012 +0100
+++ b/runtime/doc/eval.txt Wed Jan 02 09:01:40 2013 +0900
@@ -1777,7 +1777,9 @@
get( {dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
getbufline( {expr}, {lnum} [, {end}])
List lines {lnum} to {end} of buffer {expr}
-getbufvar( {expr}, {varname}) any variable {varname} in buffer {expr}
+getbufvar( {expr}, {varname} [, {def}])
+ any variable {varname} in buffer {expr}
+ or {def}
getchar( [expr]) Number get one character from the user
getcharmod( ) Number modifiers for the last typed character
getcmdline() String return the current command-line
@@ -1798,12 +1800,16 @@
getqflist() List list of quickfix items
getreg( [{regname} [, 1]]) String contents of register
getregtype( [{regname}]) String type of register
-gettabvar( {nr}, {varname}) any variable {varname} in tab {nr}
-gettabwinvar( {tabnr}, {winnr}, {name})
+gettabvar( {nr}, {varname} [, {def}])
+ any variable {varname} in tab {nr} or {def}
+gettabwinvar( {tabnr}, {winnr}, {name} [, {def}])
any {name} in {winnr} in tab page {tabnr}
+ or {def}
getwinposx() Number X coord in pixels of GUI Vim window
getwinposy() Number Y coord in pixels of GUI Vim window
-getwinvar( {nr}, {varname}) any variable {varname} in window {nr}
+getwinvar( {nr}, {varname} [, {def}])
+ any variable {varname} in window {nr}
+ or {def}
glob( {expr} [, {nosuf} [, {list}]])
any expand file wildcards in {expr}
globpath( {path}, {expr} [, {flag}])
diff -r b89e2bdcc6e5 src/eval.c
--- a/src/eval.c Sun Dec 16 12:50:40 2012 +0100
+++ b/src/eval.c Wed Jan 02 09:01:40 2013 +0900
@@ -7912,7 +7912,7 @@
{"garbagecollect", 0, 1, f_garbagecollect},
{"get", 2, 3, f_get},
{"getbufline", 2, 3, f_getbufline},
- {"getbufvar", 2, 2, f_getbufvar},
+ {"getbufvar", 2, 3, f_getbufvar},
{"getchar", 0, 1, f_getchar},
{"getcharmod", 0, 0, f_getcharmod},
{"getcmdline", 0, 0, f_getcmdline},
@@ -7932,11 +7932,11 @@
{"getqflist", 0, 0, f_getqflist},
{"getreg", 0, 2, f_getreg},
{"getregtype", 0, 1, f_getregtype},
- {"gettabvar", 2, 2, f_gettabvar},
- {"gettabwinvar", 3, 3, f_gettabwinvar},
+ {"gettabvar", 2, 3, f_gettabvar},
+ {"gettabwinvar", 3, 4, f_gettabwinvar},
{"getwinposx", 0, 0, f_getwinposx},
{"getwinposy", 0, 0, f_getwinposy},
- {"getwinvar", 2, 2, f_getwinvar},
+ {"getwinvar", 2, 3, f_getwinvar},
{"glob", 1, 3, f_glob},
{"globpath", 2, 3, f_globpath},
{"has", 1, 1, f_has},
@@ -11106,6 +11106,8 @@
save_curbuf = curbuf;
curbuf = buf;
+ if (argvars[2].v_type != VAR_UNKNOWN)
+ copy_tv(&argvars[2], rettv);
if (*varname == '&') /* buffer-local-option */
get_option_tv(&varname, rettv, TRUE);
else if (STRCMP(varname, "changedtick") == 0)
@@ -11763,6 +11765,9 @@
tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
if (tp != NULL && varname != NULL)
{
+ if (*varname != NUL && *varname != '&'
+ && argvars[2].v_type != VAR_UNKNOWN)
+ copy_tv(&argvars[2], rettv);
/* look up the variable */
v = find_var_in_ht(&tp->tp_vars.dv_hashtab, varname, FALSE);
if (v != NULL)
@@ -11904,6 +11909,8 @@
get_option_tv(&varname, rettv, 1);
else
{
+ if (argvars[off + 2].v_type != VAR_UNKNOWN)
+ copy_tv(&argvars[off + 2], rettv);
if (*varname == NUL)
/* let getwinvar({nr}, "") return the "w:" dictionary. The
* scope prefix before the NUL byte is required by
diff -r b89e2bdcc6e5 src/testdir/Makefile
--- a/src/testdir/Makefile Sun Dec 16 12:50:40 2012 +0100
+++ b/src/testdir/Makefile Wed Jan 02 09:01:40 2013 +0900
@@ -27,8 +27,8 @@
test69.out test70.out test71.out test72.out test73.out \
test74.out test75.out test76.out test77.out test78.out \
test79.out test80.out test81.out test82.out test83.out \
- test84.out test85.out test86.out test87.out test88.out
-
+ test84.out test85.out test86.out test87.out test88.out \
+ test89.out
SCRIPTS_GUI = test16.out
.SUFFIXES: .in .out
diff -r b89e2bdcc6e5 src/testdir/test89.in
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test89.in Wed Jan 02 09:01:40 2013 +0900
@@ -0,0 +1,98 @@
+Tests for getbufvar(), getwinvar(), gettabvar() and gettabwinvar().
+vim: set ft=vim :
+
+STARTTEST
+:so small.vim
+:"
+:" test for getbufvar()
+:let b:var_num = 1234
+:let def_num = 5678
+:$put =string(getbufvar(1, 'var_num'))
+:$put =string(getbufvar(1, 'var_num', def_num))
+:$put =string(getbufvar(1, ''))
+:$put =string(getbufvar(1, '', def_num))
+:unlet b:var_num
+:$put =string(getbufvar(1, 'var_num', def_num))
+:$put =string(getbufvar(1, ''))
+:$put =string(getbufvar(1, '', def_num))
+:$put =string(getbufvar(9, ''))
+:$put =string(getbufvar(9, '', def_num))
+:unlet def_num
+:$put =string(getbufvar(1, '&autoindent'))
+:$put =string(getbufvar(1, '&autoindent', 1))
+:"
+:" test for getwinvar()
+:let w:var_str = "Dance"
+:let def_str = "Chance"
+:$put =string(getwinvar(1, 'var_str'))
+:$put =string(getwinvar(1, 'var_str', def_str))
+:$put =string(getwinvar(1, ''))
+:$put =string(getwinvar(1, '', def_str))
+:unlet w:var_str
+:$put =string(getwinvar(1, 'var_str', def_str))
+:$put =string(getwinvar(1, ''))
+:$put =string(getwinvar(1, '', def_str))
+:$put =string(getwinvar(9, ''))
+:$put =string(getwinvar(9, '', def_str))
+:$put =string(getwinvar(1, '&nu'))
+:$put =string(getwinvar(1, '&nu', 1))
+:unlet def_str
+:"
+:" test for gettabvar()
+:tabnew
+:tabnew
+:let t:var_list = [1, 2, 3]
+:let def_list = [4, 5, 6, 7]
+:tabrewind
+:$put =string(gettabvar(3, 'var_list'))
+:$put =string(gettabvar(3, 'var_list', def_list))
+:$put =string(gettabvar(3, ''))
+:$put =string(gettabvar(3, '', def_list))
+:tablast
+:unlet t:var_list
+:tabrewind
+:$put =string(gettabvar(3, 'var_list', def_list))
+:$put =string(gettabvar(9, ''))
+:$put =string(gettabvar(9, '', def_list))
+:$put =string(gettabvar(3, '&nu'))
+:$put =string(gettabvar(3, '&nu', def_list))
+:unlet def_list
+:tabonly
+:"
+:" test for gettabwinvar()
+:tabnew
+:tabnew
+:tabprev
+:split
+:split
+:wincmd w
+:vert split
+:wincmd w
+:let w:var_dict = {'dict': 'tabwin'}
+:let def_dict = {'dict2': 'newval'}
+:wincmd b
+:tabrewind
+:$put =string(gettabwinvar(2, 3, 'var_dict'))
+:$put =string(gettabwinvar(2, 3, 'var_dict', def_dict))
+:$put =string(gettabwinvar(2, 3, ''))
+:$put =string(gettabwinvar(2, 3, '', def_dict))
+:tabnext
+:3wincmd w
+:unlet w:var_dict
+:tabrewind
+:$put =string(gettabwinvar(2, 3, 'var_dict', def_dict))
+:$put =string(gettabwinvar(2, 3, ''))
+:$put =string(gettabwinvar(2, 3, '', def_dict))
+:$put =string(gettabwinvar(2, 9, ''))
+:$put =string(gettabwinvar(2, 9, '', def_dict))
+:$put =string(gettabwinvar(9, 3, ''))
+:$put =string(gettabwinvar(9, 3, '', def_dict))
+:unlet def_dict
+:$put =string(gettabwinvar(2, 3, '&nu'))
+:$put =string(gettabwinvar(2, 3, '&nu', 1))
+:tabonly
+:"
+:/^start/,$wq! test.out
+ENDTEST
+
+start:
diff -r b89e2bdcc6e5 src/testdir/test89.ok
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testdir/test89.ok Wed Jan 02 09:01:40 2013 +0900
@@ -0,0 +1,45 @@
+start:
+1234
+1234
+{'var_num': 1234}
+{'var_num': 1234}
+5678
+{}
+{}
+''
+''
+0
+0
+'Dance'
+'Dance'
+{'var_str': 'Dance'}
+{'var_str': 'Dance'}
+'Chance'
+{}
+{}
+''
+''
+0
+0
+[1, 2, 3]
+[1, 2, 3]
+''
+''
+[4, 5, 6, 7]
+''
+''
+''
+''
+{'dict': 'tabwin'}
+{'dict': 'tabwin'}
+{'var_dict': {'dict': 'tabwin'}}
+{'var_dict': {'dict': 'tabwin'}}
+{'dict2': 'newval'}
+{}
+{}
+''
+''
+''
+''
+0
+0