diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-02-24 19:53:53 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-02-24 19:53:53 +0100 |
commit | 6bb2cdfe604e51eec216cbe23bb6e8fb47810347 (patch) | |
tree | 6d8ba5abf32abdd6df606bccd90d76aa359bd718 /src | |
parent | bb008dd3239c5fe3ac04501e38e4c950fa9426c8 (diff) |
patch 8.0.1539: no test for the popup menu positioningv8.0.1539
Problem: No test for the popup menu positioning.
Solution: Add a screendump test for the popup menu.
Diffstat (limited to 'src')
-rw-r--r-- | src/terminal.c | 40 | ||||
-rw-r--r-- | src/testdir/dumps/Test_popup_position_01.dump | 8 | ||||
-rw-r--r-- | src/testdir/dumps/Test_popup_position_02.dump | 8 | ||||
-rw-r--r-- | src/testdir/dumps/Test_popup_position_03.dump | 8 | ||||
-rw-r--r-- | src/testdir/screendump.vim | 20 | ||||
-rw-r--r-- | src/testdir/test_popup.vim | 34 | ||||
-rw-r--r-- | src/testdir/test_syntax.vim | 11 | ||||
-rw-r--r-- | src/version.c | 2 |
8 files changed, 105 insertions, 26 deletions
diff --git a/src/terminal.c b/src/terminal.c index 73554a1066..b6448b1b9f 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1829,7 +1829,7 @@ color2index(VTermColor *color, int fg, int *boldp) switch (color->ansi_index) { case 0: return 0; - case 1: return lookup_color( 0, fg, boldp) + 1; + case 1: return lookup_color( 0, fg, boldp) + 1; /* black */ case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */ case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */ case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ @@ -2872,7 +2872,7 @@ dump_term_color(FILE *fd, VTermColor *color) } /* - * "term_dumpwrite(buf, filename, max-height, max-width)" function + * "term_dumpwrite(buf, filename, options)" function * * Each screen cell in full is: * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx} @@ -2899,8 +2899,8 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED) buf_T *buf = term_get_buf(argvars); term_T *term; char_u *fname; - int max_height = 99999; - int max_width = 99999; + int max_height = 0; + int max_width = 0; stat_T st; FILE *fd; VTermPos pos; @@ -2913,6 +2913,23 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED) return; term = buf->b_term; + if (argvars[2].v_type != VAR_UNKNOWN) + { + dict_T *d; + + if (argvars[2].v_type != VAR_DICT) + { + EMSG(_(e_dictreq)); + return; + } + d = argvars[2].vval.v_dict; + if (d != NULL) + { + max_height = get_dict_number(d, (char_u *)"rows"); + max_width = get_dict_number(d, (char_u *)"columns"); + } + } + fname = get_tv_string_chk(&argvars[1]); if (fname == NULL) return; @@ -2922,13 +2939,6 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED) return; } - if (argvars[2].v_type != VAR_UNKNOWN) - { - max_height = get_tv_number(&argvars[2]); - if (argvars[3].v_type != VAR_UNKNOWN) - max_width = get_tv_number(&argvars[3]); - } - if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL) { EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname); @@ -2938,13 +2948,13 @@ f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED) vim_memset(&prev_cell, 0, sizeof(prev_cell)); screen = vterm_obtain_screen(term->tl_vterm); - for (pos.row = 0; pos.row < max_height && pos.row < term->tl_rows; - ++pos.row) + for (pos.row = 0; (max_height == 0 || pos.row < max_height) + && pos.row < term->tl_rows; ++pos.row) { int repeat = 0; - for (pos.col = 0; pos.col < max_width && pos.col < term->tl_cols; - ++pos.col) + for (pos.col = 0; (max_width == 0 || pos.col < max_width) + && pos.col < term->tl_cols; ++pos.col) { VTermScreenCell cell; int same_attr; diff --git a/src/testdir/dumps/Test_popup_position_01.dump b/src/testdir/dumps/Test_popup_position_01.dump new file mode 100644 index 0000000000..ed341e57b9 --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_01.dump @@ -0,0 +1,8 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a| @30 +|~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| | +0#4040ff13#ffffff0@30 +|~| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| | +0#4040ff13#ffffff0@30 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/dumps/Test_popup_position_02.dump b/src/testdir/dumps/Test_popup_position_02.dump new file mode 100644 index 0000000000..85ae8e8abb --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_02.dump @@ -0,0 +1,8 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a| @30 +|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/dumps/Test_popup_position_03.dump b/src/testdir/dumps/Test_popup_position_03.dump new file mode 100644 index 0000000000..d4f394b445 --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_03.dump @@ -0,0 +1,8 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a| @30 +|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @4| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_ +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @4| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_ +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/screendump.vim b/src/testdir/screendump.vim index a28cb8cb89..584f9ac714 100644 --- a/src/testdir/screendump.vim +++ b/src/testdir/screendump.vim @@ -1,10 +1,23 @@ " Functions shared by tests making screen dumps. " Only load this script once. -if exists('*RunVimInTerminal') +if exists('*CanRunVimInTerminal') finish endif +" Need to be able to run terminal Vim with 256 colors. On MS-Windows the +" console only has 16 colors and the GUI can't run in a terminal. +if !has('terminal') || has('win32') + func CanRunVimInTerminal() + return 0 + endfunc + finish +endif + +func CanRunVimInTerminal() + return 1 +endfunc + source shared.vim " Run Vim with "arguments" in a new terminal window. @@ -41,16 +54,17 @@ func StopVimInTerminal(buf) endfunc " Verify that Vim running in terminal buffer "buf" matches the screen dump. +" "options" is passed to term_dumpwrite(). " The file name used is "dumps/{filename}.dump". " Will wait for up to a second for the screen dump to match. -func VerifyScreenDump(buf, filename) +func VerifyScreenDump(buf, filename, options) let reference = 'dumps/' . a:filename . '.dump' let testfile = a:filename . '.dump.failed' let i = 0 while 1 call delete(testfile) - call term_dumpwrite(a:buf, testfile) + call term_dumpwrite(a:buf, testfile, a:options) if readfile(reference) == readfile(testfile) call delete(testfile) break diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim index d121affc7d..b0024e67bf 100644 --- a/src/testdir/test_popup.vim +++ b/src/testdir/test_popup.vim @@ -1,6 +1,7 @@ " Test for completion menu source shared.vim +source screendump.vim let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] let g:setting = '' @@ -743,4 +744,37 @@ func Test_balloon_split() \ 'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}')) endfunc +func Test_popup_position() + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ '123456789_123456789_123456789_a', + \ '123456789_123456789_123456789_b', + \ ' 123', + \ ], 'Xtest') + let buf = RunVimInTerminal('Xtest', {}) + call term_sendkeys(buf, ":vsplit\<CR>") + + " default pumwidth in left window: overlap in right window + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8}) + call term_sendkeys(buf, "\<Esc>u") + + " default pumwidth: fill until right of window + call term_sendkeys(buf, "\<C-W>l") + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8}) + + " larger pumwidth: used as minimum width + call term_sendkeys(buf, "\<Esc>u") + call term_sendkeys(buf, ":set pumwidth=30\<CR>") + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8}) + + call term_sendkeys(buf, "\<Esc>u") + call StopVimInTerminal(buf) + call delete('Xtest') +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim index ca87ccf66d..e49c8ed895 100644 --- a/src/testdir/test_syntax.vim +++ b/src/testdir/test_syntax.vim @@ -5,9 +5,7 @@ if !has("syntax") endif source view_util.vim -if has('terminal') - source screendump.vim -endif +source screendump.vim func GetSyntaxItem(pat) let c = '' @@ -528,10 +526,7 @@ endfunc " Check highlighting for a small piece of C code with a screen dump. func Test_syntax_c() - " Need to be able to run terminal Vim with 256 colors. - " On MS-Windows the console only has 16 colors and the GUI can't run in a - " terminal. - if !has('terminal') || has('win32') + if !CanRunVimInTerminal() return endif call writefile([ @@ -561,7 +556,7 @@ func Test_syntax_c() let $COLORFGBG = '15;0' let buf = RunVimInTerminal('Xtest.c', {}) - call VerifyScreenDump(buf, 'Test_syntax_c_01') + call VerifyScreenDump(buf, 'Test_syntax_c_01', {}) call StopVimInTerminal(buf) let $COLORFGBG = '' diff --git a/src/version.c b/src/version.c index d434ea1ebc..c75d29033d 100644 --- a/src/version.c +++ b/src/version.c @@ -779,6 +779,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1539, +/**/ 1538, /**/ 1537, |