Patch 7.4.1703
Problem: Can't assert for not equal and not matching.
Solution: Add assert_notmatch() and assert_notequal().
Files: src/eval.c, runtime/doc/eval.txt, src/testdir/test_assert.vim
*** ../vim-7.4.1702/src/eval.c 2016-04-01 21:00:44.794732242 +0200
--- src/eval.c 2016-04-03 20:47:43.383555396 +0200
***************
*** 476,481 ****
--- 476,483 ----
static void f_assert_fails(typval_T *argvars, typval_T *rettv);
static void f_assert_false(typval_T *argvars, typval_T *rettv);
static void f_assert_match(typval_T *argvars, typval_T *rettv);
+ static void f_assert_notequal(typval_T *argvars, typval_T *rettv);
+ static void f_assert_notmatch(typval_T *argvars, typval_T *rettv);
static void f_assert_true(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_FLOAT
static void f_asin(typval_T *argvars, typval_T *rettv);
***************
*** 8182,8187 ****
--- 8184,8191 ----
{"assert_fails", 1, 2, f_assert_fails},
{"assert_false", 1, 2, f_assert_false},
{"assert_match", 2, 3, f_assert_match},
+ {"assert_notequal", 2, 3, f_assert_notequal},
+ {"assert_notmatch", 2, 3, f_assert_notmatch},
{"assert_true", 1, 2, f_assert_true},
#ifdef FEAT_FLOAT
{"atan", 1, 1, f_atan},
***************
*** 9323,9330 ****
alist_name(&ARGLIST[idx]), -1);
}
static void prepare_assert_error(garray_T*gap);
! static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u
*exp_str, typval_T *exp_tv, typval_T *got_tv, int is_match);
static void assert_error(garray_T *gap);
static void assert_bool(typval_T *argvars, int isTrue);
--- 9327,9343 ----
alist_name(&ARGLIST[idx]), -1);
}
+ typedef enum
+ {
+ ASSERT_EQUAL,
+ ASSERT_NOTEQUAL,
+ ASSERT_MATCH,
+ ASSERT_NOTMATCH,
+ ASSERT_OTHER,
+ } assert_type_T;
+
static void prepare_assert_error(garray_T*gap);
! static void fill_assert_error(garray_T *gap, typval_T *opt_msg_tv, char_u
*exp_str, typval_T *exp_tv, typval_T *got_tv, assert_type_T is_match);
static void assert_error(garray_T *gap);
static void assert_bool(typval_T *argvars, int isTrue);
***************
*** 9400,9406 ****
char_u *exp_str,
typval_T *exp_tv,
typval_T *got_tv,
! int is_match)
{
char_u numbuf[NUMBUFLEN];
char_u *tofree;
--- 9413,9419 ----
char_u *exp_str,
typval_T *exp_tv,
typval_T *got_tv,
! assert_type_T atype)
{
char_u numbuf[NUMBUFLEN];
char_u *tofree;
***************
*** 9412,9418 ****
}
else
{
! if (is_match)
ga_concat(gap, (char_u *)"Pattern ");
else
ga_concat(gap, (char_u *)"Expected ");
--- 9425,9431 ----
}
else
{
! if (atype == ASSERT_MATCH || atype == ASSERT_NOTMATCH)
ga_concat(gap, (char_u *)"Pattern ");
else
ga_concat(gap, (char_u *)"Expected ");
***************
*** 9423,9430 ****
}
else
ga_concat_esc(gap, exp_str);
! if (is_match)
ga_concat(gap, (char_u *)" does not match ");
else
ga_concat(gap, (char_u *)" but got ");
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
--- 9436,9447 ----
}
else
ga_concat_esc(gap, exp_str);
! if (atype == ASSERT_MATCH)
ga_concat(gap, (char_u *)" does not match ");
+ else if (atype == ASSERT_NOTMATCH)
+ ga_concat(gap, (char_u *)" does match ");
+ else if (atype == ASSERT_NOTEQUAL)
+ ga_concat(gap, (char_u *)" differs from ");
else
ga_concat(gap, (char_u *)" but got ");
ga_concat_esc(gap, tv2string(got_tv, &tofree, numbuf, 0));
***************
*** 9446,9470 ****
list_append_string(vimvars[VV_ERRORS].vv_list, gap->ga_data, gap->ga_len);
}
- /*
- * "assert_equal(expected, actual[, msg])" function
- */
static void
! f_assert_equal(typval_T *argvars, typval_T *rettv UNUSED)
{
garray_T ga;
! if (!tv_equal(&argvars[0], &argvars[1], FALSE, FALSE))
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1],
! FALSE);
assert_error(&ga);
ga_clear(&ga);
}
}
/*
* "assert_exception(string[, msg])" function
*/
static void
--- 9463,9503 ----
list_append_string(vimvars[VV_ERRORS].vv_list, gap->ga_data, gap->ga_len);
}
static void
! assert_equal_common(typval_T *argvars, assert_type_T atype)
{
garray_T ga;
! if (tv_equal(&argvars[0], &argvars[1], FALSE, FALSE)
! != (atype == ASSERT_EQUAL))
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1],
! atype);
assert_error(&ga);
ga_clear(&ga);
}
}
/*
+ * "assert_equal(expected, actual[, msg])" function
+ */
+ static void
+ f_assert_equal(typval_T *argvars, typval_T *rettv UNUSED)
+ {
+ assert_equal_common(argvars, ASSERT_EQUAL);
+ }
+
+ /*
+ * "assert_notequal(expected, actual[, msg])" function
+ */
+ static void
+ f_assert_notequal(typval_T *argvars, typval_T *rettv UNUSED)
+ {
+ assert_equal_common(argvars, ASSERT_NOTEQUAL);
+ }
+
+ /*
* "assert_exception(string[, msg])" function
*/
static void
***************
*** 9486,9492 ****
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[1], NULL, &argvars[0],
! &vimvars[VV_EXCEPTION].vv_tv, FALSE);
assert_error(&ga);
ga_clear(&ga);
}
--- 9519,9525 ----
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[1], NULL, &argvars[0],
! &vimvars[VV_EXCEPTION].vv_tv, ASSERT_OTHER);
assert_error(&ga);
ga_clear(&ga);
}
***************
*** 9523,9529 ****
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[1],
! &vimvars[VV_ERRMSG].vv_tv, FALSE);
assert_error(&ga);
ga_clear(&ga);
}
--- 9556,9562 ----
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[1],
! &vimvars[VV_ERRMSG].vv_tv, ASSERT_OTHER);
assert_error(&ga);
ga_clear(&ga);
}
***************
*** 9555,9561 ****
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[1],
(char_u *)(isTrue ? "True" : "False"),
! NULL, &argvars[0], FALSE);
assert_error(&ga);
ga_clear(&ga);
}
--- 9588,9594 ----
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[1],
(char_u *)(isTrue ? "True" : "False"),
! NULL, &argvars[0], ASSERT_OTHER);
assert_error(&ga);
ga_clear(&ga);
}
***************
*** 9570,9580 ****
assert_bool(argvars, FALSE);
}
- /*
- * "assert_match(pattern, actual[, msg])" function
- */
static void
! f_assert_match(typval_T *argvars, typval_T *rettv UNUSED)
{
garray_T ga;
char_u buf1[NUMBUFLEN];
--- 9603,9610 ----
assert_bool(argvars, FALSE);
}
static void
! assert_match_common(typval_T *argvars, assert_type_T atype)
{
garray_T ga;
char_u buf1[NUMBUFLEN];
***************
*** 9584,9600 ****
if (pat == NULL || text == NULL)
EMSG(_(e_invarg));
! else if (!pattern_match(pat, text, FALSE))
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1],
! TRUE);
assert_error(&ga);
ga_clear(&ga);
}
}
/*
* "assert_true(actual[, msg])" function
*/
static void
--- 9614,9648 ----
if (pat == NULL || text == NULL)
EMSG(_(e_invarg));
! else if (pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH))
{
prepare_assert_error(&ga);
fill_assert_error(&ga, &argvars[2], NULL, &argvars[0], &argvars[1],
! atype);
assert_error(&ga);
ga_clear(&ga);
}
}
/*
+ * "assert_match(pattern, actual[, msg])" function
+ */
+ static void
+ f_assert_match(typval_T *argvars, typval_T *rettv UNUSED)
+ {
+ assert_match_common(argvars, ASSERT_MATCH);
+ }
+
+ /*
+ * "assert_notmatch(pattern, actual[, msg])" function
+ */
+ static void
+ f_assert_notmatch(typval_T *argvars, typval_T *rettv UNUSED)
+ {
+ assert_match_common(argvars, ASSERT_NOTMATCH);
+ }
+
+ /*
* "assert_true(actual[, msg])" function
*/
static void
*** ../vim-7.4.1702/runtime/doc/eval.txt 2016-03-29 23:10:14.006448157
+0200
--- runtime/doc/eval.txt 2016-04-03 20:27:05.423751938 +0200
***************
*** 1784,1794 ****
Number argument list id
argv( {nr}) String {nr} entry of the argument list
argv() List the argument list
! assert_equal( {exp}, {act} [, {msg}]) none assert {exp} equals {act}
assert_exception( {error} [, {msg}]) none assert {error} is in v:exception
assert_fails( {cmd} [, {error}]) none assert {cmd} fails
assert_false( {actual} [, {msg}]) none assert {actual} is false
assert_match( {pat}, {text} [, {msg}]) none assert {pat} matches {text}
assert_true( {actual} [, {msg}]) none assert {actual} is true
asin( {expr}) Float arc sine of {expr}
atan( {expr}) Float arc tangent of {expr}
--- 1801,1813 ----
Number argument list id
argv( {nr}) String {nr} entry of the argument list
argv() List the argument list
! assert_equal( {exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
assert_exception( {error} [, {msg}]) none assert {error} is in v:exception
assert_fails( {cmd} [, {error}]) none assert {cmd} fails
assert_false( {actual} [, {msg}]) none assert {actual} is false
assert_match( {pat}, {text} [, {msg}]) none assert {pat} matches {text}
+ assert_notequal( {exp}, {act} [, {msg}]) none assert {exp} is not equal {act}
+ assert_notmatch( {pat}, {text} [, {msg}]) none assert {pat} not matches
{text}
assert_true( {actual} [, {msg}]) none assert {actual} is true
asin( {expr}) Float arc sine of {expr}
atan( {expr}) Float arc tangent of {expr}
***************
*** 2321,2326 ****
--- 2341,2356 ----
< Will result in a string to be added to |v:errors|:
test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
+ *assert_notequal()*
+ assert_notequal({expected}, {actual} [, {msg}])
+ The opposite of `assert_equal()`: add an error message to
+ |v:errors| when {expected} and {actual} are equal.
+
+ *assert_notmatch()*
+ assert_notmatch({pattern}, {actual} [, {msg}])
+ The opposite of `assert_match()`: add an error message to
+ |v:errors| when {pattern} matches {actual}.
+
assert_true({actual} [, {msg}])
*assert_true()*
When {actual} is not true an error message is added to
|v:errors|, like with |assert_equal()|.
*** ../vim-7.4.1702/src/testdir/test_assert.vim 2016-03-27 15:13:06.958231628
+0200
--- src/testdir/test_assert.vim 2016-04-03 20:51:43.009121095 +0200
***************
*** 18,23 ****
--- 18,39 ----
call assert_equal(4, n)
let l = [1, 2, 3]
call assert_equal([1, 2, 3], l)
+
+ let s = 'foo'
+ call assert_equal('bar', s)
+ call assert_match("Expected 'bar' but got 'foo'", v:errors[0])
+ call remove(v:errors, 0)
+ endfunc
+
+ func Test_assert_notequal()
+ let n = 4
+ call assert_notequal('foo', n)
+ let s = 'foo'
+ call assert_notequal([1, 2, 3], s)
+
+ call assert_notequal('foo', s)
+ call assert_match("Expected 'foo' differs from 'foo'", v:errors[0])
+ call remove(v:errors, 0)
endfunc
func Test_assert_exception()
***************
*** 74,79 ****
--- 90,104 ----
call remove(v:errors, 0)
endfunc
+ func Test_notmatch()
+ call assert_notmatch('foo', 'bar')
+ call assert_notmatch('^foobar$', 'foobars')
+
+ call assert_notmatch('foo', 'foobar')
+ call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
+ call remove(v:errors, 0)
+ endfunc
+
func Test_assert_fail_fails()
call assert_fails('xxx', {})
call assert_match("Expected {} but got 'E731:", v:errors[0])
*** ../vim-7.4.1702/src/version.c 2016-04-03 14:56:48.441552044 +0200
--- src/version.c 2016-04-03 20:28:47.886757007 +0200
***************
*** 750,751 ****
--- 750,753 ----
{ /* Add new patch number below this line */
+ /**/
+ 1703,
/**/
--
hundred-and-one symptoms of being an internet addict:
211. Your husband leaves you...taking the computer with him and you
call him crying, and beg him to bring the computer back.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.