From 3a2afb3caef282677b40723155e0bde519671901 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Mon, 15 Nov 2021 13:11:42 +0900 Subject: [PATCH] Add cmdline expansion test --- lua/cmp/core_spec.lua | 51 ++++++++++++++++++++++++++++++++++++++++-- lua/cmp/utils/spec.lua | 5 +++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/lua/cmp/core_spec.lua b/lua/cmp/core_spec.lua index ae45c72..8ffb286 100644 --- a/lua/cmp/core_spec.lua +++ b/lua/cmp/core_spec.lua @@ -4,6 +4,7 @@ local types = require('cmp.types') local core = require('cmp.core') local source = require('cmp.source') local keymap = require('cmp.utils.keymap') +local api = require('cmp.utils.api') describe('cmp.core', function() describe('confirm', function() @@ -27,8 +28,12 @@ describe('cmp.core', function() local state = {} feedkeys.call('', 'x', function() feedkeys.call('', 'n', function() - state.buffer = vim.api.nvim_buf_get_lines(0, 0, -1, false) - state.cursor = vim.api.nvim_win_get_cursor(0) + if api.is_cmdline_mode() then + state.buffer = { api.get_current_line() } + else + state.buffer = vim.api.nvim_buf_get_lines(0, 0, -1, false) + end + state.cursor = api.get_cursor() end) end) return state @@ -107,5 +112,47 @@ describe('cmp.core', function() assert.are.same(state.cursor, { 2, 2 }) end) end) + + describe('cmdline-mode', function() + before_each(spec.before) + + it('label', function() + local state = confirm(':A', 'IU', { + label = 'AIUEO', + }) + assert.are.same(state.buffer, { 'AIUEO' }) + assert.are.same(state.cursor[2], 5) + end) + + it('insertText', function() + local state = confirm(':A', 'IU', { + label = 'AIUEO', + insertText = '_AIUEO_', + }) + assert.are.same(state.buffer, { '_AIUEO_' }) + assert.are.same(state.cursor[2], 7) + end) + + it('text edit', function() + local state = confirm(keymap.t(':***AEO***'), 'IU', { + label = 'AIUEO', + textEdit = { + range = { + start = { + line = 0, + character = 3, + }, + ['end'] = { + line = 0, + character = 6, + }, + }, + newText = 'foobarbaz', + }, + }) + assert.are.same(state.buffer, { '***foobarbaz***' }) + assert.are.same(state.cursor[2], 12) + end) + end) end) end) diff --git a/lua/cmp/utils/spec.lua b/lua/cmp/utils/spec.lua index 6fb49f6..a4b2c83 100644 --- a/lua/cmp/utils/spec.lua +++ b/lua/cmp/utils/spec.lua @@ -45,6 +45,11 @@ spec.before = function() end, }, }) + config.set_cmdline({ + sources = { + { name = 'spec' }, + }, + }, ':') end spec.state = function(text, row, col)