2016-09-03 16:25:24 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
2017-04-01 13:57:34 -07:00
|
|
|
local eq = helpers.eq
|
2016-09-03 16:25:24 -07:00
|
|
|
local feed = helpers.feed
|
2017-04-01 13:57:34 -07:00
|
|
|
local meths = helpers.meths
|
2016-09-03 16:25:24 -07:00
|
|
|
local clear = helpers.clear
|
2017-04-01 13:57:34 -07:00
|
|
|
local source = helpers.source
|
2016-09-03 16:25:24 -07:00
|
|
|
local command = helpers.command
|
2017-04-01 13:57:34 -07:00
|
|
|
local exc_exec = helpers.exc_exec
|
2016-09-03 16:25:24 -07:00
|
|
|
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(25, 5)
|
|
|
|
screen:attach()
|
2017-04-01 13:57:34 -07:00
|
|
|
source([[
|
|
|
|
hi Test ctermfg=Red guifg=Red term=bold
|
|
|
|
function CustomCompl(...)
|
|
|
|
return 'TEST'
|
|
|
|
endfunction
|
|
|
|
function CustomListCompl(...)
|
|
|
|
return ['FOO']
|
|
|
|
endfunction
|
2017-04-01 15:00:40 -07:00
|
|
|
|
|
|
|
highlight RBP1 guibg=Red
|
|
|
|
highlight RBP2 guibg=Yellow
|
|
|
|
highlight RBP3 guibg=Green
|
|
|
|
highlight RBP4 guibg=Blue
|
|
|
|
let g:NUM_LVLS = 4
|
|
|
|
function Redraw()
|
|
|
|
redraw!
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
cnoremap <expr> {REDRAW} Redraw()
|
|
|
|
function RainBowParens(cmdline)
|
|
|
|
let ret = []
|
|
|
|
let i = 0
|
|
|
|
let lvl = 0
|
|
|
|
while i < len(a:cmdline)
|
|
|
|
if a:cmdline[i] is# '('
|
|
|
|
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
|
|
|
|
let lvl += 1
|
|
|
|
elseif a:cmdline[i] is# ')'
|
|
|
|
let lvl -= 1
|
|
|
|
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
|
|
|
|
endif
|
|
|
|
let i += 1
|
|
|
|
endwhile
|
|
|
|
return ret
|
|
|
|
endfunction
|
2017-04-01 13:57:34 -07:00
|
|
|
]])
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
EOB={bold = true, foreground = Screen.colors.Blue1},
|
|
|
|
T={foreground=Screen.colors.Red},
|
2017-04-01 15:00:40 -07:00
|
|
|
RBP1={background=Screen.colors.Red},
|
|
|
|
RBP2={background=Screen.colors.Yellow},
|
|
|
|
RBP3={background=Screen.colors.Green},
|
|
|
|
RBP4={background=Screen.colors.Blue},
|
2018-03-31 02:12:27 -07:00
|
|
|
SEP={bold = true, reverse = true},
|
2017-04-01 13:57:34 -07:00
|
|
|
})
|
2016-09-03 16:25:24 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('input()', function()
|
2017-05-13 07:04:54 -07:00
|
|
|
it('works with multiline prompts', function()
|
2016-09-03 16:25:24 -07:00
|
|
|
feed([[:call input("Test\nFoo")<CR>]])
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2017-04-01 13:57:34 -07:00
|
|
|
{EOB:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{SEP: }|
|
2016-09-03 16:25:24 -07:00
|
|
|
Test |
|
|
|
|
Foo^ |
|
2017-04-01 13:57:34 -07:00
|
|
|
]])
|
2016-09-03 16:25:24 -07:00
|
|
|
end)
|
2017-05-13 07:04:54 -07:00
|
|
|
it('works with multiline prompts and :echohl', function()
|
2016-09-03 16:25:24 -07:00
|
|
|
feed([[:echohl Test | call input("Test\nFoo")<CR>]])
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2017-04-01 13:57:34 -07:00
|
|
|
{EOB:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{SEP: }|
|
2017-04-01 13:57:34 -07:00
|
|
|
{T:Test} |
|
|
|
|
{T:Foo}^ |
|
|
|
|
]])
|
|
|
|
command('redraw!')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:07:31 -07:00
|
|
|
it('allows unequal numeric arguments when using multiple args', function()
|
2017-05-10 13:14:23 -07:00
|
|
|
command('echohl Test')
|
|
|
|
feed([[:call input(1, 2)<CR>]])
|
2017-04-01 13:57:34 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}2^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:07:31 -07:00
|
|
|
it('allows unequal numeric values when using {opts} dictionary', function()
|
2017-05-11 02:15:41 -07:00
|
|
|
command('echohl Test')
|
|
|
|
meths.set_var('opts', {prompt=1, default=2, cancelreturn=3})
|
|
|
|
feed([[:echo input(opts)<CR>]])
|
2017-04-01 13:57:34 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}2^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}^ |
|
|
|
|
]])
|
|
|
|
feed('<Esc>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:3} |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:04:54 -07:00
|
|
|
it('works with redraw', function()
|
2017-05-11 02:15:41 -07:00
|
|
|
command('echohl Test')
|
|
|
|
meths.set_var('opts', {prompt='Foo>', default='Bar'})
|
|
|
|
feed([[:echo inputdialog(opts)<CR>]])
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Bar^ |
|
|
|
|
]])
|
|
|
|
command('redraw!')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Bar^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Ba^ |
|
|
|
|
]])
|
|
|
|
command('redraw!')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Ba^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-04-01 13:57:34 -07:00
|
|
|
it('allows omitting everything with dictionary argument', function()
|
2017-05-10 13:14:23 -07:00
|
|
|
command('echohl Test')
|
|
|
|
feed([[:call input({})<CR>]])
|
2017-04-01 13:57:34 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('supports completion', function()
|
|
|
|
feed(':let var = input("", "", "custom,CustomCompl")<CR>')
|
|
|
|
feed('<Tab><CR>')
|
|
|
|
eq('TEST', meths.get_var('var'))
|
|
|
|
|
|
|
|
feed(':let var = input({"completion": "customlist,CustomListCompl"})<CR>')
|
|
|
|
feed('<Tab><CR>')
|
|
|
|
eq('FOO', meths.get_var('var'))
|
|
|
|
end)
|
|
|
|
it('supports cancelreturn', function()
|
|
|
|
feed(':let var = input({"cancelreturn": "BAR"})<CR>')
|
|
|
|
feed('<Esc>')
|
|
|
|
eq('BAR', meths.get_var('var'))
|
|
|
|
end)
|
|
|
|
it('supports default string', function()
|
|
|
|
feed(':let var = input("", "DEF1")<CR>')
|
|
|
|
feed('<CR>')
|
|
|
|
eq('DEF1', meths.get_var('var'))
|
|
|
|
|
|
|
|
feed(':let var = input({"default": "DEF2"})<CR>')
|
|
|
|
feed('<CR>')
|
|
|
|
eq('DEF2', meths.get_var('var'))
|
|
|
|
end)
|
|
|
|
it('errors out on invalid inputs', function()
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input([])'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input("", [])'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input("", "", [])'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input({"prompt": []})'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input({"cancelreturn": []})'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input({"default": []})'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call input({"completion": []})'))
|
2017-04-08 11:30:47 -07:00
|
|
|
eq('Vim(call):E5050: {opts} must be the only argument',
|
|
|
|
exc_exec('call input({}, "default")'))
|
|
|
|
eq('Vim(call):E118: Too many arguments for function: input',
|
|
|
|
exc_exec('call input("prompt> ", "default", "file", "extra")'))
|
2017-04-01 13:57:34 -07:00
|
|
|
end)
|
2017-04-01 15:00:40 -07:00
|
|
|
it('supports highlighting', function()
|
2017-08-06 04:43:46 -07:00
|
|
|
command('nnoremap <expr> X input({"highlight": "RainBowParens"})[-1]')
|
|
|
|
feed([[X]])
|
2017-04-01 15:00:40 -07:00
|
|
|
feed('(())')
|
|
|
|
screen:expect([[
|
2017-08-06 04:43:46 -07:00
|
|
|
|
|
2017-04-01 15:00:40 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{RBP1:(}{RBP2:()}{RBP1:)}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-10-11 21:49:47 -07:00
|
|
|
it('is not hidden by :silent', function()
|
|
|
|
feed([[:silent call input('Foo: ')<CR>]])
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2017-10-11 21:49:47 -07:00
|
|
|
{EOB:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{SEP: }|
|
2017-10-11 21:49:47 -07:00
|
|
|
Foo: ^ |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
feed('Bar')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2017-10-11 21:49:47 -07:00
|
|
|
{EOB:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{SEP: }|
|
2017-10-11 21:49:47 -07:00
|
|
|
Foo: Bar^ |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
feed('<CR>')
|
|
|
|
end)
|
2017-04-01 13:57:34 -07:00
|
|
|
end)
|
|
|
|
describe('inputdialog()', function()
|
2017-05-13 07:04:54 -07:00
|
|
|
it('works with multiline prompts', function()
|
2017-04-01 13:57:34 -07:00
|
|
|
feed([[:call inputdialog("Test\nFoo")<CR>]])
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2017-04-01 13:57:34 -07:00
|
|
|
{EOB:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{SEP: }|
|
2017-04-01 13:57:34 -07:00
|
|
|
Test |
|
|
|
|
Foo^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:04:54 -07:00
|
|
|
it('works with multiline prompts and :echohl', function()
|
2017-04-01 13:57:34 -07:00
|
|
|
feed([[:echohl Test | call inputdialog("Test\nFoo")<CR>]])
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2017-04-01 13:57:34 -07:00
|
|
|
{EOB:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{SEP: }|
|
2017-04-01 13:57:34 -07:00
|
|
|
{T:Test} |
|
|
|
|
{T:Foo}^ |
|
|
|
|
]])
|
|
|
|
command('redraw!')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:07:31 -07:00
|
|
|
it('allows unequal numeric arguments when using multiple args', function()
|
2017-05-10 13:14:23 -07:00
|
|
|
command('echohl Test')
|
|
|
|
feed([[:call inputdialog(1, 2)<CR>]])
|
2017-04-01 13:57:34 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}2^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:07:31 -07:00
|
|
|
it('allows unequal numeric values when using {opts} dictionary', function()
|
2017-05-11 02:15:41 -07:00
|
|
|
command('echohl Test')
|
|
|
|
meths.set_var('opts', {prompt=1, default=2, cancelreturn=3})
|
|
|
|
feed([[:echo input(opts)<CR>]])
|
2017-04-01 13:57:34 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}2^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:1}^ |
|
|
|
|
]])
|
|
|
|
feed('<Esc>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:3} |
|
|
|
|
]])
|
|
|
|
end)
|
2017-05-13 07:04:54 -07:00
|
|
|
it('works with redraw', function()
|
2017-05-11 02:15:41 -07:00
|
|
|
command('echohl Test')
|
|
|
|
meths.set_var('opts', {prompt='Foo>', default='Bar'})
|
|
|
|
feed([[:echo input(opts)<CR>]])
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Bar^ |
|
|
|
|
]])
|
|
|
|
command('redraw!')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Bar^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Ba^ |
|
|
|
|
]])
|
|
|
|
command('redraw!')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{T:Foo>}Ba^ |
|
|
|
|
]])
|
|
|
|
end)
|
2017-04-01 13:57:34 -07:00
|
|
|
it('allows omitting everything with dictionary argument', function()
|
2017-05-10 13:14:23 -07:00
|
|
|
command('echohl Test')
|
|
|
|
feed(':echo inputdialog({})<CR>')
|
2017-04-01 13:57:34 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('supports completion', function()
|
|
|
|
feed(':let var = inputdialog({"completion": "customlist,CustomListCompl"})<CR>')
|
|
|
|
feed('<Tab><CR>')
|
|
|
|
eq('FOO', meths.get_var('var'))
|
|
|
|
end)
|
|
|
|
it('supports cancelreturn', function()
|
|
|
|
feed(':let var = inputdialog("", "", "CR1")<CR>')
|
|
|
|
feed('<Esc>')
|
|
|
|
eq('CR1', meths.get_var('var'))
|
|
|
|
|
|
|
|
feed(':let var = inputdialog({"cancelreturn": "BAR"})<CR>')
|
|
|
|
feed('<Esc>')
|
|
|
|
eq('BAR', meths.get_var('var'))
|
|
|
|
end)
|
|
|
|
it('supports default string', function()
|
|
|
|
feed(':let var = inputdialog("", "DEF1")<CR>')
|
|
|
|
feed('<CR>')
|
|
|
|
eq('DEF1', meths.get_var('var'))
|
|
|
|
|
|
|
|
feed(':let var = inputdialog({"default": "DEF2"})<CR>')
|
|
|
|
feed('<CR>')
|
|
|
|
eq('DEF2', meths.get_var('var'))
|
|
|
|
end)
|
|
|
|
it('errors out on invalid inputs', function()
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog([])'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog("", [])'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog("", "", [])'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog({"prompt": []})'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog({"cancelreturn": []})'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog({"default": []})'))
|
|
|
|
eq('Vim(call):E730: using List as a String',
|
|
|
|
exc_exec('call inputdialog({"completion": []})'))
|
2017-04-08 11:30:47 -07:00
|
|
|
eq('Vim(call):E5050: {opts} must be the only argument',
|
|
|
|
exc_exec('call inputdialog({}, "default")'))
|
|
|
|
eq('Vim(call):E118: Too many arguments for function: inputdialog',
|
|
|
|
exc_exec('call inputdialog("prompt> ", "default", "file", "extra")'))
|
2016-09-03 16:25:24 -07:00
|
|
|
end)
|
2017-04-01 15:00:40 -07:00
|
|
|
it('supports highlighting', function()
|
2017-08-06 04:43:46 -07:00
|
|
|
command('nnoremap <expr> X inputdialog({"highlight": "RainBowParens"})[-1]')
|
|
|
|
feed([[X]])
|
2017-04-01 15:00:40 -07:00
|
|
|
feed('(())')
|
|
|
|
screen:expect([[
|
2017-08-06 04:43:46 -07:00
|
|
|
|
|
2017-04-01 15:00:40 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{RBP1:(}{RBP2:()}{RBP1:)}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2016-09-03 16:25:24 -07:00
|
|
|
end)
|