comparison src/testdir/test_substitute.vim @ 16113:9994c50f7879 v8.1.1061

patch 8.1.1061: when substitute string throws error, substitute happens anyway commit https://github.com/vim/vim/commit/0e97b9487571cf725a9cb28fe4dcefc800415f69 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 27 22:53:53 2019 +0100 patch 8.1.1061: when substitute string throws error, substitute happens anyway Problem: When substitute string throws error, substitute happens anyway. Solution: Skip substitution when aborting. (closes https://github.com/vim/vim/issues/4161)
author Bram Moolenaar <Bram@vim.org>
date Wed, 27 Mar 2019 23:00:05 +0100
parents ed264e126766
children aebcd20a8a3f
comparison
equal deleted inserted replaced
16112:58f1e71bc938 16113:9994c50f7879
608 call assert_equal('bar', getline(5)) 608 call assert_equal('bar', getline(5))
609 609
610 enew! 610 enew!
611 set titlestring& 611 set titlestring&
612 endfunc 612 endfunc
613
614 func Test_nocatch_sub_failure_handling()
615 " normal error results in all replacements
616 func! Foo()
617 foobar
618 endfunc
619 new
620 call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
621 %s/aaa/\=Foo()/g
622 call assert_equal(['1 0', '2 0', '3 0'], getline(1, 3))
623
624 " Trow without try-catch causes abort after the first line.
625 " We cannot test this, since it would stop executing the test script.
626
627 " try/catch does not result in any changes
628 func! Foo()
629 throw 'error'
630 endfunc
631 call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
632 let error_caught = 0
633 try
634 %s/aaa/\=Foo()/g
635 catch
636 let error_caught = 1
637 endtry
638 call assert_equal(1, error_caught)
639 call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
640
641 bwipe!
642 endfunc