mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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.
7177da9dd4
Co-authored-by: Bram Moolenaar <Bram@vim.org>
			
			
This commit is contained in:
		| @@ -48,6 +48,11 @@ func Test_assert_equal() | |||||||
|   call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX') |   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 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) |   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 | endfunc | ||||||
|  |  | ||||||
| func Test_assert_equal_dict() | func Test_assert_equal_dict() | ||||||
| @@ -143,6 +148,14 @@ func Test_assert_exception() | |||||||
|     call assert_equal(0, assert_exception('E492:')) |     call assert_equal(0, assert_exception('E492:')) | ||||||
|   endtry |   endtry | ||||||
|  |  | ||||||
|  |   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 |   try | ||||||
|     nocommand |     nocommand | ||||||
|   catch |   catch | ||||||
| @@ -153,6 +166,10 @@ func Test_assert_exception() | |||||||
|       call assert_equal(0, assert_exception('E730:')) |       call assert_equal(0, assert_exception('E730:')) | ||||||
|     endtry |     endtry | ||||||
|   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 | endfunc | ||||||
|  |  | ||||||
| func Test_wrong_error_type() | 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 assert_match("stupid: Expected 'E9876' but got 'E492:", v:errors[0]) | ||||||
|   call remove(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_equal(1, assert_fails('echo', '', 'echo command')) | ||||||
|   call assert_match("command did not fail: echo command", v:errors[0]) |   call assert_match("command did not fail: echo command", v:errors[0]) | ||||||
|   call remove(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_equal(1, 'echo'->assert_fails('', 'echo command')) | ||||||
|   call assert_match("command did not fail: echo command", v:errors[0]) |   call assert_match("command did not fail: echo command", v:errors[0]) | ||||||
|   call remove(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 | endfunc | ||||||
|  |  | ||||||
| func Test_assert_fails_in_try_block() | func Test_assert_fails_in_try_block() | ||||||
|   | |||||||
| @@ -68,7 +68,7 @@ static void ga_concat_esc(garray_T *gap, const char_u *p, int clen) | |||||||
|     case '\\': |     case '\\': | ||||||
|       ga_concat(gap, "\\\\"); break; |       ga_concat(gap, "\\\\"); break; | ||||||
|     default: |     default: | ||||||
|       if (*p < ' ') { |       if (*p < ' ' || *p == 0x7f) { | ||||||
|         vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); |         vim_snprintf((char *)buf, NUMBUFLEN, "\\x%02x", *p); | ||||||
|         ga_concat(gap, (char *)buf); |         ga_concat(gap, (char *)buf); | ||||||
|       } else { |       } else { | ||||||
| @@ -244,12 +244,12 @@ static int assert_match_common(typval_T *argvars, assert_type_T atype) | |||||||
| { | { | ||||||
|   char buf1[NUMBUFLEN]; |   char buf1[NUMBUFLEN]; | ||||||
|   char buf2[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 pat = tv_get_string_buf_chk(&argvars[0], buf1); | ||||||
|   const char *const text = tv_get_string_buf_chk(&argvars[1], buf2); |   const char *const text = tv_get_string_buf_chk(&argvars[1], buf2); | ||||||
|  |  | ||||||
|   if (pat == NULL || text == NULL) { |   if (called_emsg == called_emsg_before | ||||||
|     emsg(_(e_invarg)); |       && pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { | ||||||
|   } else if (pattern_match(pat, text, false) != (atype == ASSERT_MATCH)) { |  | ||||||
|     garray_T ga; |     garray_T ga; | ||||||
|     prepare_assert_error(&ga); |     prepare_assert_error(&ga); | ||||||
|     fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1], atype); |     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 buf1[NUMBUFLEN]; | ||||||
|   char buf2[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 fname1 = tv_get_string_buf_chk(&argvars[0], buf1); | ||||||
|   const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2); |   const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2); | ||||||
|   garray_T ga; |   garray_T ga; | ||||||
|  |  | ||||||
|   if (fname1 == NULL || fname2 == NULL) { |   if (called_emsg > called_emsg_before) { | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq