Skip to content

Commit 213fa85

Browse files
committed
feat(tests): add tests for utils.current_file_path()
1 parent a4c0989 commit 213fa85

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

tests/plenary/utils_spec.lua

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
local utils = require('orgmode.utils')
2+
local helpers = require('tests.plenary.helpers')
23

3-
describe('Utils', function()
4-
it('should properly reduce', function()
4+
describe('Util', function()
5+
describe('reduce', function()
56
local nums = { 1, 2, 3 }
6-
local sum = utils.reduce(nums, function(acc, num)
7-
return acc + num
8-
end, 0)
9-
assert.are.same(6, sum)
107

11-
local multiplied = utils.reduce(nums, function(acc, num)
12-
table.insert(acc, num * 2)
13-
return acc
14-
end, {})
15-
assert.are.same({ 2, 4, 6 }, multiplied)
8+
it('works on sums', function()
9+
local sum = utils.reduce(nums, function(acc, num)
10+
return acc + num
11+
end, 0)
12+
assert.are.same(6, sum)
13+
end)
14+
15+
it('works on products', function()
16+
local multiplied = utils.reduce(nums, function(acc, num)
17+
table.insert(acc, num * 2)
18+
return acc
19+
end, {})
20+
assert.are.same({ 2, 4, 6 }, multiplied)
21+
end)
22+
end)
23+
24+
describe('current_file_path', function()
25+
it('returns the buffer name', function()
26+
local file = helpers.create_file({})
27+
assert.are.Not.same('', file.filename)
28+
assert.are.same(file.filename, utils.current_file_path())
29+
end)
30+
it('always returns the full path', function()
31+
local file = helpers.create_file({})
32+
local dirname = vim.fs.dirname(file.filename)
33+
helpers.with_cwd(dirname, function()
34+
local relpath = vim.fn.bufname()
35+
local abspath = utils.current_file_path()
36+
assert(vim.endswith(abspath, relpath))
37+
assert.are.Not.same(abspath, relpath)
38+
end)
39+
end)
1640
end)
1741
end)

0 commit comments

Comments
 (0)