vim-patch:8.0.1158: still old style tests

Problem:    Still old style tests.
Solution:   Convert serveral tests to new style. (Yegappan Lakshmanan)

db51007108
This commit is contained in:
Justin M. Keyes 2018-02-02 00:45:08 +01:00
parent 7d12597d29
commit 54b9510e05
7 changed files with 315 additions and 129 deletions

View File

@ -22,7 +22,6 @@ SCRIPTS_DEFAULT = \
test48.out \ test48.out \
test49.out \ test49.out \
test52.out \ test52.out \
test53.out \
test64.out \ test64.out \
test73.out \ test73.out \
test79.out \ test79.out \

View File

@ -1,74 +0,0 @@
Tests for string and html text objects. vim: set ft=vim :
Note that the end-of-line moves the cursor to the next test line.
Also test match() and matchstr()
STARTTEST
/^start:/
da"
0va'a'rx
02f`da`
0fXdi"
03f'vi'ry
:set quoteescape=+*-
di`
$F"va"oha"i"rz
:"
/^<begin
jfXdit
0fXdit
fXdat
0fXdat
dit
:"
:put =matchstr(\"abcd\", \".\", 0, 2) " b
:put =matchstr(\"abcd\", \"..\", 0, 2) " bc
:put =matchstr(\"abcd\", \".\", 2, 0) " c (zero and negative -> first match)
:put =matchstr(\"abcd\", \".\", 0, -1) " a
:put =match(\"abcd\", \".\", 0, 5) " -1
:put =match(\"abcd\", \".\", 0, -1) " 0
:put =match('abc', '.', 0, 1) " 0
:put =match('abc', '.', 0, 2) " 1
:put =match('abc', '.', 0, 3) " 2
:put =match('abc', '.', 0, 4) " -1
:put =match('abc', '.', 1, 1) " 1
:put =match('abc', '.', 2, 1) " 2
:put =match('abc', '.', 3, 1) " -1
:put =match('abc', '$', 0, 1) " 3
:put =match('abc', '$', 0, 2) " -1
:put =match('abc', '$', 1, 1) " 3
:put =match('abc', '$', 2, 1) " 3
:put =match('abc', '$', 3, 1) " 3
:put =match('abc', '$', 4, 1) " -1
:put =match('abc', '\zs', 0, 1) " 0
:put =match('abc', '\zs', 0, 2) " 1
:put =match('abc', '\zs', 0, 3) " 2
:put =match('abc', '\zs', 0, 4) " 3
:put =match('abc', '\zs', 0, 5) " -1
:put =match('abc', '\zs', 1, 1) " 1
:put =match('abc', '\zs', 2, 1) " 2
:put =match('abc', '\zs', 3, 1) " 3
:put =match('abc', '\zs', 4, 1) " -1
:/^start:/,/^end:/wq! test.out
ENDTEST
start: "wo\"rd\\" foo
'foo' 'bar' 'piep'
bla bla `quote` blah
out " in "noXno"
"'" 'blah' rep 'buh'
bla `s*`d-`+++`l**` b`la
voo "nah" sdf " asdf" sdf " sdf" sd
<begin>
-<b>asdf<i>Xasdf</i>asdf</b>-
-<b>asdX<i>a<i />sdf</i>asdf</b>-
-<b>asdf<i>Xasdf</i>asdf</b>-
-<b>asdX<i>as<b />df</i>asdf</b>-
-<b>
innertext object
</b>
</begin>
SEARCH:
end:

View File

@ -1,45 +0,0 @@
start: foo
xxxxxxxxxxxx'piep'
bla bla blah
out " in ""
"'" 'blah'yyyyy'buh'
bla `` b`la
voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd
<begin>
-<b>asdf<i></i>asdf</b>-
-<b></b>-
-<b>asdfasdf</b>-
--
-<b></b>
</begin>
b
bc
c
a
-1
0
0
1
2
-1
1
2
-1
3
-1
3
3
3
-1
0
1
2
3
-1
1
2
3
-1
SEARCH:
end:

View File

@ -0,0 +1,58 @@
" Inserts 2 million lines with consecutive integers starting from 1
" (essentially, the output of GNU's seq 1 2000000), writes them to Xtest
" and writes its cksum to test.out.
"
" We need 2 million lines to trigger a call to mf_hash_grow(). If it would mess
" up the lines the checksum would differ.
"
" cksum is part of POSIX and so should be available on most Unixes.
" If it isn't available then the test will be skipped.
func Test_File_Size()
if !executable('cksum')
return
endif
new
set fileformat=unix undolevels=-1
for i in range(1, 2000000, 100)
call append(i, range(i, i + 99))
endfor
1delete
w! Xtest
let res = systemlist('cksum Xtest')[0]
let res = substitute(res, "\r", "", "")
call assert_equal('3678979763 14888896 Xtest', res)
enew!
call delete('Xtest')
set fileformat& undolevels&
endfunc
" Test for writing and reading a file of over 100 Kbyte
func Test_File_Read_Write()
enew!
" Create a file with the following contents
" 1 line: "This is the start"
" 3001 lines: "This is the leader"
" 1 line: "This is the middle"
" 3001 lines: "This is the trailer"
" 1 line: "This is the end"
call append(0, "This is the start")
call append(1, repeat(["This is the leader"], 3001))
call append(3002, "This is the middle")
call append(3003, repeat(["This is the trailer"], 3001))
call append(6004, "This is the end")
write! Xtest
enew!
edit! Xtest
call assert_equal("This is the start", getline(1))
call assert_equal("This is the middle", getline(3003))
call assert_equal("This is the end", getline(6005))
enew!
call delete("Xtest")
endfunc

View File

@ -0,0 +1,82 @@
" Tests for 'lispwords' settings being global-local
set nocompatible viminfo+=nviminfo
func Test_global_local_lispwords()
setglobal lispwords=foo,bar,baz
setlocal lispwords-=foo | setlocal lispwords+=quux
call assert_equal('foo,bar,baz', &g:lispwords)
call assert_equal('bar,baz,quux', &l:lispwords)
call assert_equal('bar,baz,quux', &lispwords)
setlocal lispwords<
call assert_equal('foo,bar,baz', &g:lispwords)
call assert_equal('foo,bar,baz', &l:lispwords)
call assert_equal('foo,bar,baz', &lispwords)
endfunc
func Test_lisp_indent()
enew!
call append(0, [
\ '(defun html-file (base)',
\ '(format nil "~(~A~).html" base))',
\ '',
\ '(defmacro page (name title &rest body)',
\ '(let ((ti (gensym)))',
\ '`(with-open-file (*standard-output*',
\ '(html-file ,name)',
\ ':direction :output',
\ ':if-exists :supersede)',
\ '(let ((,ti ,title))',
\ '(as title ,ti)',
\ '(with center ',
\ '(as h2 (string-upcase ,ti)))',
\ '(brs 3)',
\ ',@body))))',
\ '',
\ ';;; Utilities for generating links',
\ '',
\ '(defmacro with-link (dest &rest body)',
\ '`(progn',
\ '(format t "<a href=\"~A\">" (html-file ,dest))',
\ ',@body',
\ '(princ "</a>")))'
\ ])
set lisp
set lispwords&
let save_copt = &cpoptions
set cpoptions+=p
normal 1G=G
call assert_equal([
\ '(defun html-file (base)',
\ ' (format nil "~(~A~).html" base))',
\ '',
\ '(defmacro page (name title &rest body)',
\ ' (let ((ti (gensym)))',
\ ' `(with-open-file (*standard-output*',
\ ' (html-file ,name)',
\ ' :direction :output',
\ ' :if-exists :supersede)',
\ ' (let ((,ti ,title))',
\ ' (as title ,ti)',
\ ' (with center ',
\ ' (as h2 (string-upcase ,ti)))',
\ ' (brs 3)',
\ ' ,@body))))',
\ '',
\ ';;; Utilities for generating links',
\ '',
\ '(defmacro with-link (dest &rest body)',
\ ' `(progn',
\ ' (format t "<a href=\"~A\">" (html-file ,dest))',
\ ' ,@body',
\ ' (princ "</a>")))',
\ ''
\ ], getline(1, "$"))
enew!
let &cpoptions=save_copt
set nolisp
endfunc

View File

@ -363,3 +363,59 @@ func Test_search_cmdline4()
call test_override("char_avail", 0) call test_override("char_avail", 0)
bw! bw!
endfunc endfunc
" Tests for regexp with various magic settings
func Test_search_regexp()
enew!
put ='1 a aa abb abbccc'
exe 'normal! /a*b\{2}c\+/e' . "\<CR>"
call assert_equal([0, 2, 17, 0], getpos('.'))
put ='2 d dd dee deefff'
exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>"
call assert_equal([0, 3, 17, 0], getpos('.'))
set nomagic
put ='3 g gg ghh ghhiii'
exe 'normal! /g\*h\{2}i\+/e' . "\<CR>"
call assert_equal([0, 4, 17, 0], getpos('.'))
put ='4 j jj jkk jkklll'
exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>"
call assert_equal([0, 5, 17, 0], getpos('.'))
put ='5 m mm mnn mnnooo'
exe 'normal! /\vm*n{2}o+/e' . "\<CR>"
call assert_equal([0, 6, 17, 0], getpos('.'))
put ='6 x ^aa$ x'
exe 'normal! /\V^aa$' . "\<CR>"
call assert_equal([0, 7, 5, 0], getpos('.'))
set magic
put ='7 (a)(b) abbaa'
exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>"
call assert_equal([0, 8, 14, 0], getpos('.'))
put ='8 axx [ab]xx'
exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>"
call assert_equal([0, 9, 7, 0], getpos('.'))
set undolevels=100
put ='9 foobar'
put =''
exe "normal! a\<C-G>u\<Esc>"
normal G
exe 'normal! dv?bar?' . "\<CR>"
call assert_equal('9 foo', getline('.'))
call assert_equal([0, 10, 5, 0], getpos('.'))
call assert_equal(10, line('$'))
normal u
call assert_equal('9 foobar', getline('.'))
call assert_equal([0, 10, 6, 0], getpos('.'))
call assert_equal(11, line('$'))
set undolevels&
enew!
endfunc

View File

@ -4,8 +4,7 @@ if !has('textobjects')
finish finish
endif endif
set belloff=all func CpoM(line, useM, expected)
function! CpoM(line, useM, expected)
new new
if a:useM if a:useM
@ -29,16 +28,127 @@ function! CpoM(line, useM, expected)
call assert_equal(getreg('"'), a:expected[2]) call assert_equal(getreg('"'), a:expected[2])
q! q!
endfunction endfunc
function! Test_inner_block_without_cpo_M() func Test_inner_block_without_cpo_M()
call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', '']) call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', ''])
endfunction endfunc
function! Test_inner_block_with_cpo_M_left_backslash() func Test_inner_block_with_cpo_M_left_backslash()
call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green']) call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green'])
endfunction endfunc
function! Test_inner_block_with_cpo_M_right_backslash() func Test_inner_block_with_cpo_M_right_backslash()
call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green']) call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green'])
endfunction endfunc
func Test_quote_selection_selection_exclusive()
new
call setline(1, "a 'bcde' f")
set selection=exclusive
exe "norm! fdvhi'y"
call assert_equal('bcde', @")
set selection&vim
bw!
endfunc
" Tests for string and html text objects
func Test_string_html_objects()
enew!
let t = '"wo\"rd\\" foo'
put =t
normal! da"
call assert_equal('foo', getline('.'))
let t = "'foo' 'bar' 'piep'"
put =t
normal! 0va'a'rx
call assert_equal("xxxxxxxxxxxx'piep'", getline('.'))
let t = "bla bla `quote` blah"
put =t
normal! 02f`da`
call assert_equal("bla bla blah", getline('.'))
let t = 'out " in "noXno"'
put =t
normal! 0fXdi"
call assert_equal('out " in ""', getline('.'))
let t = "\"'\" 'blah' rep 'buh'"
put =t
normal! 03f'vi'ry
call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.'))
set quoteescape=+*-
let t = "bla `s*`d-`+++`l**` b`la"
put =t
normal! di`
call assert_equal("bla `` b`la", getline('.'))
let t = 'voo "nah" sdf " asdf" sdf " sdf" sd'
put =t
normal! $F"va"oha"i"rz
call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.'))
let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
put =t
normal! fXdit
call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.'))
let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-"
put =t
normal! 0fXdit
call assert_equal('-<b></b>-', getline('.'))
let t = "-<b>asdf<i>Xasdf</i>asdf</b>-"
put =t
normal! fXdat
call assert_equal('-<b>asdfasdf</b>-', getline('.'))
let t = "-<b>asdX<i>as<b />df</i>asdf</b>-"
put =t
normal! 0fXdat
call assert_equal('--', getline('.'))
let t = "-<b>\ninnertext object\n</b>"
put =t
normal! dit
call assert_equal('-<b></b>', getline('.'))
set quoteescape&
enew!
endfunc
" Tests for match() and matchstr()
func Test_match()
call assert_equal("b", matchstr("abcd", ".", 0, 2))
call assert_equal("bc", matchstr("abcd", "..", 0, 2))
call assert_equal("c", matchstr("abcd", ".", 2, 0))
call assert_equal("a", matchstr("abcd", ".", 0, -1))
call assert_equal(-1, match("abcd", ".", 0, 5))
call assert_equal(0 , match("abcd", ".", 0, -1))
call assert_equal(0 , match('abc', '.', 0, 1))
call assert_equal(1 , match('abc', '.', 0, 2))
call assert_equal(2 , match('abc', '.', 0, 3))
call assert_equal(-1, match('abc', '.', 0, 4))
call assert_equal(1 , match('abc', '.', 1, 1))
call assert_equal(2 , match('abc', '.', 2, 1))
call assert_equal(-1, match('abc', '.', 3, 1))
call assert_equal(3 , match('abc', '$', 0, 1))
call assert_equal(-1, match('abc', '$', 0, 2))
call assert_equal(3 , match('abc', '$', 1, 1))
call assert_equal(3 , match('abc', '$', 2, 1))
call assert_equal(3 , match('abc', '$', 3, 1))
call assert_equal(-1, match('abc', '$', 4, 1))
call assert_equal(0 , match('abc', '\zs', 0, 1))
call assert_equal(1 , match('abc', '\zs', 0, 2))
call assert_equal(2 , match('abc', '\zs', 0, 3))
call assert_equal(3 , match('abc', '\zs', 0, 4))
call assert_equal(-1, match('abc', '\zs', 0, 5))
call assert_equal(1 , match('abc', '\zs', 1, 1))
call assert_equal(2 , match('abc', '\zs', 2, 1))
call assert_equal(3 , match('abc', '\zs', 3, 1))
call assert_equal(-1, match('abc', '\zs', 4, 1))
endfunc