Skip to content

Commit 81150de

Browse files
committed
β0.1.2 Improve test suites and add tests
Fix bugs in Path and achieve parity with craywall.nvim Improve Section:__tostring() Implement utils.run_command() Improve formatting in some error messages Add Github workflow
1 parent f7fe75e commit 81150de

File tree

12 files changed

+502
-243
lines changed

12 files changed

+502
-243
lines changed

.github/workflows/tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Install Lua
18+
run: sudo apt-get update && sudo apt-get install -y lua5.4
19+
20+
- name: Run tests
21+
run: lua ./tests/tests.lua

core/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Config.errors = {
7979
missing_item_in_note_schema_list = function(list, idx)
8080
return "Missing "
8181
.. (#list <= 1 and "open-tag" or "close-tag")
82-
.. "in config.note_schema["
82+
.. " in config.note_schema["
8383
.. idx
8484
.. "]."
8585
end,

core/mock_filesystem/mock_filesystem.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ function MockFilesystem:__tostring()
5353
return out
5454
end
5555

56+
---@param rhs MockFilesystem
57+
---@return boolean
58+
function MockFilesystem:__eq(rhs)
59+
return tostring(self) == tostring(rhs)
60+
end
61+
5662
return MockFilesystem

core/path.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ function Path:new(path, allow_relative)
7070
for part in string.gmatch(path, "[^/]+") do
7171
table.insert(self.parts, part)
7272
end
73+
if path:sub(#path, #path) == "/" then
74+
table.insert(self.parts, "")
75+
end
7376
if #self.parts == 1 and self.parts[1] == nil then
7477
self.parts = {}
7578
end

core/section.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Section.ROOT = "ROOT"
5252
---@param context Context
5353
---@param start_line number
5454
---@param end_line number?
55-
---@param children Section[]
55+
---@param children Section[]?
5656
---@param parent Section?
5757
---@param indent string?
5858
---@return Section? section
@@ -89,7 +89,7 @@ function Section:new(
8989
self.context = utils.read_only(context)
9090
self.start_line = start_line
9191
self.end_line = end_line
92-
self.children = children
92+
self.children = children or {}
9393
self.parent = parent
9494
self.indent = indent or ""
9595
return self
@@ -208,7 +208,9 @@ end
208208

209209
---@return string
210210
function Section:__tostring()
211-
return "Section {"
211+
return "Section {\n"
212+
.. 'id = '
213+
.. self.id
212214
.. '\n\ttype = {"'
213215
.. self.type[1]
214216
.. '", "'

core/utils.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ M.str = {
1313
---@param suffix string
1414
---@return boolean
1515
ends_with = function(str, suffix)
16-
return string.sub(str, -string.len(suffix)) == suffix
16+
return suffix == "" or string.sub(str, -#suffix) == suffix
1717
end,
1818

1919
---@param str string
@@ -97,6 +97,12 @@ M.read_from_handle = function(handle)
9797
return res
9898
end
9999

100+
---@param cmd string
101+
---@return string?
102+
M.run_command = function(cmd)
103+
return M.read_from_handle(io.popen(cmd))
104+
end
105+
100106
---@return string
101107
M.get_home_directory = function()
102108
return assert(M.read_from_handle(io.popen("echo $HOME")) .. "/")

core/version.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
return "β0.1.1"
1+
return "β0.1.2"

0 commit comments

Comments
 (0)