aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/tui_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/terminal/tui_spec.lua')
-rw-r--r--test/functional/terminal/tui_spec.lua251
1 files changed, 163 insertions, 88 deletions
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index 364ca327a4..60f989d701 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -1,11 +1,13 @@
-- Some sanity checks for the TUI using the builtin terminal emulator
-- as a simple way to send keys and assert screen state.
-local helpers = require('test.functional.helpers')
+local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
local feed = thelpers.feed_data
local execute = helpers.execute
local nvim_dir = helpers.nvim_dir
+if helpers.pending_win32(pending) then return end
+
describe('tui', function()
local screen
@@ -17,12 +19,12 @@ describe('tui', function()
screen.timeout = 60000
screen:expect([[
{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
|
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
@@ -36,20 +38,20 @@ describe('tui', function()
abc |
test1 |
test2{1: } |
- ~ |
- [No Name] [+] |
- -- INSERT -- |
- -- TERMINAL -- |
+ {4:~ }|
+ {5:[No Name] [+] }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
]])
feed('\027')
screen:expect([[
abc |
test1 |
test{1:2} |
- ~ |
- [No Name] [+] |
+ {4:~ }|
+ {5:[No Name] [+] }|
|
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
@@ -64,9 +66,9 @@ describe('tui', function()
alt-k |
alt-l |
{1: } |
- [No Name] [+] |
+ {5:[No Name] [+] }|
|
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
feed('gg')
screen:expect([[
@@ -74,9 +76,9 @@ describe('tui', function()
alt-f |
alt-g |
alt-h |
- [No Name] [+] |
+ {5:[No Name] [+] }|
|
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
@@ -90,12 +92,12 @@ describe('tui', function()
feed('i\027j')
screen:expect([[
j{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] [+] |
- -- INSERT -- |
- -- TERMINAL -- |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
]])
end)
@@ -105,46 +107,46 @@ describe('tui', function()
feed('\022\022') -- ctrl+v
feed('\022\013') -- ctrl+m
screen:expect([[
- {3:^G^V^M}{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] [+] |
- -- INSERT -- |
- -- TERMINAL -- |
- ]], {[1] = {reverse = true}, [2] = {background = 11}, [3] = {foreground = 4}})
+ {9:^G^V^M}{1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
+ ]])
end)
it('automatically sends <Paste> for bracketed paste sequences', function()
feed('i\027[200~')
screen:expect([[
{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] |
- -- INSERT (paste) -- |
- -- TERMINAL -- |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
+ {3:-- INSERT (paste) --} |
+ {3:-- TERMINAL --} |
]])
feed('pasted from terminal')
screen:expect([[
pasted from terminal{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] [+] |
- -- INSERT (paste) -- |
- -- TERMINAL -- |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ {3:-- INSERT (paste) --} |
+ {3:-- TERMINAL --} |
]])
feed('\027[201~')
screen:expect([[
pasted from terminal{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] [+] |
- -- INSERT -- |
- -- TERMINAL -- |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] [+] }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
]])
end)
@@ -160,9 +162,9 @@ describe('tui', function()
item 2998 |
item 2999 |
item 3000{1: } |
- [No Name] [+] 3000,10 Bot|
- -- INSERT -- |
- -- TERMINAL -- |
+ {5:[No Name] [+] 3000,10 Bot}|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
]])
end)
end)
@@ -176,17 +178,15 @@ describe('tui with non-tty file descriptors', function()
it('can handle pipes as stdout and stderr', function()
local screen = thelpers.screen_setup(0, '"'..helpers.nvim_prog..' -u NONE -i NONE --cmd \'set noswapfile\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"')
- screen:set_default_attr_ids({})
- screen:set_default_attr_ignore(true)
feed(':w testF\n:q\n')
screen:expect([[
:w testF |
:q |
abc |
|
- [Process exited 0] |
+ [Process exited 0]{1: } |
|
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
end)
@@ -205,23 +205,23 @@ describe('tui focus event handling', function()
feed('\027[I')
screen:expect([[
{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
gained |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
feed('\027[O')
screen:expect([[
{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
lost |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
@@ -231,22 +231,22 @@ describe('tui focus event handling', function()
feed('\027[I')
screen:expect([[
{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
gained |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
feed('\027[O')
screen:expect([[
{1: } |
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
lost |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
@@ -255,22 +255,22 @@ describe('tui focus event handling', function()
feed('\027[I')
screen:expect([[
|
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
g{1:a}ined |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
feed('\027[O')
screen:expect([[
|
- ~ |
- ~ |
- ~ |
- [No Name] |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {5:[No Name] }|
l{1:o}st |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
@@ -287,7 +287,7 @@ describe('tui focus event handling', function()
|
|
gained |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
feed('\027[O')
screen:expect([[
@@ -297,7 +297,82 @@ describe('tui focus event handling', function()
|
|
lost |
- -- TERMINAL -- |
+ {3:-- TERMINAL --} |
]])
end)
end)
+
+-- These tests require `thelpers` because --headless/--embed
+-- does not initialize the TUI.
+describe("tui 't_Co' (terminal colors)", function()
+ local screen
+ local is_linux = (helpers.eval("system('uname') =~? 'linux'") == 1)
+
+ local function assert_term_colors(term, colorterm, maxcolors)
+ helpers.clear({env={TERM=term}, args={}})
+ -- This is ugly because :term/termopen() forces TERM=xterm-256color.
+ -- TODO: Revisit this after jobstart/termopen accept `env` dict.
+ screen = thelpers.screen_setup(0, string.format(
+ [=[['sh', '-c', 'LANG=C TERM=%s %s %s -u NONE -i NONE --cmd "silent set noswapfile"']]=],
+ term,
+ (colorterm ~= nil and "COLORTERM="..colorterm or ""),
+ helpers.nvim_prog))
+
+ thelpers.feed_data(":echo &t_Co\n")
+ local tline
+ if maxcolors == 8 then
+ tline = "~ "
+ else
+ tline = "{4:~ }"
+ end
+ screen:expect(string.format([[
+ {1: } |
+ %s|
+ %s|
+ %s|
+ {5:[No Name] }|
+ %-3s |
+ {3:-- TERMINAL --} |
+ ]], tline, tline, tline, tostring(maxcolors and maxcolors or "")))
+ end
+
+ it("unknown TERM sets empty 't_Co'", function()
+ assert_term_colors("yet-another-term", nil, nil)
+ end)
+
+ it("unknown TERM with COLORTERM=screen-256color uses 256 colors", function()
+ assert_term_colors("yet-another-term", "screen-256color", 256)
+ end)
+
+ it("TERM=linux uses 8 colors", function()
+ if is_linux then
+ assert_term_colors("linux", nil, 8)
+ else
+ pending()
+ end
+ end)
+
+ it("TERM=screen uses 8 colors", function()
+ if is_linux then
+ assert_term_colors("screen", nil, 8)
+ else
+ pending()
+ end
+ end)
+
+ it("TERM=screen COLORTERM=screen-256color uses 256 colors", function()
+ assert_term_colors("screen", "screen-256color", 256)
+ end)
+
+ it("TERM=yet-another-term COLORTERM=screen-256color uses 256 colors", function()
+ assert_term_colors("screen", "screen-256color", 256)
+ end)
+
+ it("TERM=xterm uses 256 colors", function()
+ assert_term_colors("xterm", nil, 256)
+ end)
+
+ it("TERM=xterm-256color uses 256 colors", function()
+ assert_term_colors("xterm-256color", nil, 256)
+ end)
+end)