--
-- Tests for default options and environment decisions.
--
-- See editor/defaults_spec.lua for default autocmds, mappings, commands, and menus.
--
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each, after_each, finally =
t.describe, t.it, t.before_each, t.after_each, t.finally
local assert_alive = n.assert_alive
local assert_log = t.assert_log
local pcall_err = t.pcall_err
local api = n.api
local command = n.command
local clear = n.clear
local eval = n.eval
local eq = t.eq
local ok = t.ok
local fn = n.fn
local insert = n.insert
local neq = t.neq
local mkdir = t.mkdir
local rmdir = n.rmdir
local tbl_contains = vim.tbl_contains
local expect_exit = n.expect_exit
local check_close = n.check_close
local is_os = t.is_os
local testlog = 'Xtest-defaults-log'
describe('startup defaults', function()
it("NVIM_NOTTYFAST=1 unsets 'ttyfast'", function()
clear { env = { NVIM_NOTTYFAST = '1' } }
eq(0, n.eval('&ttyfast'))
end)
describe(':filetype', function()
local function expect_filetype(expected)
local screen = Screen.new(50, 4)
command('filetype')
screen:expect([[
^ |
{1:~ }|*2
]] .. expected)
end
it('all ON after `-u NORC`', function()
clear('-u', 'NORC')
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
end)
it('all ON after `:syntax …` #7765', function()
clear('-u', 'NORC', '--cmd', 'syntax on')
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
clear('-u', 'NORC', '--cmd', 'syntax off')
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
end)
it('all OFF after `-u NONE`', function()
clear('-u', 'NONE')
expect_filetype('filetype detection:OFF plugin:OFF indent:OFF |')
end)
it('explicit OFF stays OFF', function()
clear('-u', 'NORC', '--cmd', 'syntax off | filetype off | filetype plugin indent off')
expect_filetype('filetype detection:OFF plugin:OFF indent:OFF |')
clear('-u', 'NORC', '--cmd', 'syntax off | filetype plugin indent off')
expect_filetype('filetype detection:ON plugin:OFF indent:OFF |')
clear('-u', 'NORC', '--cmd', 'filetype indent off')
expect_filetype('filetype detection:ON plugin:ON indent:OFF |')
clear('-u', 'NORC', '--cmd', 'syntax off | filetype off')
expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |')
-- Swap the order.
clear('-u', 'NORC', '--cmd', 'filetype off | syntax off')
expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |')
end)
it('all ON after early `:filetype … on`', function()
-- `:filetype … on` should not change the defaults. #7765
-- Only an explicit `:filetype … off` sets OFF.
clear('-u', 'NORC', '--cmd', 'filetype on')
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
clear('-u', 'NORC', '--cmd', 'filetype plugin on')
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
clear('-u', 'NORC', '--cmd', 'filetype indent on')
expect_filetype('filetype detection:ON plugin:ON indent:ON |')
end)
it('late `:filetype … off` stays OFF', function()
clear('-u', 'NORC', '-c', 'filetype off')
expect_filetype('filetype detection:OFF plugin:(on) indent:(on) |')
clear('-u', 'NORC', '-c', 'filetype plugin off')
expect_filetype('filetype detection:ON plugin:OFF indent:ON |')
clear('-u', 'NORC', '-c', 'filetype indent off')
expect_filetype('filetype detection:ON plugin:ON indent:OFF |')
end)
end)
describe('syntax', function()
it('enabled by `-u NORC`', function()
clear('-u', 'NORC')
eq(1, eval('g:syntax_on'))
end)
it('disabled by `-u NONE`', function()
clear('-u', 'NONE')
eq(0, eval('exists("g:syntax_on")'))
end)
it('`:syntax off` stays off', function()
-- early
clear('-u', 'NORC', '--cmd', 'syntax off')
eq(0, eval('exists("g:syntax_on")'))
-- late
clear('-u', 'NORC', '-c', 'syntax off')
eq(0, eval('exists("g:syntax_on")'))
end)
it('":if 0|syntax on|endif" does not affect default #8728', function()
clear('-u', 'NORC', '--cmd', ':if 0|syntax on|endif')
eq(1, eval('exists("g:syntax_on")'))
clear('-u', 'NORC', '--cmd', ':if 0|syntax off|endif')
eq(1, eval('exists("g:syntax_on")'))
end)
end)
describe("'fillchars'", function()
it('vert/fold flags', function()
clear()
local screen = Screen.new(50, 5)
command('set laststatus=0')
|