diff options
| author | Björn Linse <bjorn.linse@gmail.com> | 2019-03-02 17:26:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-02 17:26:50 +0100 |
| commit | 7a6da502b9d8deecfc89d1497a8e8da15e65f31e (patch) | |
| tree | e3811b52dd00e67175383f11f1b67b42acc88f4c /test/functional/ui/float_spec.lua | |
| parent | 0aba4d825a5b18c5fa937c0426788f61f756e086 (diff) | |
| parent | 9a1675b065394734ddaef91a314896028e2b1d46 (diff) | |
| download | rneovim-7a6da502b9d8deecfc89d1497a8e8da15e65f31e.tar.gz rneovim-7a6da502b9d8deecfc89d1497a8e8da15e65f31e.tar.bz2 rneovim-7a6da502b9d8deecfc89d1497a8e8da15e65f31e.zip | |
Merge pull request #6619 from bfredl/floating
Floating windows in TUI and Remote UI
Diffstat (limited to 'test/functional/ui/float_spec.lua')
| -rw-r--r-- | test/functional/ui/float_spec.lua | 3030 |
1 files changed, 3030 insertions, 0 deletions
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua new file mode 100644 index 0000000000..0d0ae60ce9 --- /dev/null +++ b/test/functional/ui/float_spec.lua @@ -0,0 +1,3030 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local os = require('os') +local clear, feed = helpers.clear, helpers.feed +local command, feed_command = helpers.command, helpers.feed_command +local eval = helpers.eval +local eq = helpers.eq +local meths = helpers.meths +local curbufmeths = helpers.curbufmeths +local funcs = helpers.funcs +local run = helpers.run +local meth_pcall = helpers.meth_pcall + +describe('floating windows', function() + before_each(function() + clear() + end) + local attrs = { + [0] = {bold=true, foreground=Screen.colors.Blue}, + [1] = {background = Screen.colors.LightMagenta}, + [2] = {background = Screen.colors.LightMagenta, bold = true, foreground = Screen.colors.Blue1}, + [3] = {bold = true}, + [4] = {bold = true, reverse = true}, + [5] = {reverse = true}, + [6] = {background = Screen.colors.LightMagenta, bold = true, reverse = true}, + [7] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [8] = {bold = true, foreground = Screen.colors.SeaGreen4}, + [9] = {background = Screen.colors.LightGrey, underline = true}, + [10] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta}, + [11] = {bold = true, foreground = Screen.colors.Magenta}, + [12] = {background = Screen.colors.Red, bold = true, foreground = Screen.colors.Blue1}, + [13] = {background = Screen.colors.WebGray} + } + + local function with_ext_multigrid(multigrid) + local screen + before_each(function() + screen = Screen.new(40,7) + screen:attach({ext_multigrid=multigrid}) + screen:set_default_attr_ids(attrs) + end) + + it('can be created and reconfigured', function() + local buf = meths.create_buf(false,false) + local win = meths.open_win(buf, false, 20, 2, {relative='editor', row=2, col=5}) + meths.win_set_option(win , 'winhl', 'Normal:PMenu') + local expected_pos = { + [3]={{id=1001}, 'NW', 1, 2, 5, true}, + } + + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1: }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ | + {0:~ }| + {0:~ }{1: }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + {0:~ }| + | + ]]) + end + + + meths.win_config(win,0,0,{relative='editor', row=0, col=10}) + expected_pos[3][4] = 0 + expected_pos[3][5] = 10 + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1: }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ {1: } | + {0:~ }{2:~ }{0: }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end + end) + + it('API has proper error messages', function() + local buf = meths.create_buf(false,false) + eq({false, "Invalid options key 'bork'"}, + meth_pcall(meths.open_win,buf, false, 20, 2, {bork=true})) + eq({false, "'win' option is only valid with relative='win'"}, + meth_pcall(meths.open_win,buf, false, 20, 2, {relative='editor',row=0,col=0,win=0})) + eq({false, "Only one of 'relative' and 'external' should be used"}, + meth_pcall(meths.open_win,buf, false, 20, 2, {relative='editor',row=0,col=0,external=true})) + eq({false, "Invalid value of 'relative' option"}, + meth_pcall(meths.open_win,buf, false, 20, 2, {relative='shell',row=0,col=0})) + eq({false, "Invalid value of 'anchor' option"}, + meth_pcall(meths.open_win,buf, false, 20, 2, {relative='editor',row=0,col=0,anchor='bottom'})) + eq({false, "All of 'relative', 'row', and 'col' has to be specified at once"}, + meth_pcall(meths.open_win,buf, false, 20, 2, {relative='editor'})) + end) + + it('can be placed relative window or cursor', function() + screen:try_resize(40,9) + meths.buf_set_lines(0, 0, -1, true, {'just some', 'example text'}) + feed('gge') + local oldwin = meths.get_current_win() + command('below split') + if multigrid then + screen:expect([[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ]]) + else + screen:expect([[ + just some | + example text | + {0:~ }| + {5:[No Name] [+] }| + jus^t some | + example text | + {0:~ }| + {4:[No Name] [+] }| + | + ]]) + end + + local buf = meths.create_buf(false,false) + -- no 'win' arg, relative default window + local win = meths.open_win(buf, false, 20, 2, {relative='win', row=0, col=10}) + meths.win_set_option(win, 'winhl', 'Normal:PMenu') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1002}, "NW", 3, 0, 10, true} + }} + else + screen:expect([[ + just some | + example text | + {0:~ }| + {5:[No Name] [+] }| + jus^t some {1: } | + example te{2:~ } | + {0:~ }| + {4:[No Name] [+] }| + | + ]]) + end + + meths.win_config(win, -1, -1, {relative='cursor', row=1, col=-2}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1002}, "NW", 3, 1, 1, true} + }} + else + screen:expect([[ + just some | + example text | + {0:~ }| + {5:[No Name] [+] }| + jus^t some | + e{1: } | + {0:~}{2:~ }{0: }| + {4:[No Name] [+] }| + | + ]]) + end + + meths.win_config(win, -1, -1, {relative='cursor', row=0, col=0, anchor='SW'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1002}, "SW", 3, 0, 3, true} + }} + else + screen:expect([[ + just some | + example text | + {0:~ }{1: }{0: }| + {5:[No}{2:~ }{5: }| + jus^t some | + example text | + {0:~ }| + {4:[No Name] [+] }| + | + ]]) + end + + + meths.win_config(win, -1, -1, {relative='win', win=oldwin, row=1, col=10, anchor='NW'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1002}, "NW", 2, 1, 10, true} + }} + else + screen:expect([[ + just some | + example te{1: } | + {0:~ }{2:~ }{0: }| + {5:[No Name] [+] }| + jus^t some | + example text | + {0:~ }| + {4:[No Name] [+] }| + | + ]]) + end + + meths.win_config(win, -1, -1, {relative='win', win=oldwin, row=3, col=39, anchor='SE'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1002}, "SE", 2, 3, 39, true} + }} + else + screen:expect([[ + just some | + example text {1: } | + {0:~ }{2:~ }{0: }| + {5:[No Name] [+] }| + jus^t some | + example text | + {0:~ }| + {4:[No Name] [+] }| + | + ]]) + end + + meths.win_config(win, -1, -1, {relative='win', win=0, row=0, col=50, anchor='NE'}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + [3:----------------------------------------]| + [3:----------------------------------------]| + [3:----------------------------------------]| + {4:[No Name] [+] }| + | + ## grid 2 + just some | + example text | + {0:~ }| + ## grid 3 + jus^t some | + example text | + {0:~ }| + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {{id = 1002}, "NE", 3, 0, 50, true} + }} + else + screen:expect([[ + just some | + example text | + {0:~ }| + {5:[No Name] [+] }| + jus^t some {1: }| + example text {2:~ }| + {0:~ }| + {4:[No Name] [+] }| + | + ]]) + end + end) + + if multigrid then + pending("supports second UI without multigrid", function() + local session2 = helpers.connect(eval('v:servername')) + print(session2:request("nvim_eval", "2+2")) + local screen2 = Screen.new(40,7) + screen2:attach(nil, session2) + screen2:set_default_attr_ids(attrs) + local buf = meths.create_buf(false,false) + local win = meths.open_win(buf, true, 20, 2, {relative='editor', row=2, col=5}) + meths.win_set_option(win, 'winhl', 'Normal:PMenu') + local expected_pos = { + [2]={{id=1001}, 'NW', 1, 2, 5} + } + screen:expect{grid=[[ + ## grid 1 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + | + ## grid 2 + {1:^ }| + {2:~ }| + ]], float_pos=expected_pos} + screen2:expect([[ + | + {0:~ }| + {0:~ }{1:^ }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + {0:~ }| + | + ]]) + end) + end + + + it('handles resized screen', function() + local buf = meths.create_buf(false,false) + meths.buf_set_lines(buf, 0, -1, true, {'such', 'very', 'float'}) + local win = meths.open_win(buf, false, 15, 4, {relative='editor', row=2, col=10}) + meths.win_set_option(win , 'winhl', 'Normal:PMenu') + local expected_pos = { + [3]={{id=1001}, 'NW', 1, 2, 10, true}, + } + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:such }| + {1:very }| + {1:float }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ | + {0:~ }| + {0:~ }{1:such }{0: }| + {0:~ }{1:very }{0: }| + {0:~ }{1:float }{0: }| + {0:~ }{2:~ }{0: }| + | + ]]) + end + + screen:try_resize(40,5) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:such }| + {1:very }| + {1:float }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ {1:such } | + {0:~ }{1:very }{0: }| + {0:~ }{1:float }{0: }| + {0:~ }{2:~ }{0: }| + | + ]]) + end + + screen:try_resize(40,4) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + ^ | + {0:~ }| + {0:~ }| + ## grid 3 + {1:such }| + {1:very }| + {1:float }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ {1:such } | + {0:~ }{1:very }{0: }| + {0:~ }{1:float }{0: }| + | + ]]) + end + + screen:try_resize(40,3) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + ^ | + {0:~ }| + ## grid 3 + {1:such }| + {1:very }| + {1:float }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + ^ {1:such } | + {0:~ }{1:very }{0: }| + | + ]]) + end + feed('<c-w>wjj') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + | + {0:~ }| + ## grid 3 + {1:such }| + {1:very }| + {1:^float }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + {1:very } | + {0:~ }{1:^float }{0: }| + | + ]]) + end + + screen:try_resize(40,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:such }| + {1:very }| + {1:^float }| + {2:~ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {0:~ }{1:very }{0: }| + {0:~ }{1:^float }{0: }| + {0:~ }| + {0:~ }| + | + ]]) + end + + meths.win_config(win, -1, 3, {}) + feed('gg') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {0:~ }{1:^such }{0: }| + {0:~ }{1:very }{0: }| + {0:~ }{1:float }{0: }| + {0:~ }| + | + ]]) + end + + screen:try_resize(26,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:--------------------------]| + [2:--------------------------]| + [2:--------------------------]| + [2:--------------------------]| + [2:--------------------------]| + [2:--------------------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {0:~ }{1:^such }{0: }| + {0:~ }{1:very }{0: }| + {0:~ }{1:float }{0: }| + {0:~ }| + | + ]]) + end + + screen:try_resize(25,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + [2:-------------------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {0:~ }{1:^such }| + {0:~ }{1:very }| + {0:~ }{1:float }| + {0:~ }| + | + ]]) + end + + screen:try_resize(24,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:------------------------]| + [2:------------------------]| + [2:------------------------]| + [2:------------------------]| + [2:------------------------]| + [2:------------------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {0:~ }{1:^such }| + {0:~ }{1:very }| + {0:~ }{1:float }| + {0:~ }| + | + ]]) + end + + screen:try_resize(16,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------]| + [2:----------------]| + [2:----------------]| + [2:----------------]| + [2:----------------]| + [2:----------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {0:~}{1:^such }| + {0:~}{1:very }| + {0:~}{1:float }| + {0:~ }| + | + ]]) + end + + screen:try_resize(15,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:---------------]| + [2:---------------]| + [2:---------------]| + [2:---------------]| + [2:---------------]| + [2:---------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {1:^such }| + {1:very }| + {1:float }| + {0:~ }| + | + ]]) + end + + screen:try_resize(14,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:--------------]| + [2:--------------]| + [2:--------------]| + [2:--------------]| + [2:--------------]| + [2:--------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| + {1:float }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {1:^such }| + {1:very }| + {1:float }| + {0:~ }| + | + ]]) + end + + screen:try_resize(12,7) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:------------]| + [2:------------]| + [2:------------]| + [2:------------]| + [2:------------]| + [2:------------]| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^such }| + {1:very }| |