|
1 | 1 | local utils = require('orgmode.utils')
|
| 2 | +local helpers = require('tests.plenary.helpers') |
2 | 3 |
|
3 |
| -describe('Utils', function() |
4 |
| - it('should properly reduce', function() |
| 4 | +describe('Util', function() |
| 5 | + describe('reduce', function() |
5 | 6 | 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) |
10 | 7 |
|
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) |
16 | 40 | end)
|
17 | 41 | end)
|
0 commit comments