vim-patch:7.4.1981 (#6192)

Problem:    No testing for Farsi code.
Solution:   Add a minimal test.  Clean up Farsi code.

ee2615af64
This commit is contained in:
lonerover 2017-03-02 19:47:35 +08:00 committed by Justin M. Keyes
parent 286aacb2aa
commit 8a10497ce6
6 changed files with 306 additions and 223 deletions

View File

@ -486,7 +486,8 @@ char_u* transchar(int c)
c = K_SECOND(c);
}
if ((!chartab_initialized && (((c >= ' ') && (c <= '~')) || F_ischar(c)))
if ((!chartab_initialized && (((c >= ' ') && (c <= '~'))
|| (p_altkeymap && F_ischar(c))))
|| ((c < 256) && vim_isprintc_strict(c))) {
// printable character
transchar_buf[i] = (char_u)c;

View File

@ -131,7 +131,7 @@ static char_u toF_Xor_X_(int c)
/// @param c The character to convert.
///
/// @return Character converted to the Farsi capital leter.
char_u toF_TyA(char_u c)
static char_u toF_TyA(char_u c)
{
char_u tempc;
@ -1557,7 +1557,7 @@ static char_u toF_ending(char_u c)
}
/// Convert the Farsi 3342 standard into Farsi VIM.
void conv_to_pvim(void)
static void conv_to_pvim(void)
{
char_u *ptr;
int lnum, llen, i;
@ -1588,8 +1588,8 @@ void conv_to_pvim(void)
}
// Following lines contains Farsi encoded character.
do_cmdline_cmd("%s/\202\231/\232/g");
do_cmdline_cmd("%s/\201\231/\370\334/g");
do_cmdline_cmd("%s/\202\231/\232/ge");
do_cmdline_cmd("%s/\201\231/\370\334/ge");
// Assume the screen has been messed up: clear it and redraw.
redraw_later(CLEAR);
@ -1597,14 +1597,14 @@ void conv_to_pvim(void)
}
/// Convert the Farsi VIM into Farsi 3342 standard.
void conv_to_pstd(void)
static void conv_to_pstd(void)
{
char_u *ptr;
int lnum, llen, i;
// Following line contains Farsi encoded character.
do_cmdline_cmd("%s/\232/\202\231/g");
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) {
do_cmdline_cmd("%s/\232/\202\231/ge");
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
ptr = ml_get((linenr_T)lnum);
llen = (int)STRLEN(ptr);
for (i = 0; i < llen; i++) {
@ -2036,11 +2036,8 @@ bool F_ischar(int c)
return c >= TEE_ && c <= YE_;
}
void farsi_fkey(cmdarg_T *cap)
void farsi_f8(cmdarg_T *cap FUNC_ATTR_UNUSED)
{
int c = cap->cmdchar;
if (c == K_F8) {
if (p_altkeymap) {
if (curwin->w_farsi & W_R_L) {
p_fkmap = 0;
@ -2056,7 +2053,8 @@ void farsi_fkey(cmdarg_T *cap)
}
}
if (c == K_F9) {
void farsi_f9(cmdarg_T *cap FUNC_ATTR_UNUSED)
{
if (p_altkeymap && curwin->w_p_rl) {
curwin->w_farsi = curwin->w_farsi ^ W_CONV;
if (curwin->w_farsi & W_CONV) {
@ -2066,4 +2064,3 @@ void farsi_fkey(cmdarg_T *cap)
}
}
}
}

View File

@ -280,7 +280,7 @@ static const struct nv_cmd {
{ '}', nv_findpar, 0, FORWARD },
{ '~', nv_tilde, 0, 0 },
/* pound sign */
// pound sign
{ POUND, nv_ident, 0, 0 },
{ K_MOUSEUP, nv_mousescroll, 0, MSCR_UP },
{ K_MOUSEDOWN, nv_mousescroll, 0, MSCR_DOWN },
@ -337,8 +337,8 @@ static const struct nv_cmd {
{ K_F1, nv_help, NV_NCW, 0 },
{ K_XF1, nv_help, NV_NCW, 0 },
{ K_SELECT, nv_select, 0, 0 },
{K_F8, farsi_fkey, 0, 0},
{K_F9, farsi_fkey, 0, 0},
{ K_F8, farsi_f8, 0, 0 },
{ K_F9, farsi_f9, 0, 0 },
{ K_EVENT, nv_event, NV_KEEPREG, 0 },
{ K_FOCUSGAINED, nv_focusgained, NV_KEEPREG, 0 },
{ K_FOCUSLOST, nv_focuslost, NV_KEEPREG, 0 },

View File

@ -34,6 +34,7 @@ NEW_TESTS ?= \
test_cscope.res \
test_digraph.res \
test_diffmode.res \
test_farsi.res \
test_filter_map.res \
test_gn.res \
test_hardcopy.res \

View File

@ -0,0 +1,84 @@
" Simplistic testing of Farsi mode.
if !has('farsi') || has('nvim') " Not supported in Nvim. #6192
finish
endif
" Farsi uses a single byte encoding.
set enc=latin1
func Test_farsi_toggle()
new
set altkeymap
call assert_equal(0, &fkmap)
call assert_equal(0, &rl)
call feedkeys("\<F8>", 'x')
call assert_equal(1, &fkmap)
call assert_equal(1, &rl)
call feedkeys("\<F8>", 'x')
call assert_equal(0, &fkmap)
call assert_equal(0, &rl)
set rl
" conversion from Farsi 3342 to Farsi VIM.
call setline(1, join(map(range(0x80, 0xff), 'nr2char(v:val)'), ''))
call feedkeys("\<F9>", 'x')
let exp = [0xfc, 0xf8, 0xc1, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
\ 0xc8, 0xc9, 0xca, 0xd0, 0xd1, 0xd2, 0xd3, 0xd6,
\ 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd8, 0xd9, 0xda,
\ 0xdb, 0xdc, 0xdc, 0xc1, 0xdd, 0xde, 0xe0, 0xe0,
\ 0xe1, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
\ 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
\ 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
\ 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
\ 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
\ 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
\ 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
\ 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
\ 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
\ 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xfb, 0xfb, 0xfe,
\ 0xfe, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
\ 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xe1,
\ ]
call assert_equal(join(map(exp, 'nr2char(v:val)'), ''), getline(1))
" conversion from Farsi VIM to Farsi 3342.
call setline(1, join(map(range(0x80, 0xff), 'nr2char(v:val)'), ''))
call feedkeys("\<F9>", 'x')
let exp = [0xfc, 0xf8, 0xc1, 0x83, 0x84, 0x85, 0x86, 0x87,
\ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x90,
\ 0x90, 0x90, 0x92, 0x93, 0x93, 0x95, 0x96, 0x97,
\ 0x98, 0xdc, 0x9a, 0x9b, 0x9c, 0x9e, 0x9e, 0xff,
\ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
\ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
\ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
\ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
\ 0xc0, 0xc1, 0xc2, 0x83, 0x84, 0x85, 0x86, 0x87,
\ 0x88, 0x89, 0x8a, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
\ 0x8b, 0x8c, 0x8d, 0x8e, 0xd4, 0xd5, 0x90, 0x93,
\ 0x95, 0x96, 0x97, 0x98, 0x99, 0x9b, 0x9c, 0xdf,
\ 0x9d, 0xff, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
\ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xec, 0xee, 0xef,
\ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
\ 0xf8, 0xf9, 0xfa, 0xec, 0x80, 0xfd, 0xee, 0xff,
\ ]
call assert_equal(join(map(exp, 'nr2char(v:val)'), ''), getline(1))
bwipe!
endfunc
func Test_farsi_map()
new
set altkeymap
set rl
" RHS of mapping is reversed.
imap xyz abc
call feedkeys("axyz\<Esc>", 'tx')
call assert_equal('cba', getline(1))
set norl
iunmap xyz
set noaltkeymap
bwipe!
endfunc

View File

@ -459,7 +459,7 @@ static int included_patches[] = {
1984,
// 1983 NA
// 1982 NA
// 1981,
1981,
1980,
// 1979,
// 1978,