From 133ef7e4654c0a9946825ec7c09aec77a472d4c4 Mon Sep 17 00:00:00 2001 From: watiko Date: Tue, 9 Feb 2016 17:03:27 +0900 Subject: vim-patch:7.4.792 Problem: Can only conceal text by defining syntax items. Solution: Use matchadd() to define concealing. (Christian Brabandt) https://github.com/vim/vim/commit/6561d52ecbe6e24d1b90403078cc8b76c53c42fc --- src/nvim/testdir/Makefile | 1 + src/nvim/testdir/test_match_conceal.in | 159 +++++++++++++++++++++++++++++++++ src/nvim/testdir/test_match_conceal.ok | 52 +++++++++++ 3 files changed, 212 insertions(+) create mode 100644 src/nvim/testdir/test_match_conceal.in create mode 100644 src/nvim/testdir/test_match_conceal.ok (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index d1a7abfbf7..7495508a80 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -29,6 +29,7 @@ SCRIPTS := \ test_close_count.out \ test_command_count.out \ test_marks.out \ + test_match_conceal.out \ NEW_TESTS = diff --git a/src/nvim/testdir/test_match_conceal.in b/src/nvim/testdir/test_match_conceal.in new file mode 100644 index 0000000000..aa32b8582b --- /dev/null +++ b/src/nvim/testdir/test_match_conceal.in @@ -0,0 +1,159 @@ +Test for matchadd() and conceal feature + +STARTTEST +:so small.vim +:if !has("conceal") | e! test.ok | w! test.out | qa! | endif +:set term=ansi +:so mbyte.vim +:if &enc !=? 'utf-8'|:e! test.ok|:w! test.out|qa!|endif +:10new|:vsp|:vert resize 20 +:put =\"\#\ This\ is\ a\ Test\" +:norm! mazt +:fu! ScreenChar(width, lines) +: let c='' +: for j in range(1,a:lines) +: for i in range(1,a:width) +: let c.=nr2char(screenchar(j, i)) +: endfor +: let c.="\n" +: endfor +: return c +:endfu +:fu! ScreenAttr(line, pos, eval) +: let g:attr=[] +: for col in a:pos +: call add(g:attr, screenattr(a:line,col)) +: endfor +: " In case all values are zero, probably the terminal +: " isn't set correctly, so catch that case +: let null = (eval(join(g:attr, '+')) == 0) +: let str=substitute(a:eval, '\d\+', 'g:attr[&]', 'g') +: if null || eval(str) +: :let g:attr_test="OK: ". str +: else +: :let g:attr_test="FAILED: ".str +: :let g:attr_test.="\n". join(g:attr, ' ') +: :let g:attr_test.="\n TERM: ". &term +: endif +:endfu +:fu! DoRecordScreen() +: wincmd l +: $put =printf(\"\n%s\", g:test) +: $put =g:line +: $put =g:attr_test +: wincmd p +:endfu +:let g:test ="Test 1: simple addmatch()" +:call matchadd('Conceal', '\%2l ') +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +: +:let g:test ="Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)" +:norm! 'azt +:call clearmatches() +:syntax on +:set concealcursor=n conceallevel=1 +:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +: +:let g:test ="Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)" +:norm! 'azt +:set conceallevel=3 +:call clearmatches() +:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 1==3 && 1==4 && 0!=5") +:call DoRecordScreen() +: +:let g:test ="Test 4: more match() (should be: #Thisisa Test)" +:norm! 'azt +:call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'}) +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 0!=3 && 3==4 && 0!=5 && 3!=5") +:call DoRecordScreen() +: +:let g:test ="Test 5/1: default conceal char (should be: # This is a Test)" +:norm! 'azt +:call clearmatches() +:set conceallevel=1 +:call matchadd('Conceal', '\%2l ', 10, -1, {}) +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +:let g:test ="Test 5/2: default conceal char (should be: #+This+is+a+Test)" +:norm! 'azt +:set listchars=conceal:+ +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +:set listchars&vim +: +:let g:test ="Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)" +:norm! 'azt +:call clearmatches() +:set conceallevel=1 +:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) +:syn match MyConceal /\%2l / conceal containedin=ALL cchar=* +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +:let g:test ="Test 6/2: syn and match conceal (should be: #*This*is*a*Test)" +:norm! 'azt +:call clearmatches() +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +: +:let g:test ="Test 7/1: clear matches" +:norm! 'azt +:syn on +:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) +:let a=getmatches() +:call clearmatches() +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 0==2 && 0==3 && 0==4 && 0==5") +:call DoRecordScreen() +:$put =a +:call setmatches(a) +:norm! 'azt +:let g:test ="Test 7/2: reset match using setmatches()" +:norm! 'azt +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +: +:let g:test ="Test 8: using matchaddpos() (should be #Pis a Test" +:norm! 'azt +:call clearmatches() +:call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'}) +:let a=getmatches() +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1!=2 && 0==2 && 0==3 && 0!=4 && 0!=5 && 4==5") +:call DoRecordScreen() +:$put =a +: +:let g:test ="Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)" +:norm! 'azt +:call clearmatches() +:call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"}) +:redraw! +:let line=ScreenChar(winwidth(0),1) +:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") +:call DoRecordScreen() +: +:"sleep 10 +:%w! test.out +:qa! +ENDTEST +dummy text diff --git a/src/nvim/testdir/test_match_conceal.ok b/src/nvim/testdir/test_match_conceal.ok new file mode 100644 index 0000000000..11c379e2f8 --- /dev/null +++ b/src/nvim/testdir/test_match_conceal.ok @@ -0,0 +1,52 @@ + +# This is a Test + +Test 1: simple addmatch() +# This is a Test +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest) +#XThisXisXaXTest +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest) +#ThisisaTest +OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]!=g:attr[5] + +Test 4: more match() (should be: #Thisisa Test) +#Thisisa Test +OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[0]!=g:attr[3] && g:attr[3]==g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[3]!=g:attr[5] + +Test 5/1: default conceal char (should be: # This is a Test) +# This is a Test +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 5/2: default conceal char (should be: #+This+is+a+Test) +#+This+is+a+Test +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest) +#ZThisZisZaZTest +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 6/2: syn and match conceal (should be: #*This*is*a*Test) +#*This*is*a*Test +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 7/1: clear matches +# This is a Test +OK: g:attr[0]==g:attr[1] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]==g:attr[4] && g:attr[0]==g:attr[5] +{'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': 10, 'conceal': 'Z'} + +Test 7/2: reset match using setmatches() +#ZThisZisZaZTest +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] + +Test 8: using matchaddpos() (should be #Pis a Test +#Pis a Test +OK: g:attr[0]!=g:attr[1] && g:attr[1]!=g:attr[2] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]!=g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[4]==g:attr[5] +{'group': 'Conceal', 'id': 11, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'} + +Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest) +#ˑThisˑisˑaˑTest +OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] -- cgit From b137ebdd17cd3015fdb1123c2c1d9c54f37e8548 Mon Sep 17 00:00:00 2001 From: watiko Date: Tue, 9 Feb 2016 20:21:16 +0900 Subject: tests: Migrate legacy test match_conceal --- src/nvim/testdir/test_match_conceal.in | 159 --------------------------------- src/nvim/testdir/test_match_conceal.ok | 52 ----------- 2 files changed, 211 deletions(-) delete mode 100644 src/nvim/testdir/test_match_conceal.in delete mode 100644 src/nvim/testdir/test_match_conceal.ok (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_match_conceal.in b/src/nvim/testdir/test_match_conceal.in deleted file mode 100644 index aa32b8582b..0000000000 --- a/src/nvim/testdir/test_match_conceal.in +++ /dev/null @@ -1,159 +0,0 @@ -Test for matchadd() and conceal feature - -STARTTEST -:so small.vim -:if !has("conceal") | e! test.ok | w! test.out | qa! | endif -:set term=ansi -:so mbyte.vim -:if &enc !=? 'utf-8'|:e! test.ok|:w! test.out|qa!|endif -:10new|:vsp|:vert resize 20 -:put =\"\#\ This\ is\ a\ Test\" -:norm! mazt -:fu! ScreenChar(width, lines) -: let c='' -: for j in range(1,a:lines) -: for i in range(1,a:width) -: let c.=nr2char(screenchar(j, i)) -: endfor -: let c.="\n" -: endfor -: return c -:endfu -:fu! ScreenAttr(line, pos, eval) -: let g:attr=[] -: for col in a:pos -: call add(g:attr, screenattr(a:line,col)) -: endfor -: " In case all values are zero, probably the terminal -: " isn't set correctly, so catch that case -: let null = (eval(join(g:attr, '+')) == 0) -: let str=substitute(a:eval, '\d\+', 'g:attr[&]', 'g') -: if null || eval(str) -: :let g:attr_test="OK: ". str -: else -: :let g:attr_test="FAILED: ".str -: :let g:attr_test.="\n". join(g:attr, ' ') -: :let g:attr_test.="\n TERM: ". &term -: endif -:endfu -:fu! DoRecordScreen() -: wincmd l -: $put =printf(\"\n%s\", g:test) -: $put =g:line -: $put =g:attr_test -: wincmd p -:endfu -:let g:test ="Test 1: simple addmatch()" -:call matchadd('Conceal', '\%2l ') -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -: -:let g:test ="Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest)" -:norm! 'azt -:call clearmatches() -:syntax on -:set concealcursor=n conceallevel=1 -:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -: -:let g:test ="Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest)" -:norm! 'azt -:set conceallevel=3 -:call clearmatches() -:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 1==3 && 1==4 && 0!=5") -:call DoRecordScreen() -: -:let g:test ="Test 4: more match() (should be: #Thisisa Test)" -:norm! 'azt -:call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'}) -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 1==2 && 0!=3 && 3==4 && 0!=5 && 3!=5") -:call DoRecordScreen() -: -:let g:test ="Test 5/1: default conceal char (should be: # This is a Test)" -:norm! 'azt -:call clearmatches() -:set conceallevel=1 -:call matchadd('Conceal', '\%2l ', 10, -1, {}) -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -:let g:test ="Test 5/2: default conceal char (should be: #+This+is+a+Test)" -:norm! 'azt -:set listchars=conceal:+ -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -:set listchars&vim -: -:let g:test ="Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest)" -:norm! 'azt -:call clearmatches() -:set conceallevel=1 -:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) -:syn match MyConceal /\%2l / conceal containedin=ALL cchar=* -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -:let g:test ="Test 6/2: syn and match conceal (should be: #*This*is*a*Test)" -:norm! 'azt -:call clearmatches() -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -: -:let g:test ="Test 7/1: clear matches" -:norm! 'azt -:syn on -:call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) -:let a=getmatches() -:call clearmatches() -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0==1 && 0==2 && 0==3 && 0==4 && 0==5") -:call DoRecordScreen() -:$put =a -:call setmatches(a) -:norm! 'azt -:let g:test ="Test 7/2: reset match using setmatches()" -:norm! 'azt -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -: -:let g:test ="Test 8: using matchaddpos() (should be #Pis a Test" -:norm! 'azt -:call clearmatches() -:call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'}) -:let a=getmatches() -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1!=2 && 0==2 && 0==3 && 0!=4 && 0!=5 && 4==5") -:call DoRecordScreen() -:$put =a -: -:let g:test ="Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest)" -:norm! 'azt -:call clearmatches() -:call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"}) -:redraw! -:let line=ScreenChar(winwidth(0),1) -:call ScreenAttr(1,[1,2,7,10,12,16], "0!=1 && 1==2 && 1==3 && 1==4 && 0==5") -:call DoRecordScreen() -: -:"sleep 10 -:%w! test.out -:qa! -ENDTEST -dummy text diff --git a/src/nvim/testdir/test_match_conceal.ok b/src/nvim/testdir/test_match_conceal.ok deleted file mode 100644 index 11c379e2f8..0000000000 --- a/src/nvim/testdir/test_match_conceal.ok +++ /dev/null @@ -1,52 +0,0 @@ - -# This is a Test - -Test 1: simple addmatch() -# This is a Test -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 2: simple addmatch() and conceal (should be: #XThisXisXaXTest) -#XThisXisXaXTest -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 3: addmatch() and conceallevel=3 (should be: #ThisisaTest) -#ThisisaTest -OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]!=g:attr[5] - -Test 4: more match() (should be: #Thisisa Test) -#Thisisa Test -OK: g:attr[0]==g:attr[1] && g:attr[1]==g:attr[2] && g:attr[0]!=g:attr[3] && g:attr[3]==g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[3]!=g:attr[5] - -Test 5/1: default conceal char (should be: # This is a Test) -# This is a Test -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 5/2: default conceal char (should be: #+This+is+a+Test) -#+This+is+a+Test -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 6/1: syn and match conceal (should be: #ZThisZisZaZTest) -#ZThisZisZaZTest -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 6/2: syn and match conceal (should be: #*This*is*a*Test) -#*This*is*a*Test -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 7/1: clear matches -# This is a Test -OK: g:attr[0]==g:attr[1] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]==g:attr[4] && g:attr[0]==g:attr[5] -{'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': 10, 'conceal': 'Z'} - -Test 7/2: reset match using setmatches() -#ZThisZisZaZTest -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] - -Test 8: using matchaddpos() (should be #Pis a Test -#Pis a Test -OK: g:attr[0]!=g:attr[1] && g:attr[1]!=g:attr[2] && g:attr[0]==g:attr[2] && g:attr[0]==g:attr[3] && g:attr[0]!=g:attr[4] && g:attr[0]!=g:attr[5] && g:attr[4]==g:attr[5] -{'group': 'Conceal', 'id': 11, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'} - -Test 9: match using multibyte conceal char (should be: #ˑThisˑisˑaˑTest) -#ˑThisˑisˑaˑTest -OK: g:attr[0]!=g:attr[1] && g:attr[1]==g:attr[2] && g:attr[1]==g:attr[3] && g:attr[1]==g:attr[4] && g:attr[0]==g:attr[5] -- cgit