ui: refactor ui options

This commit is contained in:
Björn Linse
2018-02-13 13:45:49 +01:00
parent 0f1bc5ddce
commit 6e5cb0debd
11 changed files with 109 additions and 45 deletions

View File

@@ -1,6 +1,7 @@
local helpers = require('test.functional.helpers')(after_each)
local mpack = require('mpack')
local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq
local call = helpers.call
local function read_mpack_file(fname)
local fd = io.open(fname, 'rb')
@@ -18,7 +19,7 @@ describe("api_info()['version']", function()
before_each(clear)
it("returns API level", function()
local version = helpers.call('api_info')['version']
local version = call('api_info')['version']
local current = version['api_level']
local compat = version['api_compatible']
eq("number", type(current))
@@ -27,7 +28,7 @@ describe("api_info()['version']", function()
end)
it("returns Nvim version", function()
local version = helpers.call('api_info')['version']
local version = call('api_info')['version']
local major = version['major']
local minor = version['minor']
local patch = version['patch']
@@ -147,3 +148,14 @@ describe("api functions", function()
end)
end)
describe("ui_options in metadata", function()
it('are correct', function()
-- TODO(bfredl) once a release freezes this into metadata,
-- instead check that all old options are present
local api = helpers.call('api_info')
local options = api.ui_options
eq({'rgb', 'ext_cmdline', 'ext_popupmenu',
'ext_tabline', 'ext_wildmenu'}, options)
end)
end)

View File

@@ -106,7 +106,8 @@ describe('api functions', function()
it('have metadata accessible with api_info()', function()
local api_keys = eval("sort(keys(api_info()))")
eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_keys)
eq({'error_types', 'functions', 'types',
'ui_events', 'ui_options', 'version'}, api_keys)
end)
it('are highlighted by vim.vim syntax file', function()

View File

@@ -463,7 +463,8 @@ describe('msgpackparse() function', function()
eval(cmd)
eval(cmd) -- do it again (try to force segfault)
local api_info = eval(cmd) -- do it again
eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_info)
eq({'error_types', 'functions', 'types',
'ui_events', 'ui_options', 'version'}, api_info)
end)
it('fails when called with no arguments', function()

View File

@@ -10,7 +10,6 @@ describe('ui receives option updates', function()
before_each(function()
clear()
screen = Screen.new(20,5)
screen:attach()
end)
after_each(function()
@@ -27,15 +26,21 @@ describe('ui receives option updates', function()
linespace=0,
showtabline=1,
termguicolors=false,
ext_cmdline=false,
ext_popupmenu=false,
ext_tabline=false,
ext_wildmenu=false,
}
it("for defaults", function()
screen:attach()
screen:expect(function()
eq(defaults, screen.options)
end)
end)
it("when setting options", function()
screen:attach()
local changed = {}
for k,v in pairs(defaults) do
changed[k] = v
@@ -76,4 +81,30 @@ describe('ui receives option updates', function()
eq(defaults, screen.options)
end)
end)
it('with UI extensions', function()
local changed = {}
for k,v in pairs(defaults) do
changed[k] = v
end
screen:attach({ext_cmdline=true, ext_wildmenu=true})
changed.ext_cmdline = true
changed.ext_wildmenu = true
screen:expect(function()
eq(changed, screen.options)
end)
screen:set_option('ext_popupmenu', true)
changed.ext_popupmenu = true
screen:expect(function()
eq(changed, screen.options)
end)
screen:set_option('ext_wildmenu', false)
changed.ext_wildmenu = false
screen:expect(function()
eq(changed, screen.options)
end)
end)
end)