telescope-frecency.nvim/lua/frecency/tests/database_spec.lua
JINNOUCHI Yasushi ada91ca486
feat!: remove code for SQLite (#172)
* feat!: remove code for SQLite

ref [Introduce revised telescope-frecency.nvim : neovim](https://www.reddit.com/r/neovim/comments/174m8zu/introduce_revised_telescopefrecencynvim/)

I have deprecated SQLite features 4 months ago. It is the time to remove
code for them.

* test: fix test to load telescope validly

* test: remove sqlite.lua from CI settings

* test: test database as native

* fix: add lacked type from old database/sqlite.lua

* docs: remove description for SQLite3 logic

* chore: fix types

* chore: add types for Database:raw_table
2024-01-30 18:26:07 +09:00

47 lines
1.4 KiB
Lua

local FS = require "frecency.fs"
local Database = require "frecency.database"
local async = require "plenary.async" --[[@as PlenaryAsync]]
local util = require "frecency.tests.util"
async.tests.add_to_env()
local function with_database(f)
local fs = FS.new { ignore_patterns = {} }
local dir, close = util.tmpdir()
dir:joinpath("file_frecency.bin"):touch()
return function()
local database = Database.new(fs, { root = dir.filename })
f(database)
close()
end
end
local function save_and_load(database, tbl, datetime)
database:raw_save(util.v1_table(tbl))
async.util.sleep(100)
local entries = database:get_entries(nil, datetime)
table.sort(entries, function(a, b)
return a.path < b.path
end)
return entries
end
a.describe("frecency.database", function()
a.describe("updated by another process", function()
a.it(
"returns valid entries",
with_database(function(database)
assert.are.same(
{
{ path = "hoge1.txt", count = 1, ages = { 60 } },
{ path = "hoge2.txt", count = 1, ages = { 60 } },
},
save_and_load(database, {
["hoge1.txt"] = { count = 1, timestamps = { "2023-08-21T00:00:00+0000" } },
["hoge2.txt"] = { count = 1, timestamps = { "2023-08-21T00:00:00+0000" } },
}, "2023-08-21T01:00:00+0000")
)
end)
)
end)
end)