From 68603998b91a7fbf9a6cb415a51526fbd88b6581 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 8 Feb 2022 14:47:23 +0800 Subject: [PATCH] test: add Lua functional tests for Ex mode --- src/nvim/testdir/test_ex_mode.vim | 5 ++-- test/functional/legacy/ex_mode_spec.lua | 36 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/functional/legacy/ex_mode_spec.lua diff --git a/src/nvim/testdir/test_ex_mode.vim b/src/nvim/testdir/test_ex_mode.vim index 78663f7deb..dcec5f7cc6 100644 --- a/src/nvim/testdir/test_ex_mode.vim +++ b/src/nvim/testdir/test_ex_mode.vim @@ -29,12 +29,11 @@ endfunc " Test editing line in Ex mode (both Q and gQ) func Test_ex_mode() - throw 'skipped: TODO: ' + throw 'Skipped: Nvim only supports Vim Ex mode' let encoding_save = &encoding set sw=2 - " for e in ['utf8', 'latin1'] - for e in ['utf8'] + for e in ['utf8', 'latin1'] exe 'set encoding=' . e call assert_equal(['bar', 'bar'], Ex("foo bar\bar"), e) diff --git a/test/functional/legacy/ex_mode_spec.lua b/test/functional/legacy/ex_mode_spec.lua new file mode 100644 index 0000000000..44719027a6 --- /dev/null +++ b/test/functional/legacy/ex_mode_spec.lua @@ -0,0 +1,36 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval +local feed = helpers.feed +local meths = helpers.meths + +before_each(clear) + +describe('Ex mode', function() + it('supports command line editing', function() + local function test_ex_edit(expected, cmd) + feed('gQ' .. cmd .. '"') + local ret = eval('@:[1:]') -- Remove leading quote. + feed('visual') + eq(meths.replace_termcodes(expected, true, true, true), ret) + end + command('set sw=2') + test_ex_edit('bar', 'foo barbar') + test_ex_edit('12', '12') + test_ex_edit('213', '123') + test_ex_edit('2013', '0123') + test_ex_edit('0213', '0123') + test_ex_edit('0342', '01234') + test_ex_edit('foo ', 'foo bar') + test_ex_edit('foo', 'fooba') + test_ex_edit('foobar', 'foobar') + test_ex_edit('abbreviate', 'abbrev') + test_ex_edit('1', '1') + test_ex_edit('1', '1') + test_ex_edit(' foo', ' foo') + test_ex_edit(' foo0', ' foo0') + test_ex_edit(' foo^', ' foo^') + end) +end)