Update generated neovim config
This commit is contained in:
@ -8,7 +8,7 @@ describe("With default settings:", function()
|
||||
-- vim.fn.system("rm -rf " .. e(session_dir))
|
||||
end)
|
||||
|
||||
it("it saves a session", function()
|
||||
it("saves a session", function()
|
||||
-- Check no file exists
|
||||
assert.equals(vim.fn.system("ls tests/default_data | wc -l"):gsub("%s+", ""), "0")
|
||||
|
||||
@ -24,7 +24,7 @@ describe("With default settings:", function()
|
||||
assert.equals("1", vim.fn.system("ls tests/default_data | wc -l"):gsub("%s+", ""))
|
||||
end)
|
||||
|
||||
it("it loads a session", function()
|
||||
it("loads a session", function()
|
||||
-- Load a session
|
||||
require("persisted").load()
|
||||
|
||||
@ -35,19 +35,19 @@ describe("With default settings:", function()
|
||||
assert.equals(vim.g.persisting, true)
|
||||
end)
|
||||
|
||||
it("it stops a session", function()
|
||||
it("stops a session", function()
|
||||
require("persisted").stop()
|
||||
|
||||
assert.equals(vim.g.persisting, false)
|
||||
end)
|
||||
|
||||
it("it starts a session", function()
|
||||
it("starts a session", function()
|
||||
require("persisted").start()
|
||||
|
||||
assert.equals(vim.g.persisting, true)
|
||||
end)
|
||||
|
||||
it("it lists sessions", function()
|
||||
it("lists sessions", function()
|
||||
local sessions = require("persisted").list()
|
||||
local path = require("plenary.path"):new(sessions[1].file_path)
|
||||
|
||||
@ -59,19 +59,10 @@ local async = require("plenary.async.tests")
|
||||
local util = require("plenary.async.util")
|
||||
|
||||
async.describe("With default settings:", function()
|
||||
async.it("it deletes a session", function()
|
||||
async.it("deletes a session", function()
|
||||
require("persisted").delete()
|
||||
util.scheduler()
|
||||
|
||||
assert.equals("0", vim.fn.system("ls tests/default_data | wc -l"):gsub("%s+", ""))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("Utilities", function()
|
||||
it("can make derive the session name", function()
|
||||
local session = "%home%username%projects%front@@user%fix-analytics-export-null-values.vim"
|
||||
local data = require("persisted.utils").make_session_data(session)
|
||||
|
||||
assert.equals("home/username/projects/front@@user/fix-analytics-export-null-values", data.name)
|
||||
end)
|
||||
end)
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
local session_dir = vim.fn.getcwd() .. "/tests/default_data/"
|
||||
local utils = require("persisted.utils")
|
||||
|
||||
describe("Directory utilities:", function()
|
||||
it("can match directories", function()
|
||||
local cwd = "~/Code/Neovim/persisted.nvim"
|
||||
|
||||
local allowed_dirs = { "~/Code" }
|
||||
local match = utils.dirs_match(cwd, allowed_dirs)
|
||||
assert.equals(true, match)
|
||||
|
||||
allowed_dirs = { "~/.dotfiles" }
|
||||
match = utils.dirs_match(cwd, allowed_dirs)
|
||||
assert.equals(false, match)
|
||||
end)
|
||||
|
||||
it("can work with exact directories", function()
|
||||
local cwd = "~/Code/Neovim/persisted.nvim"
|
||||
local allowed_dirs = { { "~/Code", exact = true } }
|
||||
local match = utils.dirs_match(cwd, allowed_dirs)
|
||||
assert.equals(false, match)
|
||||
|
||||
cwd = "~/Code/Neovim/persisted.nvim"
|
||||
allowed_dirs = { { "~/Code/Neovim/persisted.nvim", exact = true } }
|
||||
match = utils.dirs_match(cwd, allowed_dirs)
|
||||
assert.equals(true, match)
|
||||
end)
|
||||
|
||||
it("can handle only ignore directories", function()
|
||||
local cwd = "~/Code/Neovim/persisted.nvim"
|
||||
local allowed_dirs = {}
|
||||
local ignored_dirs = { { "/tmp" } }
|
||||
local allowed_match = utils.dirs_match(cwd, allowed_dirs)
|
||||
local ignored_match = utils.dirs_match(cwd, ignored_dirs)
|
||||
-- This looks weird, I know. That is because we expect dirs_match to return
|
||||
-- false for allowed_dirs since allowed dirs is empty.
|
||||
-- Therefore this is actually testing to ensure we are getting false and false
|
||||
-- This test specifically addresses the change added in
|
||||
-- https://github.com/olimorris/persisted.nvim/pull/152
|
||||
assert.equals(true, not allowed_match and not ignored_match)
|
||||
end)
|
||||
end)
|
||||
@ -1,15 +1,13 @@
|
||||
pcall(vim.fn.system, "rm -rf tests/dummy_data")
|
||||
|
||||
local session_dir = vim.fn.getcwd() .. "/tests/dummy_data/"
|
||||
|
||||
-- follow_cwd = true
|
||||
pcall(vim.fn.system, "rm -rf tests/dummy_data")
|
||||
require("persisted").setup({
|
||||
save_dir = session_dir,
|
||||
follow_cwd = true,
|
||||
})
|
||||
|
||||
describe("Follow cwd change", function()
|
||||
it("creates two sessions with change in cwd", function()
|
||||
describe("Follow cwd", function()
|
||||
it("creates two sessions", function()
|
||||
vim.cmd(":e tests/stubs/test_autoload.txt")
|
||||
vim.cmd(":w")
|
||||
|
||||
@ -19,15 +17,15 @@ describe("Follow cwd change", function()
|
||||
require("persisted").save()
|
||||
vim.cmd(":bdelete")
|
||||
end)
|
||||
|
||||
it("ensures both sessions were created", function()
|
||||
require("persisted").load()
|
||||
|
||||
local pattern = "/"
|
||||
local branch1 = require("persisted").get_branch()
|
||||
local name1 = vim.fn.getcwd():gsub(pattern, "%%") .. (branch1 or "") .. ".vim"
|
||||
local name1 = vim.fn.getcwd():gsub(pattern, "%%") .. ".vim"
|
||||
|
||||
vim.cmd(":cd ../..")
|
||||
local branch2 = require("persisted").get_branch()
|
||||
local name2 = vim.fn.getcwd():gsub(pattern, "%%") .. (branch2 or "") .. ".vim"
|
||||
local name2 = vim.fn.getcwd():gsub(pattern, "%%") .. ".vim"
|
||||
|
||||
local sessions = vim.fn.readdir(session_dir)
|
||||
assert.equals(sessions[1], name1)
|
||||
@ -35,14 +33,13 @@ describe("Follow cwd change", function()
|
||||
end)
|
||||
end)
|
||||
|
||||
-- follow_cwd = false
|
||||
pcall(vim.fn.system, "rm -rf tests/dummy_data")
|
||||
require("persisted").setup({
|
||||
save_dir = session_dir,
|
||||
follow_cwd = false,
|
||||
})
|
||||
|
||||
describe("Don't follow cwd change", function()
|
||||
describe("Follow a cwd change", function()
|
||||
it("creates two sessions with change in cwd", function()
|
||||
vim.cmd(":e tests/stubs/test_autoload.txt")
|
||||
vim.cmd(":w")
|
||||
@ -56,11 +53,11 @@ describe("Don't follow cwd change", function()
|
||||
it("ensures only one session was created", function()
|
||||
local pattern = "/"
|
||||
vim.cmd(":cd ../..")
|
||||
local branch = require("persisted").get_branch()
|
||||
local name = vim.fn.getcwd():gsub(pattern, "%%") .. (branch or "") .. ".vim"
|
||||
|
||||
local name = vim.fn.getcwd():gsub(pattern, "%%") .. ".vim"
|
||||
|
||||
local sessions = vim.fn.readdir(session_dir)
|
||||
assert.equals(#sessions, 1)
|
||||
assert.equals(name, sessions[1])
|
||||
assert.equals(sessions[1], name)
|
||||
end)
|
||||
end)
|
||||
|
||||
@ -21,9 +21,24 @@ describe("Git Branching", function()
|
||||
end)
|
||||
|
||||
it("ensures the session has the branch name in", function()
|
||||
if vim.fn.isdirectory(session_dir .. "/.git") == 0 then
|
||||
vim.fn.system("mkdir -p " .. session_dir)
|
||||
vim.fn.system("cd " .. session_dir .. " && git init")
|
||||
end
|
||||
|
||||
local branch_name = require("persisted").branch()
|
||||
|
||||
-- Check if branch_name is valid
|
||||
if not branch_name then
|
||||
print("Failed to get branch name.")
|
||||
branch_name = ""
|
||||
else
|
||||
branch_name = "@@" .. branch_name
|
||||
end
|
||||
|
||||
-- Workout what the name should be
|
||||
local pattern = "/"
|
||||
local name = vim.fn.getcwd():gsub(pattern, "%%") .. require("persisted").get_branch() .. ".vim"
|
||||
local name = vim.fn.getcwd():gsub(pattern, "%%") .. branch_name .. ".vim"
|
||||
local session = vim.fn.glob(session_dir .. "*.vim", true, true)[1]
|
||||
|
||||
session:gsub(session_dir .. "/", "")
|
||||
|
||||
@ -7,4 +7,5 @@ command TestAutoloading PlenaryBustedDirectory tests/autoload {minimal_init = 't
|
||||
command TestGitBranching PlenaryBustedDirectory tests/git_branching {minimal_init = 'tests/minimal.vim'}
|
||||
command TestFollowCwd PlenaryBustedDirectory tests/follow_cwd {minimal_init = 'tests/minimal.vim'}
|
||||
command TestDefaults PlenaryBustedFile tests/default_settings_spec.lua
|
||||
command TestDirs PlenaryBustedFile tests/dirs_spec.lua
|
||||
command TearDown PlenaryBustedFile tests/teardown/clean_up_dirs.lua
|
||||
|
||||
Reference in New Issue
Block a user