2016-01-15 21:31 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> Nikolay Pavlov wrote:
>
> > I think that assert_fails(command, exception_pattern[, message]) would
> > be more practical: I mean a function which executes command given as
> > an argument and intercepts exceptions from it, failing if there was no
> > exception or if exception did not match, so that your example is one
> > line only:
> >
> > call assert_fails('commandthatfails', '\V\^Vim:E492:')
>
> For simple commands this works. However, one has to put the command
> inside a string. That gets a bit more complicated when escaping is
> required. In most current use it's simple enough.
>
The only thing one needs to escape in this case is single quote when using
single quoted strings (except for multiline commands like :py << EOF, which
in any case do not fit into `:execute`). I can hardly see how your example
is easier to use then
try
commandthatfails
call assert_false(1, 'command should have failed')
catch
call assert_true(stridx(v:exception, 'E492:') != -1)
endtry
which requires exactly same line numbers and is just a few characters away,
many of which you can avoid if you are not too picky (I could have used
`v:exception=~'E492:'`, but do not like using regexes when they can be
avoided, miss spaces around operators or use string operators without
trailing `#`).
>
> --
> Eye have a spelling checker, it came with my PC;
> It plainly marks four my revue mistakes I cannot sea.
> I've run this poem threw it, I'm sure your please to no,
> It's letter perfect in it's weigh, my checker tolled me sew!
>
> /// 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.