comparison src/testdir/test_diffmode.vim @ 14762:b43ea03bb522 v8.1.0393

patch 8.1.0393: not all white space difference options available commit https://github.com/vim/vim/commit/785fc6567f572b8caefbc89ec29bbd8b801464ae Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 15 19:17:38 2018 +0200 patch 8.1.0393: not all white space difference options available Problem: Not all white space difference options available. Solution: Add "iblank", "iwhiteall" and "iwhiteeol" to 'diffopt'.
author Christian Brabandt <cb@256bit.org>
date Sat, 15 Sep 2018 19:30:06 +0200
parents 655f00c29c58
children 27055ad9276b
comparison
equal deleted inserted replaced
14761:99582039da8d 14762:b43ea03bb522
669 call assert_equal(w2lines, w1lines) 669 call assert_equal(w2lines, w1lines)
670 bwipe! 670 bwipe!
671 bwipe! 671 bwipe!
672 endfunc 672 endfunc
673 673
674 func WriteDiffFiles(list1, list2) 674 func WriteDiffFiles(buf, list1, list2)
675 call writefile(a:list1, 'Xfile1') 675 call writefile(a:list1, 'Xfile1')
676 call writefile(a:list2, 'Xfile2') 676 call writefile(a:list2, 'Xfile2')
677 endfunc 677 if a:buf
678 678 call term_sendkeys(a:buf, ":checktime\<CR>")
679 " Verify a screendump with both the external and external diff. 679 endif
680 endfunc
681
682 " Verify a screendump with both the internal and external diff.
680 func VerifyBoth(buf, dumpfile, extra) 683 func VerifyBoth(buf, dumpfile, extra)
681 call term_sendkeys(a:buf, ":diffupdate!\<cr>")
682 " trailing : for leaving the cursor on the command line 684 " trailing : for leaving the cursor on the command line
683 for cmd in [":set diffopt=filler" . a:extra . "\<cr>:", ":set diffopt+=internal\<cr>:"] 685 for cmd in [":set diffopt=filler" . a:extra . "\<CR>:", ":set diffopt+=internal\<CR>:"]
684 call term_sendkeys(a:buf, cmd) 686 call term_sendkeys(a:buf, cmd)
685 if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external') 687 if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external')
686 break " don't let the next iteration overwrite the "failed" file. 688 break " don't let the next iteration overwrite the "failed" file.
687 endif 689 endif
688 endfor 690 endfor
691 endfunc
692
693 " Verify a screendump with the internal diff only.
694 func VerifyInternal(buf, dumpfile, extra)
695 call term_sendkeys(a:buf, ":diffupdate!\<CR>")
696 " trailing : for leaving the cursor on the command line
697 call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:")
698 call VerifyScreenDump(a:buf, a:dumpfile, {})
689 endfunc 699 endfunc
690 700
691 func Test_diff_screen() 701 func Test_diff_screen()
692 if !CanRunVimInTerminal() || !has('menu') 702 if !CanRunVimInTerminal() || !has('menu')
693 return 703 return
695 " clean up already existing swap files, just in case 705 " clean up already existing swap files, just in case
696 call delete('.Xfile1.swp') 706 call delete('.Xfile1.swp')
697 call delete('.Xfile2.swp') 707 call delete('.Xfile2.swp')
698 708
699 " Test 1: Add a line in beginning of file 2 709 " Test 1: Add a line in beginning of file 2
700 call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) 710 call WriteDiffFiles(0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
701 let buf = RunVimInTerminal('-d Xfile1 Xfile2', {}) 711 let buf = RunVimInTerminal('-d Xfile1 Xfile2', {})
702 " Set autoread mode, ,so that Vim won't complain once we re-write the test 712 " Set autoread mode, ,so that Vim won't complain once we re-write the test
703 " files 713 " files
704 call term_sendkeys(buf, ":set autoread\<cr>\<c-w>w:set autoread\<cr>\<c-w>w") 714 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
705 715
706 call VerifyBoth(buf, 'Test_diff_01', '') 716 call VerifyBoth(buf, 'Test_diff_01', '')
707 717
708 " Test 2: Add a line in beginning of file 1 718 " Test 2: Add a line in beginning of file 1
709 call WriteDiffFiles([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) 719 call WriteDiffFiles(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
710 call VerifyBoth(buf, 'Test_diff_02', '') 720 call VerifyBoth(buf, 'Test_diff_02', '')
711 721
712 " Test 3: Add a line at the end of file 2 722 " Test 3: Add a line at the end of file 2
713 call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) 723 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
714 call VerifyBoth(buf, 'Test_diff_03', '') 724 call VerifyBoth(buf, 'Test_diff_03', '')
715 725
716 " Test 4: Add a line at the end of file 1 726 " Test 4: Add a line at the end of file 1
717 call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) 727 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
718 call VerifyBoth(buf, 'Test_diff_04', '') 728 call VerifyBoth(buf, 'Test_diff_04', '')
719 729
720 " Test 5: Add a line in the middle of file 2, remove on at the end of file 1 730 " Test 5: Add a line in the middle of file 2, remove on at the end of file 1
721 call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10]) 731 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10])
722 call VerifyBoth(buf, 'Test_diff_05', '') 732 call VerifyBoth(buf, 'Test_diff_05', '')
723 733
724 " Test 6: Add a line in the middle of file 1, remove on at the end of file 2 734 " Test 6: Add a line in the middle of file 1, remove on at the end of file 2
725 call WriteDiffFiles([1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) 735 call WriteDiffFiles(buf, [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
726 call VerifyBoth(buf, 'Test_diff_06', '') 736 call VerifyBoth(buf, 'Test_diff_06', '')
727 737
728 " Test 7 - 9: Test normal/patience/histogram diff algorithm 738 " Test 7 - 9: Test normal/patience/histogram diff algorithm
729 call WriteDiffFiles(['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{', 739 call WriteDiffFiles(buf, ['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{',
730 \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");', 740 \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");',
731 \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {', 741 \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {',
732 \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)', 742 \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)',
733 \ '{', ' frobnitz(fact(10));', '}'], 743 \ '{', ' frobnitz(fact(10));', '}'],
734 \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {', 744 \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {',
746 call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>") 756 call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>")
747 call VerifyScreenDump(buf, 'Test_diff_09', {}) 757 call VerifyScreenDump(buf, 'Test_diff_09', {})
748 758
749 " Test 10-11: normal/indent-heuristic 759 " Test 10-11: normal/indent-heuristic
750 call term_sendkeys(buf, ":set diffopt&vim\<cr>") 760 call term_sendkeys(buf, ":set diffopt&vim\<cr>")
751 call WriteDiffFiles(['', ' def finalize(values)', '', ' values.each do |v|', ' v.finalize', ' end'], 761 call WriteDiffFiles(buf, ['', ' def finalize(values)', '', ' values.each do |v|', ' v.finalize', ' end'],
752 \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '', 762 \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '',
753 \ ' values.each do |v|', ' v.finalize', ' end']) 763 \ ' values.each do |v|', ' v.finalize', ' end'])
754 call term_sendkeys(buf, ":diffupdate!\<cr>") 764 call term_sendkeys(buf, ":diffupdate!\<cr>")
755 call term_sendkeys(buf, ":set diffopt+=internal\<cr>") 765 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
756 call VerifyScreenDump(buf, 'Test_diff_10', {}) 766 call VerifyScreenDump(buf, 'Test_diff_10', {})
757 767
758 call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>") 768 call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>")
759 call VerifyScreenDump(buf, 'Test_diff_11', {}) 769 call VerifyScreenDump(buf, 'Test_diff_11', {})
760 770
761 " Test 12: diff the same file 771 " Test 12: diff the same file
762 call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) 772 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
763 call VerifyBoth(buf, 'Test_diff_12', '') 773 call VerifyBoth(buf, 'Test_diff_12', '')
764 774
765 " Test 13: diff an empty file 775 " Test 13: diff an empty file
766 call WriteDiffFiles([], []) 776 call WriteDiffFiles(buf, [], [])
767 call VerifyBoth(buf, 'Test_diff_13', '') 777 call VerifyBoth(buf, 'Test_diff_13', '')
768 778
769 " Test 14: test diffopt+=icase 779 " Test 14: test diffopt+=icase
770 call WriteDiffFiles(['a', 'b', 'cd'], ['A', 'b', 'cDe']) 780 call WriteDiffFiles(buf, ['a', 'b', 'cd'], ['A', 'b', 'cDe'])
771 call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase") 781 call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase")
772 782
773 " Test 15-16: test diffopt+=iwhite 783 " Test 15-16: test diffopt+=iwhite
774 call WriteDiffFiles(['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'], 784 call WriteDiffFiles(buf, ['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'],
775 \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}']) 785 \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}'])
776 call term_sendkeys(buf, ":diffupdate!\<cr>") 786 call term_sendkeys(buf, ":diffupdate!\<cr>")
777 call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>") 787 call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>")
778 call VerifyScreenDump(buf, 'Test_diff_15', {}) 788 call VerifyScreenDump(buf, 'Test_diff_15', {})
779 call term_sendkeys(buf, ":set diffopt+=internal\<cr>") 789 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
780 call VerifyScreenDump(buf, 'Test_diff_16', {}) 790 call VerifyScreenDump(buf, 'Test_diff_16', {})
781 791
792 " Test 17: test diffopt+=iblank
793 call WriteDiffFiles(buf, ['a', ' ', 'cd', 'ef', 'xxx'], ['a', 'cd', '', 'ef', 'yyy'])
794 call VerifyInternal(buf, 'Test_diff_17', " diffopt+=iblank")
795
796 " Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol
797 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhite")
798 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteall")
799 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteeol")
800
801 " Test 19: test diffopt+=iwhiteeol
802 call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar'])
803 call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol")
804
805 " Test 19: test diffopt+=iwhiteall
806 call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall")
807
782 " clean up 808 " clean up
783 call StopVimInTerminal(buf) 809 call StopVimInTerminal(buf)
784 call delete('Xfile1') 810 call delete('Xfile1')
785 call delete('Xfile2') 811 call delete('Xfile2')
786 endfunc 812 endfunc