Patch 8.1.1861
Problem: Only some assert functions can be used as a method.
Solution: Allow using most assert functions as a method.
Files: runtime/doc/testing.txt, src/evalfunc.c,
src/testdir/test_assert.vim
*** ../vim-8.1.1860/runtime/doc/testing.txt 2019-08-04 15:03:33.367303750
+0200
--- runtime/doc/testing.txt 2019-08-16 21:28:23.788106873 +0200
***************
*** 206,211 ****
--- 206,214 ----
NOT produce a beep or visual bell.
Also see |assert_fails()| and |assert-return|.
+ Can also be used as a |method|: >
+ GetCmd()->assert_beeps()
+ <
*assert_equal()*
assert_equal({expected}, {actual} [, {msg}])
When {expected} and {actual} are not equal an error message is
***************
*** 255,260 ****
--- 258,266 ----
Note that beeping is not considered an error, and some failing
commands only beep. Use |assert_beeps()| for those.
+ Can also be used as a |method|: >
+ GetCmd()->assert_fails('E99:')
+
assert_false({actual} [, {msg}]) *assert_false()*
When {actual} is not false an error message is added to
|v:errors|, like with |assert_equal()|.
***************
*** 264,269 ****
--- 270,278 ----
When {msg} is omitted an error in the form
"Expected False but got {actual}" is produced.
+ Can also be used as a |method|: >
+ GetResult()->assert_false()
+
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
This asserts number and |Float| values. When {actual} is lower
than {lower} or higher than {upper} an error message is added
***************
*** 292,297 ****
--- 301,309 ----
< Will result in a string to be added to |v:errors|:
test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
+ Can also be used as a |method|: >
+ getFile()->assert_match('foo.*')
+ <
*assert_notequal()*
assert_notequal({expected}, {actual} [, {msg}])
The opposite of `assert_equal()`: add an error message to
***************
*** 307,312 ****
--- 319,327 ----
|v:errors| when {pattern} matches {actual}.
Also see |assert-return|.
+ Can also be used as a |method|: >
+ getFile()->assert_notmatch('bar.*')
+
assert_report({msg}) *assert_report()*
Report a test failure directly, using {msg}.
Always returns one.
***************
*** 320,324 ****
--- 335,342 ----
When {msg} is omitted an error in the form "Expected True but
got {actual}" is produced.
+ Can also be used as a |method|: >
+ GetResult()->assert_true()
+ <
vim:tw=78:ts=8:noet:ft=help:norl:
*** ../vim-8.1.1860/src/evalfunc.c 2019-08-15 21:30:26.622085162 +0200
--- src/evalfunc.c 2019-08-16 21:40:20.080691413 +0200
***************
*** 415,420 ****
--- 415,421 ----
// values for f_argtype; zero means it cannot be used as a method
#define FEARG_1 1 // base is the first argument
#define FEARG_2 2 // base is the second argument
+ #define FEARG_3 3 // base is the third argument
#define FEARG_LAST 9 // base is the last argument
static funcentry_T global_functions[] =
***************
*** 434,451 ****
#ifdef FEAT_FLOAT
{"asin", 1, 1, 0, f_asin}, // WJMc
#endif
! {"assert_beeps", 1, 2, 0, f_assert_beeps},
{"assert_equal", 2, 3, FEARG_2, f_assert_equal},
{"assert_equalfile", 2, 2, 0, f_assert_equalfile},
{"assert_exception", 1, 2, 0, f_assert_exception},
! {"assert_fails", 1, 3, 0, f_assert_fails},
! {"assert_false", 1, 2, 0, f_assert_false},
! {"assert_inrange", 3, 4, 0, f_assert_inrange},
! {"assert_match", 2, 3, 0, f_assert_match},
{"assert_notequal", 2, 3, FEARG_2, f_assert_notequal},
! {"assert_notmatch", 2, 3, 0, f_assert_notmatch},
{"assert_report", 1, 1, 0, f_assert_report},
! {"assert_true", 1, 2, 0, f_assert_true},
#ifdef FEAT_FLOAT
{"atan", 1, 1, 0, f_atan},
{"atan2", 2, 2, 0, f_atan2},
--- 435,452 ----
#ifdef FEAT_FLOAT
{"asin", 1, 1, 0, f_asin}, // WJMc
#endif
! {"assert_beeps", 1, 2, FEARG_1, f_assert_beeps},
{"assert_equal", 2, 3, FEARG_2, f_assert_equal},
{"assert_equalfile", 2, 2, 0, f_assert_equalfile},
{"assert_exception", 1, 2, 0, f_assert_exception},
! {"assert_fails", 1, 3, FEARG_1, f_assert_fails},
! {"assert_false", 1, 2, FEARG_1, f_assert_false},
! {"assert_inrange", 3, 4, FEARG_3, f_assert_inrange},
! {"assert_match", 2, 3, FEARG_2, f_assert_match},
{"assert_notequal", 2, 3, FEARG_2, f_assert_notequal},
! {"assert_notmatch", 2, 3, FEARG_2, f_assert_notmatch},
{"assert_report", 1, 1, 0, f_assert_report},
! {"assert_true", 1, 2, FEARG_1, f_assert_true},
#ifdef FEAT_FLOAT
{"atan", 1, 1, 0, f_atan},
{"atan2", 2, 2, 0, f_atan2},
***************
*** 1134,1139 ****
--- 1135,1149 ----
for (i = 1; i < argcount; ++i)
argv[i + 1] = argvars[i];
}
+ else if (global_functions[fi].f_argtype == FEARG_3)
+ {
+ // base value goes third
+ argv[0] = argvars[0];
+ argv[1] = argvars[1];
+ argv[2] = *basetv;
+ for (i = 2; i < argcount; ++i)
+ argv[i + 1] = argvars[i];
+ }
else
{
// FEARG_1: base value goes first
*** ../vim-8.1.1860/src/testdir/test_assert.vim 2019-07-10 22:04:44.960086645
+0200
--- src/testdir/test_assert.vim 2019-08-16 21:42:50.267986848 +0200
***************
*** 3,22 ****
--- 3,32 ----
func Test_assert_false()
call assert_equal(0, assert_false(0))
call assert_equal(0, assert_false(v:false))
+ call assert_equal(0, v:false->assert_false())
call assert_equal(1, assert_false(123))
call assert_match("Expected False but got 123", v:errors[0])
call remove(v:errors, 0)
+
+ call assert_equal(1, 123->assert_false())
+ call assert_match("Expected False but got 123", v:errors[0])
+ call remove(v:errors, 0)
endfunc
func Test_assert_true()
call assert_equal(0, assert_true(1))
call assert_equal(0, assert_true(123))
call assert_equal(0, assert_true(v:true))
+ call assert_equal(0, v:true->assert_true())
call assert_equal(1, assert_true(0))
call assert_match("Expected True but got 0", v:errors[0])
call remove(v:errors, 0)
+
+ call assert_equal(1, 0->assert_true())
+ call assert_match("Expected True but got 0", v:errors[0])
+ call remove(v:errors, 0)
endfunc
func Test_assert_equal()
***************
*** 141,146 ****
--- 151,160 ----
call assert_equal(1, assert_match('bar.*foo', 'foobar', 'wrong'))
call assert_match('wrong', v:errors[0])
call remove(v:errors, 0)
+
+ call assert_equal(1, 'foobar'->assert_match('bar.*foo', 'wrong'))
+ call assert_match('wrong', v:errors[0])
+ call remove(v:errors, 0)
endfunc
func Test_notmatch()
***************
*** 150,155 ****
--- 164,173 ----
call assert_equal(1, assert_notmatch('foo', 'foobar'))
call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
call remove(v:errors, 0)
+
+ call assert_equal(1, 'foobar'->assert_notmatch('foo'))
+ call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
+ call remove(v:errors, 0)
endfunc
func Test_assert_fail_fails()
***************
*** 164,169 ****
--- 182,191 ----
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)
+
+ 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)
endfunc
func Test_assert_fails_in_try_block()
***************
*** 179,184 ****
--- 201,212 ----
call assert_equal(1, assert_beeps('normal 0'))
call assert_match("command did not beep: normal 0", v:errors[0])
call remove(v:errors, 0)
+
+ call assert_equal(0, 'normal h'->assert_beeps())
+ call assert_equal(1, 'normal 0'->assert_beeps())
+ call assert_match("command did not beep: normal 0", v:errors[0])
+ call remove(v:errors, 0)
+
bwipe
endfunc
***************
*** 195,200 ****
--- 223,234 ----
call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
call remove(v:errors, 0)
+ call assert_equal(0, 5->assert_inrange(5, 7))
+ call assert_equal(0, 7->assert_inrange(5, 7))
+ call assert_equal(1, 8->assert_inrange(5, 7))
+ call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
+ call remove(v:errors, 0)
+
call assert_fails('call assert_inrange(1, 1)', 'E119:')
if has('float')
*** ../vim-8.1.1860/src/version.c 2019-08-16 21:47:23.870692859 +0200
--- src/version.c 2019-08-16 21:48:27.062392577 +0200
***************
*** 771,772 ****
--- 771,774 ----
{ /* Add new patch number below this line */
+ /**/
+ 1861,
/**/
--
hundred-and-one symptoms of being an internet addict:
69. Yahoo welcomes you with your own start page
/// 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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/201908161949.x7GJnnVw019462%40masaka.moolenaar.net.