--
-- 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 assert_alive = n.assert_alive
local assert_log = t.assert_log
local api = n.api
local command = n.command
local clear = n.clear
local exc_exec = n.exc_exec
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()
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")'))
|