diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-02-11 20:32:44 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-02-11 20:37:20 +0800 |
commit | 5546492c4449ee0d6262a23b0b26f49d1b43cf27 (patch) | |
tree | 9bb611e9f0e843f60d234a433a74d5d5967a2a17 | |
parent | 2db0a52074ab6b822edc1fa04eca399d4e727784 (diff) | |
download | rneovim-5546492c4449ee0d6262a23b0b26f49d1b43cf27.tar.gz rneovim-5546492c4449ee0d6262a23b0b26f49d1b43cf27.tar.bz2 rneovim-5546492c4449ee0d6262a23b0b26f49d1b43cf27.zip |
test: convert Test_file_changed_dialog() to Lua functional test
-rw-r--r-- | src/nvim/testdir/test_filechanged.vim | 2 | ||||
-rw-r--r-- | test/functional/legacy/filechanged_spec.lua | 76 |
2 files changed, 77 insertions, 1 deletions
diff --git a/src/nvim/testdir/test_filechanged.vim b/src/nvim/testdir/test_filechanged.vim index b95cd5faf8..b4c32fcc16 100644 --- a/src/nvim/testdir/test_filechanged.vim +++ b/src/nvim/testdir/test_filechanged.vim @@ -91,7 +91,7 @@ func Test_FileChangedShell_reload() endfunc func Test_file_changed_dialog() - throw 'skipped: TODO: ' + throw 'Skipped: requires a UI to a active' if !has('unix') || has('gui_running') return endif diff --git a/test/functional/legacy/filechanged_spec.lua b/test/functional/legacy/filechanged_spec.lua new file mode 100644 index 0000000000..fed7b27b0c --- /dev/null +++ b/test/functional/legacy/filechanged_spec.lua @@ -0,0 +1,76 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, source = helpers.clear, helpers.source +local call, eq, meths = helpers.call, helpers.eq, helpers.meths + +local function expected_empty() + eq({}, meths.get_vvar('errors')) +end + +describe('file changed dialog', function() + before_each(function() + clear() + meths.ui_attach(80, 24, {}) + meths.set_option('autoread', false) + source([[ + func Test_file_changed_dialog() + au! FileChangedShell + + new Xchanged_d + call setline(1, 'reload this') + write + " Need to wait until the timestamp would change by at least a second. + sleep 2 + silent !echo 'extra line' >>Xchanged_d + call nvim_input('L') + checktime + call assert_match('W11:', v:warningmsg) + call assert_equal(2, line('$')) + call assert_equal('reload this', getline(1)) + call assert_equal('extra line', getline(2)) + + " delete buffer, only shows an error, no prompt + silent !rm Xchanged_d + checktime + call assert_match('E211:', v:warningmsg) + call assert_equal(2, line('$')) + call assert_equal('extra line', getline(2)) + let v:warningmsg = 'empty' + + " change buffer, recreate the file and reload + call setline(1, 'buffer is changed') + silent !echo 'new line' >Xchanged_d + call nvim_input('L') + checktime + call assert_match('W12:', v:warningmsg) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + " Only mode changed, reload + silent !chmod +x Xchanged_d + call nvim_input('L') + checktime + call assert_match('W16:', v:warningmsg) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + " Only time changed, no prompt + sleep 2 + silent !touch Xchanged_d + let v:warningmsg = '' + checktime + call assert_equal('', v:warningmsg) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + bwipe! + call delete('Xchanged_d') + endfunc + ]]) + end) + + it('works', function() + if helpers.pending_win32(pending) then return end + call('Test_file_changed_dialog') + expected_empty() + end) +end) |