Skip to content

Commit 41042f3

Browse files
committed
patch 8.0.0435: some functions are not tested
Problem: Some functions are not tested. Solution: Add more tests for functions. (Dominique Pelle, closes #1541)
1 parent 5f69fee commit 41042f3

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed

src/testdir/test_functions.vim

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ func Test_empty()
2727
call assert_equal(1, empty(v:false))
2828
call assert_equal(0, empty(v:true))
2929

30+
if has('channel')
31+
call assert_equal(1, empty(test_null_channel()))
32+
endif
33+
if has('job')
34+
call assert_equal(1, empty(test_null_job()))
35+
endif
36+
3037
call assert_equal(0, empty(function('Test_empty')))
3138
endfunc
3239

@@ -467,6 +474,247 @@ func Test_getbufvar()
467474
set fileformats&
468475
endfunc
469476

477+
func Test_bufexists()
478+
call assert_equal(0, bufexists('does_not_exist'))
479+
call assert_equal(1, bufexists(bufnr('%')))
480+
call assert_equal(0, bufexists(0))
481+
new Xfoo
482+
let bn = bufnr('%')
483+
call assert_equal(1, bufexists(bn))
484+
call assert_equal(1, bufexists('Xfoo'))
485+
call assert_equal(1, bufexists(getcwd() . '/Xfoo'))
486+
call assert_equal(1, bufexists(0))
487+
bw
488+
call assert_equal(0, bufexists(bn))
489+
call assert_equal(0, bufexists('Xfoo'))
490+
endfunc
491+
492+
func Test_last_buffer_nr()
493+
call assert_equal(bufnr('$'), last_buffer_nr())
494+
endfunc
495+
496+
func Test_stridx()
497+
call assert_equal(-1, stridx('', 'l'))
498+
call assert_equal(0, stridx('', ''))
499+
call assert_equal(0, stridx('hello', ''))
500+
call assert_equal(-1, stridx('hello', 'L'))
501+
call assert_equal(2, stridx('hello', 'l', -1))
502+
call assert_equal(2, stridx('hello', 'l', 0))
503+
call assert_equal(2, stridx('hello', 'l', 1))
504+
call assert_equal(3, stridx('hello', 'l', 3))
505+
call assert_equal(-1, stridx('hello', 'l', 4))
506+
call assert_equal(-1, stridx('hello', 'l', 10))
507+
call assert_equal(2, stridx('hello', 'll'))
508+
call assert_equal(-1, stridx('hello', 'hello world'))
509+
endfunc
510+
511+
func Test_strridx()
512+
call assert_equal(-1, strridx('', 'l'))
513+
call assert_equal(0, strridx('', ''))
514+
call assert_equal(5, strridx('hello', ''))
515+
call assert_equal(-1, strridx('hello', 'L'))
516+
call assert_equal(3, strridx('hello', 'l'))
517+
call assert_equal(3, strridx('hello', 'l', 10))
518+
call assert_equal(3, strridx('hello', 'l', 3))
519+
call assert_equal(2, strridx('hello', 'l', 2))
520+
call assert_equal(-1, strridx('hello', 'l', 1))
521+
call assert_equal(-1, strridx('hello', 'l', 0))
522+
call assert_equal(-1, strridx('hello', 'l', -1))
523+
call assert_equal(2, strridx('hello', 'll'))
524+
call assert_equal(-1, strridx('hello', 'hello world'))
525+
endfunc
526+
527+
func Test_matchend()
528+
call assert_equal(7, matchend('testing', 'ing'))
529+
call assert_equal(7, matchend('testing', 'ing', 2))
530+
call assert_equal(-1, matchend('testing', 'ing', 5))
531+
endfunc
532+
533+
func Test_nextnonblank_prevnonblank()
534+
new
535+
insert
536+
This
537+
538+
539+
is
540+
541+
a
542+
Test
543+
.
544+
call assert_equal(0, nextnonblank(-1))
545+
call assert_equal(0, nextnonblank(0))
546+
call assert_equal(1, nextnonblank(1))
547+
call assert_equal(4, nextnonblank(2))
548+
call assert_equal(4, nextnonblank(3))
549+
call assert_equal(4, nextnonblank(4))
550+
call assert_equal(6, nextnonblank(5))
551+
call assert_equal(6, nextnonblank(6))
552+
call assert_equal(7, nextnonblank(7))
553+
call assert_equal(0, nextnonblank(8))
554+
555+
call assert_equal(0, prevnonblank(-1))
556+
call assert_equal(0, prevnonblank(0))
557+
call assert_equal(1, prevnonblank(1))
558+
call assert_equal(1, prevnonblank(2))
559+
call assert_equal(1, prevnonblank(3))
560+
call assert_equal(4, prevnonblank(4))
561+
call assert_equal(4, prevnonblank(5))
562+
call assert_equal(6, prevnonblank(6))
563+
call assert_equal(7, prevnonblank(7))
564+
call assert_equal(0, prevnonblank(8))
565+
bw!
566+
endfunc
567+
568+
func Test_byte2line_line2byte()
569+
new
570+
call setline(1, ['a', 'bc', 'd'])
571+
572+
set fileformat=unix
573+
call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
574+
\ map(range(-1, 8), 'byte2line(v:val)'))
575+
call assert_equal([-1, -1, 1, 3, 6, 8, -1],
576+
\ map(range(-1, 5), 'line2byte(v:val)'))
577+
578+
set fileformat=mac
579+
call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
580+
\ map(range(-1, 8), 'byte2line(v:val)'))
581+
call assert_equal([-1, -1, 1, 3, 6, 8, -1],
582+
\ map(range(-1, 5), 'line2byte(v:val)'))
583+
584+
set fileformat=dos
585+
call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1],
586+
\ map(range(-1, 11), 'byte2line(v:val)'))
587+
call assert_equal([-1, -1, 1, 4, 8, 11, -1],
588+
\ map(range(-1, 5), 'line2byte(v:val)'))
589+
590+
set fileformat&
591+
bw!
592+
endfunc
593+
594+
func Test_count()
595+
let l = ['a', 'a', 'A', 'b']
596+
call assert_equal(2, count(l, 'a'))
597+
call assert_equal(1, count(l, 'A'))
598+
call assert_equal(1, count(l, 'b'))
599+
call assert_equal(0, count(l, 'B'))
600+
601+
call assert_equal(2, count(l, 'a', 0))
602+
call assert_equal(1, count(l, 'A', 0))
603+
call assert_equal(1, count(l, 'b', 0))
604+
call assert_equal(0, count(l, 'B', 0))
605+
606+
call assert_equal(3, count(l, 'a', 1))
607+
call assert_equal(3, count(l, 'A', 1))
608+
call assert_equal(1, count(l, 'b', 1))
609+
call assert_equal(1, count(l, 'B', 1))
610+
call assert_equal(0, count(l, 'c', 1))
611+
612+
call assert_equal(1, count(l, 'a', 0, 1))
613+
call assert_equal(2, count(l, 'a', 1, 1))
614+
call assert_fails('call count(l, "a", 0, 10)', 'E684:')
615+
616+
let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'}
617+
call assert_equal(2, count(d, 'a'))
618+
call assert_equal(1, count(d, 'A'))
619+
call assert_equal(1, count(d, 'b'))
620+
call assert_equal(0, count(d, 'B'))
621+
622+
call assert_equal(2, count(d, 'a', 0))
623+
call assert_equal(1, count(d, 'A', 0))
624+
call assert_equal(1, count(d, 'b', 0))
625+
call assert_equal(0, count(d, 'B', 0))
626+
627+
call assert_equal(3, count(d, 'a', 1))
628+
call assert_equal(3, count(d, 'A', 1))
629+
call assert_equal(1, count(d, 'b', 1))
630+
call assert_equal(1, count(d, 'B', 1))
631+
call assert_equal(0, count(d, 'c', 1))
632+
633+
call assert_fails('call count(d, "a", 0, 1)', 'E474:')
634+
call assert_fails('call count("a", "a")', 'E712:')
635+
endfunc
636+
637+
func Test_changenr()
638+
new Xchangenr
639+
call assert_equal(0, changenr())
640+
norm ifoo
641+
call assert_equal(1, changenr())
642+
set undolevels=10
643+
norm Sbar
644+
call assert_equal(2, changenr())
645+
undo
646+
call assert_equal(1, changenr())
647+
redo
648+
call assert_equal(2, changenr())
649+
bw!
650+
set undolevels&
651+
endfunc
652+
653+
func Test_filewritable()
654+
new Xfilewritable
655+
write!
656+
call assert_equal(1, filewritable('Xfilewritable'))
657+
658+
call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----'))
659+
call assert_equal(0, filewritable('Xfilewritable'))
660+
661+
call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----'))
662+
call assert_equal(1, filewritable('Xfilewritable'))
663+
664+
call assert_equal(0, filewritable('doesnotexist'))
665+
666+
call delete('Xfilewritable')
667+
bw!
668+
endfunc
669+
670+
func Test_hostname()
671+
let hostname_vim = hostname()
672+
if has('unix')
673+
let hostname_system = systemlist('uname -n')[0]
674+
call assert_equal(hostname_vim, hostname_system)
675+
endif
676+
endfunc
677+
678+
func Test_getpid()
679+
" getpid() always returns the same value within a vim instance.
680+
call assert_equal(getpid(), getpid())
681+
if has('unix')
682+
call assert_equal(systemlist('echo $PPID')[0], string(getpid()))
683+
endif
684+
endfunc
685+
686+
func Test_hlexists()
687+
call assert_equal(0, hlexists('does_not_exist'))
688+
call assert_equal(0, hlexists('Number'))
689+
call assert_equal(0, highlight_exists('does_not_exist'))
690+
call assert_equal(0, highlight_exists('Number'))
691+
syntax on
692+
call assert_equal(0, hlexists('does_not_exist'))
693+
call assert_equal(1, hlexists('Number'))
694+
call assert_equal(0, highlight_exists('does_not_exist'))
695+
call assert_equal(1, highlight_exists('Number'))
696+
syntax off
697+
endfunc
698+
699+
func Test_col()
700+
new
701+
call setline(1, 'abcdef')
702+
norm gg4|mx6|mY2|
703+
call assert_equal(2, col('.'))
704+
call assert_equal(7, col('$'))
705+
call assert_equal(4, col("'x"))
706+
call assert_equal(6, col("'Y"))
707+
call assert_equal(2, col([1, 2]))
708+
call assert_equal(7, col([1, '$']))
709+
710+
call assert_equal(0, col(''))
711+
call assert_equal(0, col('x'))
712+
call assert_equal(0, col([2, '$']))
713+
call assert_equal(0, col([1, 100]))
714+
call assert_equal(0, col([1]))
715+
bw!
716+
endfunc
717+
470718
func Test_balloon_show()
471719
if has('balloon_eval')
472720
" This won't do anything but must not crash either.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
435,
767769
/**/
768770
434,
769771
/**/

0 commit comments

Comments
 (0)