comparison src/testdir/test_functions.vim @ 17829:1090d6637cfd v8.1.1911

patch 8.1.1911: more functions can be used as methods Commit: https://github.com/vim/vim/commit/64b4d73524b9a2304d89b87529cd8d3cef14b856 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 22 22:18:17 2019 +0200 patch 8.1.1911: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make a few more functions usable as a method.
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Aug 2019 22:30:04 +0200
parents 45eca7143d7c
children f71ee7b04f0b
comparison
equal deleted inserted replaced
17828:35e158a08c97 17829:1090d6637cfd
870 call assert_equal([-1, -1, 1, 3, 6, 8, -1], 870 call assert_equal([-1, -1, 1, 3, 6, 8, -1],
871 \ map(range(-1, 5), 'line2byte(v:val)')) 871 \ map(range(-1, 5), 'line2byte(v:val)'))
872 872
873 set fileformat=mac 873 set fileformat=mac
874 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], 874 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
875 \ map(range(-1, 8), 'byte2line(v:val)')) 875 \ map(range(-1, 8), 'v:val->byte2line()'))
876 call assert_equal([-1, -1, 1, 3, 6, 8, -1], 876 call assert_equal([-1, -1, 1, 3, 6, 8, -1],
877 \ map(range(-1, 5), 'line2byte(v:val)')) 877 \ map(range(-1, 5), 'line2byte(v:val)'))
878 878
879 set fileformat=dos 879 set fileformat=dos
880 call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], 880 call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1],
891 call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). 891 call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte).
892 endfor 892 endfor
893 893
894 set endofline& fixendofline& fileformat& 894 set endofline& fixendofline& fileformat&
895 bw! 895 bw!
896 endfunc
897
898 func Test_byteidx()
899 let a = '.é.' " one char of two bytes
900 call assert_equal(0, byteidx(a, 0))
901 call assert_equal(0, byteidxcomp(a, 0))
902 call assert_equal(1, byteidx(a, 1))
903 call assert_equal(1, byteidxcomp(a, 1))
904 call assert_equal(3, byteidx(a, 2))
905 call assert_equal(3, byteidxcomp(a, 2))
906 call assert_equal(4, byteidx(a, 3))
907 call assert_equal(4, byteidxcomp(a, 3))
908 call assert_equal(-1, byteidx(a, 4))
909 call assert_equal(-1, byteidxcomp(a, 4))
910
911 let b = '.é.' " normal e with composing char
912 call assert_equal(0, b->byteidx(0))
913 call assert_equal(1, b->byteidx(1))
914 call assert_equal(4, b->byteidx(2))
915 call assert_equal(5, b->byteidx(3))
916 call assert_equal(-1, b->byteidx(4))
917
918 call assert_equal(0, b->byteidxcomp(0))
919 call assert_equal(1, b->byteidxcomp(1))
920 call assert_equal(2, b->byteidxcomp(2))
921 call assert_equal(4, b->byteidxcomp(3))
922 call assert_equal(5, b->byteidxcomp(4))
923 call assert_equal(-1, b->byteidxcomp(5))
896 endfunc 924 endfunc
897 925
898 func Test_count() 926 func Test_count()
899 let l = ['a', 'a', 'A', 'b'] 927 let l = ['a', 'a', 'A', 'b']
900 call assert_equal(2, count(l, 'a')) 928 call assert_equal(2, count(l, 'a'))
1504 call assert_false(filereadable('Xdir/[a-1]/foo.txt')) 1532 call assert_false(filereadable('Xdir/[a-1]/foo.txt'))
1505 endfunc 1533 endfunc
1506 1534
1507 func Test_call() 1535 func Test_call()
1508 call assert_equal(3, call('len', [123])) 1536 call assert_equal(3, call('len', [123]))
1537 call assert_equal(3, 'len'->call([123]))
1509 call assert_fails("call call('len', 123)", 'E714:') 1538 call assert_fails("call call('len', 123)", 'E714:')
1510 call assert_equal(0, call('', [])) 1539 call assert_equal(0, call('', []))
1511 1540
1512 function Mylen() dict 1541 function Mylen() dict
1513 return len(self.data) 1542 return len(self.data)
1514 endfunction 1543 endfunction
1515 let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} 1544 let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
1545 eval mydict.len->call([], mydict)->assert_equal(4)
1516 call assert_fails("call call('Mylen', [], 0)", 'E715:') 1546 call assert_fails("call call('Mylen', [], 0)", 'E715:')
1517 endfunc 1547 endfunc
1518 1548
1519 func Test_char2nr() 1549 func Test_char2nr()
1520 call assert_equal(12354, char2nr('あ', 1)) 1550 call assert_equal(12354, char2nr('あ', 1))