Mercurial > vim
comparison src/testdir/test_quickfix.vim @ 21409:2c40e60017a8 v8.2.1255
patch 8.2.1255: cannot use a lambda with quickfix functions
Commit: https://github.com/vim/vim/commit/d43906d2e5969288f239df851f5ad7b1dc2c7251
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jul 20 21:31:32 2020 +0200
patch 8.2.1255: cannot use a lambda with quickfix functions
Problem: Cannot use a lambda with quickfix functions.
Solution: Add support for lambda. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/6499)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 20 Jul 2020 21:45:04 +0200 |
parents | 6a4806e326dd |
children | 0843f244e547 |
comparison
equal
deleted
inserted
replaced
21408:233bc1a5e828 | 21409:2c40e60017a8 |
---|---|
3488 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) | 3488 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) |
3489 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick) | 3489 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick) |
3490 if a:cchar == 'c' | 3490 if a:cchar == 'c' |
3491 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, | 3491 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, |
3492 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0, | 3492 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0, |
3493 \ 'title' : '', 'winid' : 0, 'changedtick': 0}, | 3493 \ 'title' : '', 'winid' : 0, 'changedtick': 0, |
3494 \ g:Xgetlist({'all' : 0})) | 3494 \ 'quickfixtextfunc' : ''}, g:Xgetlist({'all' : 0})) |
3495 else | 3495 else |
3496 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, | 3496 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, |
3497 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', | 3497 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', |
3498 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0, | 3498 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0, |
3499 \ 'qfbufnr' : 0}, | 3499 \ 'qfbufnr' : 0, 'quickfixtextfunc' : ''}, |
3500 \ g:Xgetlist({'all' : 0})) | 3500 \ g:Xgetlist({'all' : 0})) |
3501 endif | 3501 endif |
3502 | 3502 |
3503 " Quickfix window with empty stack | 3503 " Quickfix window with empty stack |
3504 silent! Xopen | 3504 silent! Xopen |
3533 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid) | 3533 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid) |
3534 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick) | 3534 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick) |
3535 if a:cchar == 'c' | 3535 if a:cchar == 'c' |
3536 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], | 3536 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
3537 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, | 3537 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
3538 \ 'qfbufnr' : qfbufnr, | 3538 \ 'qfbufnr' : qfbufnr, 'quickfixtextfunc' : '', |
3539 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0})) | 3539 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0})) |
3540 else | 3540 else |
3541 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], | 3541 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
3542 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, | 3542 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
3543 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0}, | 3543 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0, |
3544 \ 'quickfixtextfunc' : ''}, | |
3544 \ g:Xgetlist({'id' : qfid, 'all' : 0})) | 3545 \ g:Xgetlist({'id' : qfid, 'all' : 0})) |
3545 endif | 3546 endif |
3546 | 3547 |
3547 " Non-existing quickfix list number | 3548 " Non-existing quickfix list number |
3548 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context) | 3549 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context) |
3555 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid) | 3556 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid) |
3556 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick) | 3557 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick) |
3557 if a:cchar == 'c' | 3558 if a:cchar == 'c' |
3558 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], | 3559 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
3559 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, | 3560 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
3560 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr}, | 3561 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr, |
3561 \ g:Xgetlist({'nr' : 5, 'all' : 0})) | 3562 \ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0})) |
3562 else | 3563 else |
3563 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], | 3564 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], |
3564 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, | 3565 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, |
3565 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0}, | 3566 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0, |
3566 \ g:Xgetlist({'nr' : 5, 'all' : 0})) | 3567 \ 'quickfixtextfunc' : ''}, g:Xgetlist({'nr' : 5, 'all' : 0})) |
3567 endif | 3568 endif |
3568 endfunc | 3569 endfunc |
3569 | 3570 |
3570 func Test_getqflist() | 3571 func Test_getqflist() |
3571 call Xgetlist_empty_tests('c') | 3572 call Xgetlist_empty_tests('c') |
4863 func Xtest_qftextfunc(cchar) | 4864 func Xtest_qftextfunc(cchar) |
4864 call s:setup_commands(a:cchar) | 4865 call s:setup_commands(a:cchar) |
4865 | 4866 |
4866 set efm=%f:%l:%c:%m | 4867 set efm=%f:%l:%c:%m |
4867 set quickfixtextfunc=Tqfexpr | 4868 set quickfixtextfunc=Tqfexpr |
4869 call assert_equal('Tqfexpr', &quickfixtextfunc) | |
4870 call assert_equal('', | |
4871 \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) | |
4868 Xexpr ['F1:10:2:green', 'F1:20:4:blue'] | 4872 Xexpr ['F1:10:2:green', 'F1:20:4:blue'] |
4869 Xwindow | 4873 Xwindow |
4870 call assert_equal('F1-L10C2-green', getline(1)) | 4874 call assert_equal('F1-L10C2-green', getline(1)) |
4871 call assert_equal('F1-L20C4-blue', getline(2)) | 4875 call assert_equal('F1-L20C4-blue', getline(2)) |
4872 Xclose | 4876 Xclose |
4899 Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] | 4903 Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] |
4900 Xwindow | 4904 Xwindow |
4901 call assert_equal('Line 10, Col 2', getline(1)) | 4905 call assert_equal('Line 10, Col 2', getline(1)) |
4902 call assert_equal('Line 20, Col 4', getline(2)) | 4906 call assert_equal('Line 20, Col 4', getline(2)) |
4903 Xclose | 4907 Xclose |
4908 call assert_equal(function('PerQfText'), | |
4909 \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) | |
4904 " Add entries to the list when the quickfix buffer is hidden | 4910 " Add entries to the list when the quickfix buffer is hidden |
4905 Xaddexpr ['F1:30:6:red'] | 4911 Xaddexpr ['F1:30:6:red'] |
4906 Xwindow | 4912 Xwindow |
4907 call assert_equal('Line 30, Col 6', getline(3)) | 4913 call assert_equal('Line 30, Col 6', getline(3)) |
4908 Xclose | 4914 Xclose |
4909 call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''}) | 4915 call g:Xsetlist([], 'r', {'quickfixtextfunc' : ''}) |
4916 call assert_equal('', g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) | |
4910 set quickfixtextfunc& | 4917 set quickfixtextfunc& |
4911 delfunc PerQfText | 4918 delfunc PerQfText |
4912 | 4919 |
4913 " Non-existing function | 4920 " Non-existing function |
4914 set quickfixtextfunc=Tabc | 4921 set quickfixtextfunc=Tabc |
4939 endfunc | 4946 endfunc |
4940 set quickfixtextfunc=Xqftext2 | 4947 set quickfixtextfunc=Xqftext2 |
4941 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']", | 4948 call assert_fails("Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']", |
4942 \ 'E730:') | 4949 \ 'E730:') |
4943 call assert_fails('Xwindow', 'E730:') | 4950 call assert_fails('Xwindow', 'E730:') |
4944 call assert_equal(['one', 'F1|20 col 4| blue', 'two'], getline(1, '$')) | 4951 call assert_equal(['one', 'F1|20 col 4| blue', 'F1|30 col 6| red'], |
4952 \ getline(1, '$')) | |
4945 Xclose | 4953 Xclose |
4946 | 4954 |
4947 set quickfixtextfunc& | 4955 set quickfixtextfunc& |
4948 delfunc Xqftext | 4956 delfunc Xqftext |
4949 delfunc Xqftext2 | 4957 delfunc Xqftext2 |
4958 | |
4959 " set the global option to a lambda function | |
4960 set quickfixtextfunc={d\ ->\ map(g:Xgetlist({'id'\ :\ d.id,\ 'items'\ :\ 1}).items[d.start_idx-1:d.end_idx-1],\ 'v:val.text')} | |
4961 Xexpr ['F1:10:2:green', 'F1:20:4:blue'] | |
4962 Xwindow | |
4963 call assert_equal(['green', 'blue'], getline(1, '$')) | |
4964 Xclose | |
4965 call assert_equal("{d -> map(g:Xgetlist({'id' : d.id, 'items' : 1}).items[d.start_idx-1:d.end_idx-1], 'v:val.text')}", &quickfixtextfunc) | |
4966 set quickfixtextfunc& | |
4967 | |
4968 " use a lambda function that returns an empty list | |
4969 set quickfixtextfunc={d\ ->\ []} | |
4970 Xexpr ['F1:10:2:green', 'F1:20:4:blue'] | |
4971 Xwindow | |
4972 call assert_equal(['F1|10 col 2| green', 'F1|20 col 4| blue'], | |
4973 \ getline(1, '$')) | |
4974 Xclose | |
4975 set quickfixtextfunc& | |
4976 | |
4977 " use a lambda function that returns a list with empty strings | |
4978 set quickfixtextfunc={d\ ->\ ['',\ '']} | |
4979 Xexpr ['F1:10:2:green', 'F1:20:4:blue'] | |
4980 Xwindow | |
4981 call assert_equal(['F1|10 col 2| green', 'F1|20 col 4| blue'], | |
4982 \ getline(1, '$')) | |
4983 Xclose | |
4984 set quickfixtextfunc& | |
4985 | |
4986 " set the per-quickfix list text function to a lambda function | |
4987 call g:Xsetlist([], ' ', | |
4988 \ {'quickfixtextfunc' : | |
4989 \ {d -> map(g:Xgetlist({'id' : d.id, 'items' : 1}).items[d.start_idx-1:d.end_idx-1], | |
4990 \ "'Line ' .. v:val.lnum .. ', Col ' .. v:val.col")}}) | |
4991 Xaddexpr ['F1:10:2:green', 'F1:20:4:blue'] | |
4992 Xwindow | |
4993 call assert_equal('Line 10, Col 2', getline(1)) | |
4994 call assert_equal('Line 20, Col 4', getline(2)) | |
4995 Xclose | |
4996 call assert_match("function('<lambda>\\d\\+')", string(g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc)) | |
4997 call g:Xsetlist([], 'f') | |
4950 endfunc | 4998 endfunc |
4951 | 4999 |
4952 func Test_qftextfunc() | 5000 func Test_qftextfunc() |
4953 call Xtest_qftextfunc('c') | 5001 call Xtest_qftextfunc('c') |
4954 call Xtest_qftextfunc('l') | 5002 call Xtest_qftextfunc('l') |