diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:28:19 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 12:31:31 +0800 |
commit | b33de61cc3e14cc6160a972205f6543e82b843aa (patch) | |
tree | 0328a930a9b4b23a0f9fc579ce9fb1a122c27cb8 | |
parent | 159d52b433055e957fec6dee5da20f23fabf10d4 (diff) | |
download | rneovim-b33de61cc3e14cc6160a972205f6543e82b843aa.tar.gz rneovim-b33de61cc3e14cc6160a972205f6543e82b843aa.tar.bz2 rneovim-b33de61cc3e14cc6160a972205f6543e82b843aa.zip |
vim-patch:8.2.1199: not all assert functions are fully tested
Problem: Not all assert functions are fully tested.
Solution: Test more assert functions.
https://github.com/vim/vim/commit/7177da9dd4d9a521c6141c6fbf7e9a4d6296ab05
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/testdir/test_assert.vim | 46 | ||||
-rw-r--r-- | src/nvim/testing.c | 11 |
2 files changed, 52 insertions, 5 deletions
diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index 8723a0a38d..0ba45d0b13 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -48,6 +48,11 @@ func Test_assert_equal() call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX') call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0]) call remove(v:errors, 0) + + " special characters are escaped + call assert_equal("\b\e\f\n\t\r\\\x01\x7f", 'x') + call assert_match('Expected ''\\b\\e\\f\\n\\t\\r\\\\\\x01\\x7f'' but got ''x''', v:errors[0]) + call remove(v:errors, 0) endfunc func Test_assert_equal_dict() @@ -146,6 +151,14 @@ func Test_assert_exception() try nocommand catch + call assert_equal(1, assert_exception('E12345:')) + endtry + call assert_match("Expected 'E12345:' but got 'Vim:E492: ", v:errors[0]) + call remove(v:errors, 0) + + try + nocommand + catch try " illegal argument, get NULL for error call assert_equal(1, assert_exception([])) @@ -153,6 +166,10 @@ func Test_assert_exception() call assert_equal(0, assert_exception('E730:')) endtry endtry + + call assert_equal(1, assert_exception('E492:')) + call assert_match('v:exception is not set', v:errors[0]) + call remove(v:errors, 0) endfunc func Test_wrong_error_type() @@ -202,6 +219,14 @@ func Test_assert_fail_fails() call assert_match("stupid: Expected 'E9876' but got 'E492:", v:errors[0]) call remove(v:errors, 0) + call assert_equal(1, assert_fails('xxx', ['E9876'])) + call assert_match("Expected \\['E9876'\\] but got 'E492:", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_fails('xxx', ['E492:', 'E9876'])) + call assert_match("Expected \\['E492:', 'E9876'\\] but got 'E492:", v:errors[0]) + call remove(v:errors, 0) + call assert_equal(1, assert_fails('echo', '', 'echo command')) call assert_match("command did not fail: echo command", v:errors[0]) call remove(v:errors, 0) @@ -209,6 +234,27 @@ func Test_assert_fail_fails() call assert_equal(1, 'echo'->assert_fails('', 'echo command')) call assert_match("command did not fail: echo command", v:errors[0]) call remove(v:errors, 0) + + try + call assert_equal(1, assert_fails('xxx', [])) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', ['1', '2', '3'])) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) + + try + call assert_equal(1, assert_fails('xxx', #{one: 1})) + catch + let exp = v:exception + endtry + call assert_match("E856: assert_fails() second argument", exp) endfunc func Test_assert_fails_in_try_block() diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 5c0e757ccf..e1a28fbde3 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -68,7 +68,7 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) case '\\': ga_concat(gap, "\\\\"); break; default: - if (*p < ' ') { + if (*p < ' ' || *p == 0x7f) { vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); ga_concat(gap, (char *)buf); } else { @@ -244,12 +244,12 @@ static int assert_match_common(typval_T *argvars, assert_type_T atype) { char buf1[NUMBUFLEN]; char buf2[NUMBUFLEN]; + const int called_emsg_before = called_emsg; const char *const pat = tv_get_string_buf_chk(&argvars[0], buf1); const char *const text = tv_get_string_buf_chk(&argvars[1], buf2); - if (pat == NULL || text == NULL) { - emsg(_(e_invarg)); - } else if (pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { + if (called_emsg == called_emsg_before + && pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { garray_T ga; prepare_assert_error(&ga); fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], atype); @@ -350,11 +350,12 @@ static int assert_equalfile(typval_T *argvars) { char buf1[NUMBUFLEN]; char buf2[NUMBUFLEN]; + const int called_emsg_before = called_emsg; const char *const fname1 = tv_get_string_buf_chk(&argvars[0], buf1); const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2); garray_T ga; - if (fname1 == NULL || fname2 == NULL) { + if (called_emsg > called_emsg_before) { return 0; } |