From 2a2175837c0d0675323b79bb8c0bd4446e92806d Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 10 Apr 2016 18:46:29 +0900 Subject: [PATCH] Convert test_match_conceal.in to new style test --- src/testdir/test_matchadd_conceal.vim | 276 +++++++++++++++++++++++++- src/testdir/test_undolevels.vim | 3 + 2 files changed, 276 insertions(+), 3 deletions(-) diff --git a/src/testdir/test_matchadd_conceal.vim b/src/testdir/test_matchadd_conceal.vim index 334f3d442a1b5d..c799effe5949e2 100644 --- a/src/testdir/test_matchadd_conceal.vim +++ b/src/testdir/test_matchadd_conceal.vim @@ -2,6 +2,24 @@ if !has('conceal') finish endif +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 + function! s:screenline(lnum) abort let line = [] for c in range(1, winwidth(0)) @@ -14,9 +32,261 @@ function! s:trim(str) abort return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$') endfunction -function! Test_matchadd_conceal() - " quit! all other windows - silent! only! +function! Test_simple_matchadd() + new + + 1put='# This is a Test' + " 1234567890123456 + let expect = '# This is a Test' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ') + redraw! + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + quit! +endfunction + +function! Test_simple_matchadd_and_conceal() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#XThisXisXaXTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) + redraw! + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + quit! +endfunction + +function! Test_matchadd_and_conceallevel_3() + new + + setlocal conceallevel=3 + " set filetype and :syntax on to change screenattr() + setlocal filetype=conf + syntax on + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#ThisisaTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) + redraw! + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 16)) + + " more matchadd() + " 1234567890123456 + let expect = '#Thisisa Test' + + call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'}) + redraw! + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 10) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 16)) + call assert_true(screenattr(lnum, 10) !=# screenattr(lnum, 16)) + + syntax off + quit! +endfunction + +function! Test_default_conceal_char() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '# This is a Test' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {}) + redraw! + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + " 1234567890123456 + let expect = '#+This+is+a+Test' + let listchars_save = &listchars + set listchars=conceal:+ + redraw! + + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + let &listchars = listchars_save + quit! +endfunction + +function! Test_syn_and_match_conceal() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#ZThisZisZaZTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) + syntax match MyConceal /\%2l / conceal containedin=ALL cchar=* + redraw! + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + " 1234567890123456 + let expect = '#*This*is*a*Test' + call clearmatches() + redraw! + + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + syntax off + quit! +endfunction + +function! Test_clearmatches() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '# This is a Test' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) + let a = getmatches() + call clearmatches() + redraw! + + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + " reset match using setmatches() + " 1234567890123456 + let expect = '#ZThisZisZaZTest' + call setmatches(a) + redraw! + + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + call assert_equal({'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': a[0].id, 'conceal': 'Z'}, a[0]) + + quit! +endfunction + +function! Test_using_matchaddpos() + new + setlocal concealcursor=n conceallevel=1 + " set filetype and :syntax on to change screenattr() + setlocal filetype=conf + syntax on + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#Pis a Test' + + call cursor(1, 1) + call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'}) + let a = getmatches() + redraw! + + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) !=# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 16)) + call assert_true(screenattr(lnum, 12) ==# screenattr(lnum, 16)) + call assert_equal({'group': 'Conceal', 'id': a[0].id, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'}, a[0]) + + syntax off + quit! +endfunction + +function! Test_match_using_multibyte_conceal_char() + so mbyte.vim + if &enc !=? 'utf-8' + return + endif + + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#ˑThisˑisˑaˑTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"}) + redraw! + + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_true(screenattr(lnum, 1) !=# screenattr(lnum, 2)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 7)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 10)) + call assert_true(screenattr(lnum, 2) ==# screenattr(lnum, 12)) + call assert_true(screenattr(lnum, 1) ==# screenattr(lnum, 16)) + + quit! +endfunction + +function! Test_matchadd_repeat_conceal_without_syntax() new " To test targets in the same line string is replaced with conceal char diff --git a/src/testdir/test_undolevels.vim b/src/testdir/test_undolevels.vim index 7bb25effb5297d..5da14b5b70e1b7 100644 --- a/src/testdir/test_undolevels.vim +++ b/src/testdir/test_undolevels.vim @@ -41,4 +41,7 @@ func Test_global_local_undolevels() call assert_equal(50, &g:undolevels) call assert_equal(-123456, &l:undolevels) + " Drop created windows + new + only! endfunc