test: TUI colors ('t_Co')

This commit is contained in:
Justin M. Keyes 2016-07-03 01:13:48 -04:00
parent c002310787
commit 173d366a5b
2 changed files with 61 additions and 5 deletions

View File

@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear, eval, eq = helpers.clear, helpers.eval, helpers.eq
local eval, eq = helpers.eval, helpers.eq
local execute = helpers.execute
local function init_session(...)
@ -15,10 +15,6 @@ local function init_session(...)
end
describe('startup defaults', function()
before_each(function()
clear()
end)
describe(':filetype', function()
local function expect_filetype(expected)
local screen = Screen.new(48, 4)

View File

@ -301,3 +301,63 @@ describe('tui focus event handling', function()
]])
end)
end)
-- These tests require `thelpers` because --headless/--embed
-- does not initialize the TUI.
describe("tui 't_Co' (terminal colors)", function()
local screen
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', '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")
screen:expect(string.format([[
{1: } |
~ |
~ |
~ |
[No Name] |
%-3s |
-- TERMINAL -- |
]], 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()
assert_term_colors("linux", nil, 8)
end)
it("TERM=screen uses 8 colors", function()
assert_term_colors("screen", nil, 8)
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)