diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-09-16 21:02:49 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2019-09-16 21:36:46 -0400 |
commit | 792c2903435ceda05e68007d7bee344f65ee3a4f (patch) | |
tree | 8e5274f0d06366d4ba7714ae4ba2decb8a7c7a69 /src | |
parent | 0b71bb73e8431400c870dcd458f322dc50da96d1 (diff) | |
download | rneovim-792c2903435ceda05e68007d7bee344f65ee3a4f.tar.gz rneovim-792c2903435ceda05e68007d7bee344f65ee3a4f.tar.bz2 rneovim-792c2903435ceda05e68007d7bee344f65ee3a4f.zip |
vim-patch:8.0.1523: cannot write and read terminal screendumps
Problem: Cannot write and read terminal screendumps.
Solution: Add term_dumpwrite(), term_dumpread() and term_dumpdiff().
Also add assert_equalfile().
https://github.com/vim/vim/commit/d96ff165113ce5fe62107add590997660e3d4802
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 56 | ||||
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_assert.vim | 35 |
3 files changed, 92 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 1f753608d2..1a2bdcf88f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6961,6 +6961,56 @@ static void assert_equal_common(typval_T *argvars, assert_type_T atype) } } +static void assert_equalfile(typval_T *argvars) + FUNC_ATTR_NONNULL_ALL +{ + char buf1[NUMBUFLEN]; + char buf2[NUMBUFLEN]; + const char *const fname1 = tv_get_string_buf_chk(&argvars[0], buf1); + const char *const fname2 = tv_get_string_buf_chk(&argvars[1], buf2); + garray_T ga; + + if (fname1 == NULL || fname2 == NULL) { + return; + } + + IObuff[0] = NUL; + FILE *const fd1 = os_fopen(fname1, READBIN); + if (fd1 == NULL) { + snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname1); + } else { + FILE *const fd2 = os_fopen(fname2, READBIN); + if (fd2 == NULL) { + fclose(fd1); + snprintf((char *)IObuff, IOSIZE, (char *)e_notread, fname2); + } else { + for (int64_t count = 0; ; count++) { + const int c1 = fgetc(fd1); + const int c2 = fgetc(fd2); + if (c1 == EOF) { + if (c2 != EOF) { + STRCPY(IObuff, "first file is shorter"); + } + break; + } else if (c2 == EOF) { + STRCPY(IObuff, "second file is shorter"); + break; + } else if (c1 != c2) { + snprintf((char *)IObuff, IOSIZE, + "difference at byte %" PRId64, count); + break; + } + } + } + } + if (IObuff[0] != NUL) { + prepare_assert_error(&ga); + ga_concat(&ga, IObuff); + assert_error(&ga); + ga_clear(&ga); + } +} + static void f_assert_beeps(typval_T *argvars, typval_T *rettv, FunPtr fptr) { const char *const cmd = tv_get_string_chk(&argvars[0]); @@ -6988,6 +7038,12 @@ static void f_assert_equal(typval_T *argvars, typval_T *rettv, FunPtr fptr) assert_equal_common(argvars, ASSERT_EQUAL); } +// "assert_equalfile(fname-one, fname-two)" function +static void f_assert_equalfile(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + assert_equalfile(argvars); +} + // "assert_notequal(expected, actual[, msg])" function static void f_assert_notequal(typval_T *argvars, typval_T *rettv, FunPtr fptr) { diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index ab5ff57c2f..8efbcc71f1 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -28,6 +28,7 @@ return { asin={args=1, func="float_op_wrapper", data="&asin"}, -- WJMc assert_beeps={args={1, 2}}, assert_equal={args={2, 3}}, + assert_equalfile={args=2}, assert_exception={args={1, 2}}, assert_fails={args={1, 2}}, assert_false={args={1, 2}}, diff --git a/src/nvim/testdir/test_assert.vim b/src/nvim/testdir/test_assert.vim index a4c8ce7e43..cbb65ffc01 100644 --- a/src/nvim/testdir/test_assert.vim +++ b/src/nvim/testdir/test_assert.vim @@ -1,5 +1,40 @@ " Test that the methods used for testing work. +func Test_assert_equalfile() + call assert_equalfile('abcabc', 'xyzxyz') + call assert_match("E485: Can't read file abcabc", v:errors[0]) + call remove(v:errors, 0) + + let goodtext = ["one", "two", "three"] + call writefile(goodtext, 'Xone') + call assert_equalfile('Xone', 'xyzxyz') + call assert_match("E485: Can't read file xyzxyz", v:errors[0]) + call remove(v:errors, 0) + + call writefile(goodtext, 'Xtwo') + call assert_equalfile('Xone', 'Xtwo') + + call writefile([goodtext[0]], 'Xone') + call assert_equalfile('Xone', 'Xtwo') + call assert_match("first file is shorter", v:errors[0]) + call remove(v:errors, 0) + + call writefile(goodtext, 'Xone') + call writefile([goodtext[0]], 'Xtwo') + call assert_equalfile('Xone', 'Xtwo') + call assert_match("second file is shorter", v:errors[0]) + call remove(v:errors, 0) + + call writefile(['1234X89'], 'Xone') + call writefile(['1234Y89'], 'Xtwo') + call assert_equalfile('Xone', 'Xtwo') + call assert_match("difference at byte 4", v:errors[0]) + call remove(v:errors, 0) + + call delete('Xone') + call delete('Xtwo') +endfunc + func Test_assert_fails_in_try_block() try call assert_equal(0, assert_fails('throw "error"')) |