patch 8.0.0359: 'number' and 'relativenumber' are not properly tested

Problem:    'number' and 'relativenumber' are not properly tested.
Solution:   Add tests, change old style to new style tests. (Ozaki Kiichi,
            closes #1447)
This commit is contained in:
Bram Moolenaar
2017-02-23 18:46:50 +01:00
parent 60629d6425
commit dc9a081712
9 changed files with 288 additions and 103 deletions

View File

@ -2082,7 +2082,7 @@ test1 \
test50 test51 test52 test53 test54 test55 test56 test57 test58 test59 \
test60 test64 test65 test66 test67 test68 test69 \
test70 test72 test73 test74 test75 test77 test78 test79 \
test80 test82 test83 test84 test85 test86 test87 test88 test89 \
test80 test82 test83 test84 test85 test86 test87 test88 \
test90 test91 test94 test95 test97 test98 test99 \
test100 test101 test103 test104 test107 test108:
cd testdir; rm -f $@.out; $(MAKE) -f Makefile $@.out VIMPROG=../$(VIMTARGET) $(GUI_TESTARG) SCRIPTSOURCE=../$(SCRIPTSOURCE)
@ -2122,6 +2122,7 @@ test_arglist \
test_fileformat \
test_filter_cmd \
test_filter_map \
test_findfile \
test_float_func \
test_fnameescape \
test_fnamemodify \
@ -2164,6 +2165,7 @@ test_arglist \
test_nested_function \
test_netbeans \
test_normal \
test_number \
test_options \
test_packadd \
test_partial \

View File

@ -117,8 +117,7 @@ SCRIPTS_MORE4 = \
test59.out \
test72.out \
test78.out \
test83.out \
test89.out
test83.out
# Tests specifically for MS-Windows.
@ -174,6 +173,7 @@ NEW_TESTS = test_arglist.res \
test_nested_function.res \
test_netbeans.res \
test_normal.res \
test_number.res \
test_packadd.res \
test_paste.res \
test_perl.res \

View File

@ -91,7 +91,7 @@ SCRIPT = test1.out test3.out test4.out test5.out \
test66.out test67.out test68.out test69.out \
test72.out test75.out \
test77a.out test78.out test79.out test80.out \
test82.out test84.out test88.out test89.out \
test82.out test84.out test88.out \
test90.out test91.out test94.out \
test95.out test98.out test99.out \
test103.out test104.out \

View File

@ -1,71 +0,0 @@
- Some tests for setting 'number' and 'relativenumber'
This is not all that useful now that the options are no longer reset when
setting the other.
- Some tests for findfile() function
STARTTEST
:so small.vim
:set hidden nocp nu rnu viminfo+=nviminfo
:redir @a | set nu? rnu? | redir END
:e! xx
:redir @b | set nu? rnu? | redir END
:e! #
:$put ='results:'
:$put a
:$put b
:"
:set nonu nornu
:setglobal nu
:setlocal rnu
:redir @c | setglobal nu? | redir END
:set nonu nornu
:setglobal rnu
:setlocal nu
:redir @d | setglobal rnu? | redir END
:$put =':setlocal must NOT reset the other global value'
:$put c
:$put d
:"
:set nonu nornu
:setglobal nu
:setglobal rnu
:redir @e | setglobal nu? | redir END
:set nonu nornu
:setglobal rnu
:setglobal nu
:redir @f | setglobal rnu? | redir END
:$put =':setglobal MUST reset the other global value'
:$put e
:$put f
:"
:set nonu nornu
:set nu
:set rnu
:redir @g | setglobal nu? | redir END
:set nonu nornu
:set rnu
:set nu
:redir @h | setglobal rnu? | redir END
:$put =':set MUST reset the other global value'
:$put g
:$put h
:"
:let cwd=getcwd()
:cd ..
:" Tests may be run from a shadow directory, so an extra cd needs to be done to
:" get above src/
:if fnamemodify(getcwd(), ':t') != 'src' | cd ../.. | else | cd .. | endif
:$put =''
:$put ='Testing findfile'
:$put =''
:set ssl
:$put =findfile('test19.in','src/test*')
:exe "cd" cwd
:cd ..
:$put =findfile('test19.in','test*')
:$put =findfile('test19.in','testdir')
:exe "cd" cwd
:/^results/,$w! test.out
:q!
ENDTEST

View File

@ -1,28 +0,0 @@
results:
number
relativenumber
number
relativenumber
:setlocal must NOT reset the other global value
number
relativenumber
:setglobal MUST reset the other global value
number
relativenumber
:set MUST reset the other global value
number
relativenumber
Testing findfile
src/testdir/test19.in
testdir/test19.in
testdir/test19.in

View File

@ -16,6 +16,7 @@ source test_file_perm.vim
source test_fileformat.vim
source test_filter_cmd.vim
source test_filter_map.vim
source test_findfile.vim
source test_float_func.vim
source test_fnamemodify.vim
source test_functions.vim

View File

@ -0,0 +1,25 @@
" Test for findfile()
"
func Test_findfile()
new
let cwd=getcwd()
cd ..
" Tests may be run from a shadow directory, so an extra cd needs to be done to
" get above src/
if fnamemodify(getcwd(), ':t') != 'src'
cd ../..
else
cd ..
endif
set ssl
call assert_equal('src/testdir/test_findfile.vim', findfile('test_findfile.vim','src/test*'))
exe "cd" cwd
cd ..
call assert_equal('testdir/test_findfile.vim', findfile('test_findfile.vim','test*'))
call assert_equal('testdir/test_findfile.vim', findfile('test_findfile.vim','testdir'))
exe "cd" cwd
q!
endfunc

254
src/testdir/test_number.vim Normal file
View File

@ -0,0 +1,254 @@
" Test for 'number' and 'relativenumber'
source view_util.vim
func! s:screen_lines(start, end) abort
return ScreenLines([a:start, a:end], 8)
endfunc
func! s:compare_lines(expect, actual)
call assert_equal(a:expect, a:actual)
endfunc
func! s:test_windows(h, w) abort
call NewWindow(a:h, a:w)
endfunc
func! s:close_windows() abort
call CloseWindow()
endfunc
func! s:validate_cursor() abort
" update skipcol.
" wincol():
" f_wincol
" -> validate_cursor
" -> curs_columns
call wincol()
endfunc
func Test_set_options()
set nu rnu
call assert_equal(1, &nu)
call assert_equal(1, &rnu)
call s:test_windows(10, 20)
call assert_equal(1, &nu)
call assert_equal(1, &rnu)
call s:close_windows()
set nu& rnu&
endfunc
func Test_set_global_and_local()
" setlocal must NOT reset the other global value
set nonu nornu
setglobal nu
setlocal rnu
call assert_equal(1, &g:nu)
set nonu nornu
setglobal rnu
setlocal nu
call assert_equal(1, &g:rnu)
" setglobal MUST reset the other global value
set nonu nornu
setglobal nu
setglobal rnu
call assert_equal(1, &g:nu)
set nonu nornu
setglobal rnu
setglobal nu
call assert_equal(1, &g:rnu)
" set MUST reset the other global value
set nonu nornu
set nu
set rnu
call assert_equal(1, &g:nu)
set nonu nornu
set rnu
set nu
call assert_equal(1, &g:rnu)
set nu& rnu&
endfunc
func Test_number()
call s:test_windows(10, 20)
call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
setl number
let lines = s:screen_lines(1, 4)
let expect = [
\ " 1 abcd",
\ " 2 klmn",
\ " 3 uvwx",
\ " 4 EFGH",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_relativenumber()
call s:test_windows(10, 20)
call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
3
setl relativenumber
let lines = s:screen_lines(1, 6)
let expect = [
\ " 2 abcd",
\ " 1 klmn",
\ " 0 uvwx",
\ " 1 EFGH",
\ " 2 OPQR",
\ " 3 YZ ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_number_with_relativenumber()
call s:test_windows(10, 20)
call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"])
4
setl number relativenumber
let lines = s:screen_lines(1, 6)
let expect = [
\ " 3 abcd",
\ " 2 klmn",
\ " 1 uvwx",
\ "4 EFGH",
\ " 1 OPQR",
\ " 2 YZ ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_number_with_linewrap1()
call s:test_windows(3, 20)
normal! 61ia
setl number wrap
call s:validate_cursor()
let lines = s:screen_lines(1, 3)
let expect = [
\ "--1 aaaa",
\ " aaaa",
\ " aaaa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI
func XTest_number_with_linewrap2()
call s:test_windows(3, 20)
normal! 61ia
setl number wrap
call s:validate_cursor()
0
call s:validate_cursor()
let lines = s:screen_lines(1, 3)
let expect = [
\ " 1 aaaa",
\ " aaaa",
\ " aaaa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI
func XTest_number_with_linewrap3()
call s:test_windows(4, 20)
normal! 81ia
setl number wrap
call s:validate_cursor()
setl nonumber
call s:validate_cursor()
let lines = s:screen_lines(1, 4)
let expect = [
\ "aaaaaaaa",
\ "aaaaaaaa",
\ "aaaaaaaa",
\ "a ",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_numberwidth()
call s:test_windows(10, 20)
call setline(1, repeat(['aaaa'], 10))
setl number numberwidth=6
let lines = s:screen_lines(1, 3)
let expect = [
\ " 1 aa",
\ " 2 aa",
\ " 3 aa",
\ ]
call s:compare_lines(expect, lines)
set relativenumber
let lines = s:screen_lines(1, 3)
let expect = [
\ "1 aa",
\ " 1 aa",
\ " 2 aa",
\ ]
call s:compare_lines(expect, lines)
set nonumber
let lines = s:screen_lines(1, 3)
let expect = [
\ " 0 aa",
\ " 1 aa",
\ " 2 aa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc
func Test_numberwidth_adjusted()
call s:test_windows(10, 20)
call setline(1, repeat(['aaaa'], 10000))
setl number numberwidth=4
let lines = s:screen_lines(1, 3)
let expect = [
\ " 1 aa",
\ " 2 aa",
\ " 3 aa",
\ ]
call s:compare_lines(expect, lines)
$
let lines = s:screen_lines(8, 10)
let expect = [
\ " 9998 aa",
\ " 9999 aa",
\ "10000 aa",
\ ]
call s:compare_lines(expect, lines)
setl relativenumber
let lines = s:screen_lines(8, 10)
let expect = [
\ " 2 aa",
\ " 1 aa",
\ "10000 aa",
\ ]
call s:compare_lines(expect, lines)
setl nonumber
let lines = s:screen_lines(8, 10)
let expect = [
\ " 2 aaaa",
\ " 1 aaaa",
\ " 0 aaaa",
\ ]
call s:compare_lines(expect, lines)
call s:close_windows()
endfunc

View File

@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
359,
/**/
358,
/**/