From bfb9b6119470bc43ca10744a039b295c7520a560 Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Sun, 5 Oct 2025 20:23:47 -0400 Subject: [PATCH] Untested POC --- README.md | 23 ++++++++++++++ minimal_init.lua | 31 ++++++++++++++++++ run_tests.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ test_runner.lua | 60 +++++++++++++++++++++++++++++++++++ test_runner.sh | 59 +++++++++++++++++++++++++++++++++++ 5 files changed, 254 insertions(+) create mode 100644 minimal_init.lua create mode 100644 run_tests.lua create mode 100755 test_runner.lua create mode 100755 test_runner.sh diff --git a/README.md b/README.md index 6b072a8..2464e3e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,29 @@ A relational document system for Neovim that brings Notion-like database capabil ### Installation +Using [lazy.nvim](https://github.com/folke/lazy.nvim) (recommended): + +```lua +{ + 'your-username/notex.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons' + }, + config = function() + require('notex').setup({ + -- Configuration options + database_path = vim.fn.stdpath('data') .. '/notex/notex.db', + auto_index = true, + performance = { + enable_caching = true, + cache_size = 100 + } + }) + end +} +``` + Using [packer.nvim](https://github.com/wbthomason/packer.nvim): ```lua diff --git a/minimal_init.lua b/minimal_init.lua new file mode 100644 index 0000000..0c714ca --- /dev/null +++ b/minimal_init.lua @@ -0,0 +1,31 @@ +-- Minimal Neovim config for testing +vim.opt.runtimepath:prepend('.') + +-- Mock vim functions that tests need +vim.loop = vim.loop or {} +vim.loop.fs_stat = vim.loop.fs_stat or function(path) + return {type = "file", size = 100} +end +vim.loop.timer_start = vim.loop.timer_start or function(delay, callback) + return 1 +end +vim.loop.timer_stop = vim.loop.timer_stop or function(timer_id) + -- Mock timer stop +end + +vim.uv = vim.uv or {} +vim.uv.new_timer = vim.uv.new_timer or function() + return { + start = function() end, + stop = function() end, + close = function() end + } +end +vim.uv.hrtime = vim.uv.hrtime or function() + return os.clock() * 1e9 +end + +vim.schedule = vim.schedule or function(fn) fn() end +vim.defer_fn = vim.defer_fn or function(fn, delay) fn() end + +print("Minimal Neovim config loaded") \ No newline at end of file diff --git a/run_tests.lua b/run_tests.lua new file mode 100644 index 0000000..e95ddf3 --- /dev/null +++ b/run_tests.lua @@ -0,0 +1,81 @@ +-- Set up Lua path +package.path = "./lua/?.lua;./lua/?/init.lua;" .. package.path + +-- Extend existing vim global +if not _G.vim then _G.vim = {} end + +local vim = _G.vim + +-- Mock missing vim functions if they don't exist +vim.fn = vim.fn or {} +vim.fn.stdpath = vim.fn.stdpath or function(type) + return "/tmp/notex_test" +end +vim.fn.getpid = vim.fn.getpid or function() + return 12345 +end + +vim.loop = vim.loop or {} +vim.loop.fs_stat = vim.loop.fs_stat or function(path) + return {type = "file", size = 100} +end +vim.loop.timer_start = vim.loop.timer_start or function(delay, callback) + return 1 +end +vim.loop.timer_stop = vim.loop.timer_stop or function(timer_id) + -- Mock timer stop +end + +vim.uv = vim.uv or {} +vim.uv.new_timer = vim.uv.new_timer or function() + return { + start = function() end, + stop = function() end, + close = function() end + } +end +vim.uv.hrtime = vim.uv.hrtime or function() + return os.clock() * 1e9 +end + +vim.trim = vim.trim or function(str) + return str:match("^%s*(.-)%s*$") +end + +vim.split = vim.split or function(str, sep) + local fields = {} + local pattern = string.format("([^%s]+)", sep) + str:gsub(pattern, function(c) fields[#fields + 1] = c end) + return fields +end + +vim.tbl_contains = vim.tbl_contains or function(t, val) + for _, v in ipairs(t) do + if v == val then return true end + end + return false +end + +-- Add missing API functions +vim.api = vim.api or {} +vim.api.nvim_buf_get_lines = vim.api.nvim_buf_get_lines or function() return {} end +vim.api.nvim_buf_set_lines = vim.api.nvim_buf_set_lines or function() end +vim.api.nvim_create_buf = vim.api.nvim_create_buf or function() return 1 end + +vim.g = vim.g or {} +vim.b = vim.b or {} +vim.o = vim.o or {} +vim.bo = vim.bo or {} +vim.wo = vim.wo or {} + +-- Mock scheduler +vim.schedule = vim.schedule or function(fn) fn() end +vim.defer_fn = vim.defer_fn or function(fn, delay) fn() end + +-- Run busted with command line args +local busted = require('busted') +local args = arg or {} +if #args == 0 then + args = {'tests/', '--verbose'} +end +busted.run(args) \ No newline at end of file diff --git a/test_runner.lua b/test_runner.lua new file mode 100755 index 0000000..a9a5665 --- /dev/null +++ b/test_runner.lua @@ -0,0 +1,60 @@ +#!/bin/bash +exec nvim --headless "$0" "$@" + +-- Set up Lua path +package.path = "./lua/?.lua;./lua/?/init.lua;" .. package.path + +-- Mock minimal vim global for testing +_G.vim = { + fn = { + stdpath = function(type) + return "/tmp/notex_test" + end, + getpid = function() + return 12345 + end, + }, + loop = { + fs_stat = function(path) + -- Mock file stat + return {type = "file", size = 100} + end, + timer_start = function(delay, callback) + return 1 -- mock timer id + end, + timer_stop = function(timer_id) + -- Mock timer stop + end, + }, + uv = { + new_timer = function() + return { + start = function() end, + stop = function() end, + close = function() end + } + end, + hrtime = function() + return os.clock() * 1e9 + end, + }, + trim = function(str) + return str:match("^%s*(.-)%s*$") + end, + split = function(str, sep) + local fields = {} + local pattern = string.format("([^%s]+)", sep) + str:gsub(pattern, function(c) fields[#fields + 1] = c end) + return fields + end, + tbl_contains = function(t, val) + for _, v in ipairs(t) do + if v == val then return true end + end + return false + end, +} + +-- Run busted with command line args +local busted = require('busted') +busted.run(arg) \ No newline at end of file diff --git a/test_runner.sh b/test_runner.sh new file mode 100755 index 0000000..133ae91 --- /dev/null +++ b/test_runner.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Run tests with Neovim context +LUA_PATH="./lua/?.lua;./lua/?/init.lua;$LUA_PATH" nvim --headless -c " + -- Mock minimal vim global for testing + _G.vim = { + fn = { + stdpath = function(type) + return '/tmp/notex_test' + end, + getpid = function() + return 12345 + end, + }, + loop = { + fs_stat = function(path) + return {type = 'file', size = 100} + end, + timer_start = function(delay, callback) + return 1 + end, + timer_stop = function(timer_id) + -- Mock timer stop + end, + }, + uv = { + new_timer = function() + return { + start = function() end, + stop = function() end, + close = function() end + } + end, + hrtime = function() + return os.clock() * 1e9 + end, + }, + trim = function(str) + return str:match('^%s*(.-)%s*$') + end, + split = function(str, sep) + local fields = {} + local pattern = string.format('([^%s]+)', sep) + str:gsub(pattern, function(c) fields[#fields + 1] = c end) + return fields + end, + tbl_contains = function(t, val) + for _, v in ipairs(t) do + if v == val then return true end + end + return false + end, + } + + -- Run busted + local busted = require('busted') + local args = {'$@'} + busted.run(args) +" -c "qa" \ No newline at end of file