Mercurial > vim
comparison src/testdir/test_expr.vim @ 19969:b07672d13ff9 v8.2.0540
patch 8.2.0540: regexp and other code not tested
Commit: https://github.com/vim/vim/commit/004a6781b3cf15ca5dd632c38cc09bb3b253d1f8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 11 17:09:31 2020 +0200
patch 8.2.0540: regexp and other code not tested
Problem: Regexp and other code not tested.
Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5904)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 11 Apr 2020 17:15:06 +0200 |
parents | 2c4d9ca33769 |
children | 3601e816a569 |
comparison
equal
deleted
inserted
replaced
19968:1908e92b02fd | 19969:b07672d13ff9 |
---|---|
427 call assert_equal("1001001100101100000001011010010", printf('%b', 1234567890)) | 427 call assert_equal("1001001100101100000001011010010", printf('%b', 1234567890)) |
428 call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345)) | 428 call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345)) |
429 call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1)) | 429 call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1)) |
430 endfunc | 430 endfunc |
431 | 431 |
432 func Test_substitute_expr() | |
433 let g:val = 'XXX' | |
434 call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', '')) | |
435 call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, '')) | |
436 call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', | |
437 \ '\=nr2char("0x" . submatch(1))', 'g')) | |
438 call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', | |
439 \ {-> nr2char("0x" . submatch(1))}, 'g')) | |
440 | |
441 call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)', | |
442 \ {-> submatch(2) . submatch(3) . submatch(1)}, '')) | |
443 | |
444 func Recurse() | |
445 return substitute('yyy', 'y\(.\)y', {-> submatch(1)}, '') | |
446 endfunc | |
447 " recursive call works | |
448 call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, '')) | |
449 | |
450 call assert_fails("let s=submatch([])", 'E745:') | |
451 call assert_fails("let s=submatch(2, [])", 'E745:') | |
452 endfunc | |
453 | |
454 func Test_invalid_submatch() | |
455 " This was causing invalid memory access in Vim-7.4.2232 and older | |
456 call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:') | |
457 endfunc | |
458 | |
459 func Test_substitute_expr_arg() | |
460 call assert_equal('123456789-123456789=', substitute('123456789', | |
461 \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', | |
462 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) | |
463 | |
464 call assert_equal('123456-123456=789', substitute('123456789', | |
465 \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)', | |
466 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) | |
467 | |
468 call assert_equal('123456789-123456789x=', substitute('123456789', | |
469 \ '\(.\)\(.\)\(.*\)', | |
470 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) | |
471 | |
472 call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:') | |
473 call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:') | |
474 call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:') | |
475 call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:') | |
476 endfunc | |
477 | |
478 func Test_function_with_funcref() | 432 func Test_function_with_funcref() |
479 let s:f = function('type') | 433 let s:f = function('type') |
480 let s:fref = function(s:f) | 434 let s:fref = function(s:f) |
481 call assert_equal(v:t_string, s:fref('x')) | 435 call assert_equal(v:t_string, s:fref('x')) |
482 call assert_fails("call function('s:f')", 'E700:') | 436 call assert_fails("call function('s:f')", 'E700:') |