Mercurial > vim
changeset 11603:4e66689bced6 v8.0.0684
patch 8.0.0684: old style tests are not nice
commit https://github.com/vim/vim/commit/28b238225ae618f63cfe5d3d723120960a941da7
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 27 18:29:17 2017 +0200
patch 8.0.0684: old style tests are not nice
Problem: Old style tests are not nice.
Solution: Turn two tests into new style. (pschuh, closes https://github.com/vim/vim/issues/1797)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 27 Jun 2017 18:30:03 +0200 |
parents | f36644d90543 |
children | ba60f4a8956b |
files | src/Makefile src/testdir/Make_all.mak src/testdir/Make_vms.mms src/testdir/test82.in src/testdir/test82.ok src/testdir/test90.in src/testdir/test90.ok src/testdir/test_sha256.vim src/testdir/test_utf8_comparisons.vim src/version.c |
diffstat | 10 files changed, 125 insertions(+), 173 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Makefile +++ b/src/Makefile @@ -2089,8 +2089,8 @@ test1 \ test50 test51 test52 test53 test54 test55 test56 test57 test59 \ test60 test64 test66 test67 test68 test69 \ test70 test72 test73 test74 test75 test77 test78 test79 \ - test80 test82 test83 test84 test85 test86 test87 test88 \ - test90 test91 test94 test95 test97 test98 test99 \ + test80 test83 test84 test85 test86 test87 test88 \ + 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) @@ -2207,6 +2207,7 @@ test_arglist \ test_search \ test_searchpos \ test_set \ + test_sha256 \ test_signs \ test_smartindent \ test_sort \ @@ -2233,6 +2234,7 @@ test_arglist \ test_unlet \ test_usercommands \ test_utf8 \ + test_utf8_comparisons \ test_viminfo \ test_vimscript \ test_visual \
--- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -60,10 +60,8 @@ SCRIPTS_ALL = \ test77.out \ test79.out \ test80.out \ - test82.out \ test84.out \ test88.out \ - test90.out \ test91.out \ test94.out \ test95.out \
--- a/src/testdir/Make_vms.mms +++ b/src/testdir/Make_vms.mms @@ -91,8 +91,8 @@ SCRIPT = test1.out test3.out test4.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 \ - test90.out test91.out test94.out \ + test84.out test88.out \ + test91.out test94.out \ test95.out test98.out test99.out \ test103.out test104.out \ test107.out test108.out\
deleted file mode 100644 --- a/src/testdir/test82.in +++ /dev/null @@ -1,103 +0,0 @@ -Tests for case-insensitive UTF-8 comparisons (utf_strnicmp() in mbyte.c) -Also test "g~ap". - -STARTTEST -:so small.vim -:if !has("multi_byte") -: e! test.ok -: w! test.out -: qa! -:endif -:set enc=utf8 -ggdG: -: -:function! Ch(a, op, b, expected) -: if eval(printf('"%s" %s "%s"', a:a, a:op, a:b)) != a:expected -: call append(line('$'), printf('"%s" %s "%s" should return %d', a:a, a:op, a:b, a:expected)) -: else -: let b:passed += 1 -: endif -:endfunction -: -:function! Chk(a, b, result) -: if a:result == 0 -: call Ch(a:a, '==?', a:b, 1) -: call Ch(a:a, '!=?', a:b, 0) -: call Ch(a:a, '<=?', a:b, 1) -: call Ch(a:a, '>=?', a:b, 1) -: call Ch(a:a, '<?', a:b, 0) -: call Ch(a:a, '>?', a:b, 0) -: elseif a:result > 0 -: call Ch(a:a, '==?', a:b, 0) -: call Ch(a:a, '!=?', a:b, 1) -: call Ch(a:a, '<=?', a:b, 0) -: call Ch(a:a, '>=?', a:b, 1) -: call Ch(a:a, '<?', a:b, 0) -: call Ch(a:a, '>?', a:b, 1) -: else -: call Ch(a:a, '==?', a:b, 0) -: call Ch(a:a, '!=?', a:b, 1) -: call Ch(a:a, '<=?', a:b, 1) -: call Ch(a:a, '>=?', a:b, 0) -: call Ch(a:a, '<?', a:b, 1) -: call Ch(a:a, '>?', a:b, 0) -: endif -:endfunction -: -:function! Check(a, b, result) -: call Chk(a:a, a:b, a:result) -: call Chk(a:b, a:a, -a:result) -:endfunction -: -:function! LT(a, b) -: call Check(a:a, a:b, -1) -:endfunction -: -:function! GT(a, b) -: call Check(a:a, a:b, 1) -:endfunction -: -:function! EQ(a, b) -: call Check(a:a, a:b, 0) -:endfunction -: -:let b:passed=0 -:call EQ('', '') -:call LT('', 'a') -:call EQ('abc', 'abc') -:call EQ('Abc', 'abC') -:call LT('ab', 'abc') -:call LT('AB', 'abc') -:call LT('ab', 'aBc') -:call EQ('\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd', '\xd0\xb9\xd0\xa6\xd0\xa3\xd0\xba\xd0\x95\xd0\xbd') -:call LT('\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd', '\xd0\xaf\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd') -:call EQ('\xe2\x84\xaa', 'k') -:call LT('\xe2\x84\xaa', 'kkkkkk') -:call EQ('\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa', 'kkk') -:call LT('kk', '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa') -:call EQ('\xe2\x84\xaa\xe2\x84\xa6k\xe2\x84\xaak\xcf\x89', 'k\xcf\x89\xe2\x84\xaakk\xe2\x84\xa6') -:call EQ('Abc\x80', 'AbC\x80') -:call LT('Abc\x80', 'AbC\x81') -:call LT('Abc', 'AbC\x80') -:call LT('abc\x80DEF', 'abc\x80def') " case folding stops at the first bad character -:call LT('\xc3XYZ', '\xc3xyz') -:call EQ('\xef\xbc\xba', '\xef\xbd\x9a') " FF3A (upper), FF5A (lower) -:call GT('\xef\xbc\xba', '\xef\xbc\xff') " first string is ok and equals \xef\xbd\x9a after folding, second string is illegal and was left unchanged, then the strings were bytewise compared -:call LT('\xc3', '\xc3\x83') -:call EQ('\xc3\xa3xYz', '\xc3\x83XyZ') -:for n in range(0x60, 0xFF) | call LT(printf('xYz\x%.2X', n-1), printf('XyZ\x%.2X', n)) | endfor -:for n in range(0x80, 0xBF) | call EQ(printf('xYz\xc2\x%.2XUvW', n), printf('XyZ\xc2\x%.2XuVw', n)) | endfor -:for n in range(0xC0, 0xFF) | call LT(printf('xYz\xc2\x%.2XUvW', n), printf('XyZ\xc2\x%.2XuVw', n)) | endfor -:call append(0, printf('%d checks passed', b:passed)) -:" -:" test that g~ap changes one paragraph only. -:new -iabcd - -defggg0g~ap:let lns = getline(1,3) -:q! -:call append(line('$'), lns) -:" -:wq! test.out -ENDTEST -
deleted file mode 100644 --- a/src/testdir/test82.ok +++ /dev/null @@ -1,5 +0,0 @@ -3732 checks passed - -ABCD - -defg
deleted file mode 100644 --- a/src/testdir/test90.in +++ /dev/null @@ -1,53 +0,0 @@ -Tests for sha256() function. vim: set ft=vim et ts=2 sw=2 : - -STARTTEST -:so small.vim -:if !has('cryptv') || !exists('*sha256') - e! test.ok - wq! test.out -:endif -:" -:let testcase='test for empty string: ' -:if sha256("") ==# 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' -: let res='ok' -:else -: let res='ng' -:endif -:$put =testcase.res -:" -:let testcase='test for 1 char: ' -:if sha256("a") ==# 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb' -: let res='ok' -:else -: let res='ng' -:endif -:$put =testcase.res -:" -:let testcase='test for 3 chars: ' -:if sha256("abc") ==# 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' -: let res='ok' -:else -: let res='ng' -:endif -:$put =testcase.res -:" -:let testcase='test for contains meta char: ' -:if sha256("foo\nbar") ==# '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776' -: let res='ok' -:else -: let res='ng' -:endif -:$put =testcase.res -:" -:let testcase='test for contains non-ascii char: ' -:if sha256("\xde\xad\xbe\xef") ==# '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953' -: let res='ok' -:else -: let res='ng' -:endif -:$put =testcase.res -:" -:/^start:/,$wq! test.out -ENDTEST - -start:
deleted file mode 100644 --- a/src/testdir/test90.ok +++ /dev/null @@ -1,6 +0,0 @@ -start: -test for empty string: ok -test for 1 char: ok -test for 3 chars: ok -test for contains meta char: ok -test for contains non-ascii char: ok
new file mode 100644 --- /dev/null +++ b/src/testdir/test_sha256.vim @@ -0,0 +1,22 @@ +" Tests for the sha256() function. + +if !has('cryptv') || !exists('*sha256') + finish +endif + +function Test_sha256() + " test for empty string: + call assert_equal(sha256(""), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') + + "'test for 1 char: + call assert_equal(sha256("a"), 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb') + " + "test for 3 chars: + call assert_equal(sha256("abc"), 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad') + + " test for contains meta char: + call assert_equal(sha256("foo\nbar"), '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776') + + " test for contains non-ascii char: + call assert_equal(sha256("\xde\xad\xbe\xef"), '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953') +endfunction
new file mode 100644 --- /dev/null +++ b/src/testdir/test_utf8_comparisons.vim @@ -0,0 +1,95 @@ +" Tests for case-insensitive UTF-8 comparisons (utf_strnicmp() in mbyte.c) +" Also test "g~ap". + +if !has("multi_byte") + finish +endif + +function! Ch(a, op, b, expected) + call assert_equal(eval(printf('"%s" %s "%s"', a:a, a:op, a:b)), a:expected, + \ printf('"%s" %s "%s" should return %d', a:a, a:op, a:b, a:expected)) +endfunction + +function! Chk(a, b, result) + if a:result == 0 + call Ch(a:a, '==?', a:b, 1) + call Ch(a:a, '!=?', a:b, 0) + call Ch(a:a, '<=?', a:b, 1) + call Ch(a:a, '>=?', a:b, 1) + call Ch(a:a, '<?', a:b, 0) + call Ch(a:a, '>?', a:b, 0) + elseif a:result > 0 + call Ch(a:a, '==?', a:b, 0) + call Ch(a:a, '!=?', a:b, 1) + call Ch(a:a, '<=?', a:b, 0) + call Ch(a:a, '>=?', a:b, 1) + call Ch(a:a, '<?', a:b, 0) + call Ch(a:a, '>?', a:b, 1) + else + call Ch(a:a, '==?', a:b, 0) + call Ch(a:a, '!=?', a:b, 1) + call Ch(a:a, '<=?', a:b, 1) + call Ch(a:a, '>=?', a:b, 0) + call Ch(a:a, '<?', a:b, 1) + call Ch(a:a, '>?', a:b, 0) + endif +endfunction + +function! Check(a, b, result) + call Chk(a:a, a:b, a:result) + call Chk(a:b, a:a, -a:result) +endfunction + +function! LT(a, b) + call Check(a:a, a:b, -1) +endfunction + +function! GT(a, b) + call Check(a:a, a:b, 1) +endfunction + +function! EQ(a, b) + call Check(a:a, a:b, 0) +endfunction + +function Test_comparisons() + call EQ('', '') + call LT('', 'a') + call EQ('abc', 'abc') + call EQ('Abc', 'abC') + call LT('ab', 'abc') + call LT('AB', 'abc') + call LT('ab', 'aBc') + call EQ('\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd', '\xd0\xb9\xd0\xa6\xd0\xa3\xd0\xba\xd0\x95\xd0\xbd') + call LT('\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd', '\xd0\xaf\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd') + call EQ('\xe2\x84\xaa', 'k') + call LT('\xe2\x84\xaa', 'kkkkkk') + call EQ('\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa', 'kkk') + call LT('kk', '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa') + call EQ('\xe2\x84\xaa\xe2\x84\xa6k\xe2\x84\xaak\xcf\x89', 'k\xcf\x89\xe2\x84\xaakk\xe2\x84\xa6') + call EQ('Abc\x80', 'AbC\x80') + call LT('Abc\x80', 'AbC\x81') + call LT('Abc', 'AbC\x80') + call LT('abc\x80DEF', 'abc\x80def') " case folding stops at the first bad character + call LT('\xc3XYZ', '\xc3xyz') + call EQ('\xef\xbc\xba', '\xef\xbd\x9a') " FF3A (upper), FF5A (lower) + call GT('\xef\xbc\xba', '\xef\xbc\xff') " first string is ok and equals \xef\xbd\x9a after folding, second string is illegal and was left unchanged, then the strings were bytewise compared + call LT('\xc3', '\xc3\x83') + call EQ('\xc3\xa3xYz', '\xc3\x83XyZ') + for n in range(0x60, 0xFF) + call LT(printf('xYz\x%.2X', n-1), printf('XyZ\x%.2X', n)) + endfor + for n in range(0x80, 0xBF) + call EQ(printf('xYz\xc2\x%.2XUvW', n), printf('XyZ\xc2\x%.2XuVw', n)) + endfor + for n in range(0xC0, 0xFF) + call LT(printf('xYz\xc2\x%.2XUvW', n), printf('XyZ\xc2\x%.2XuVw', n)) + endfor +endfunction + +" test that g~ap changes one paragraph only. +function Test_gap() + new + call feedkeys("iabcd\n\ndefggg0g~ap", "tx") + call assert_equal(["ABCD", "", "defg"], getline(1,3)) +endfunction