Mercurial > vim
diff src/testdir/test_digraph.vim @ 25294:c626fd34b66f v8.2.3184
patch 8.2.3184: cannot add a digraph with a leading space
Commit: https://github.com/vim/vim/commit/6106504e9edc8500131f7a36e59bc146f90180fa
Author: mityu <mityu.mail@gmail.com>
Date: Mon Jul 19 20:07:21 2021 +0200
patch 8.2.3184: cannot add a digraph with a leading space
Problem: Cannot add a digraph with a leading space. It is not easy to list
existing digraphs.
Solution: Add setdigraph(), setdigraphlist(), getdigraph() and
getdigraphlist(). (closes #8580)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 19 Jul 2021 20:15:04 +0200 |
parents | e0af4660dfc7 |
children | 890fd8211202 |
line wrap: on
line diff
--- a/src/testdir/test_digraph.vim +++ b/src/testdir/test_digraph.vim @@ -214,7 +214,7 @@ func Test_digraphs() call assert_fails('exe "digraph a\<Esc> 100"', 'E104:') call assert_fails('exe "digraph \<Esc>a 100"', 'E104:') call assert_fails('digraph xy z', 'E39:') - call assert_fails('digraph x', 'E474:') + call assert_fails('digraph x', 'E1214:') bw! endfunc @@ -515,4 +515,81 @@ func Test_entering_digraph() call StopVimInTerminal(buf) endfunc +func Test_setdigraph_function() + new + call setdigraph('aa', 'あ') + call Put_Dig('aa') + call assert_equal('あ', getline('$')) + call setdigraph(' i', 'い') + call Put_Dig(' i') + call assert_equal('い', getline('$')) + call setdigraph(' ', 'う') + call Put_Dig(' ') + call assert_equal('う', getline('$')) + + eval 'aa'->setdigraph('え') + call Put_Dig('aa') + call assert_equal('え', getline('$')) + + call assert_fails('call setdigraph("aaa", "あ")', 'E1214: Digraph must be just two characters: aaa') + call assert_fails('call setdigraph("b", "あ")', 'E1214: Digraph must be just two characters: b') + call assert_fails('call setdigraph("あ", "あ")', 'E1214: Digraph must be just two characters: あ') + call assert_fails('call setdigraph("aa", "ああ")', 'E1215: Digraph must be one character: ああ') + call assert_fails('call setdigraph("aa", "か" .. nr2char(0x3099))', 'E1215: Digraph must be one character: か' .. nr2char(0x3099)) + bwipe! +endfunc + +func Test_getdigraph_function() + " Built-in digraphs + call assert_equal('∞', getdigraph('00')) + + " User-defined digraphs + call setdigraph('aa', 'あ') + call setdigraph(' i', 'い') + call setdigraph(' ', 'う') + call assert_equal('あ', getdigraph('aa')) + call assert_equal('あ', 'aa'->getdigraph()) + call assert_equal('い', getdigraph(' i')) + call assert_equal('う', getdigraph(' ')) + call assert_fails('call getdigraph("aaa")', 'E1214: Digraph must be just two characters: aaa') + call assert_fails('call getdigraph("b")', 'E1214: Digraph must be just two characters: b') +endfunc + +func Test_getdigraph_function_encode() + CheckFeature iconv + let testcases = { + \'00': '∞', + \'aa': 'あ', + \} + for [key, ch] in items(testcases) + call setdigraph(key, ch) + set encoding=japan + call assert_equal(iconv(ch, 'utf-8', 'japan'), getdigraph(key)) + set encoding& + endfor +endfunc + +func Test_setdigraphlist_function() + call setdigraphlist([['aa', 'き'], ['bb', 'く']]) + call assert_equal('き', getdigraph('aa')) + call assert_equal('く', getdigraph('bb')) + + call assert_fails('call setdigraphlist([[]])', 'E1216:') + call assert_fails('call setdigraphlist([["aa", "b", "cc"]])', '1216:') + call assert_fails('call setdigraphlist([["あ", "あ"]])', 'E1214: Digraph must be just two characters: あ') +endfunc + +func Test_getdigraphlist_function() + " Make sure user-defined digraphs are defined + call setdigraphlist([['aa', 'き'], ['bb', 'く']]) + + for pair in getdigraphlist(1) + call assert_equal(getdigraph(pair[0]), pair[1]) + endfor + + " We don't know how many digraphs are registered before, so check the number + " of digraphs returned. + call assert_equal(getdigraphlist()->len(), getdigraphlist(0)->len()) + call assert_notequal((getdigraphlist()->len()), getdigraphlist(1)->len()) +endfunc " vim: shiftwidth=2 sts=2 expandtab