|
8 | 8 | -- luacheck: ignore 311 |
9 | 9 |
|
10 | 10 | local vim9 = require('_vim9script') |
| 11 | +local M = {} |
11 | 12 | describe('filename', function() |
12 | 13 | -- vim9script |
13 | 14 |
|
@@ -79,4 +80,52 @@ describe('filename', function() |
79 | 80 | -- Assert that errors is still empty |
80 | 81 | assert.are.same({}, vim.v.errors) |
81 | 82 | end) |
| 83 | + |
| 84 | + it('Test_can_do_funcref', function() |
| 85 | + -- Set errors to empty |
| 86 | + vim.v.errors = {} |
| 87 | + |
| 88 | + -- Actual test |
| 89 | + |
| 90 | + local MyDoubler = function(x) |
| 91 | + return vim9.ops.Multiply(x, 2) |
| 92 | + end |
| 93 | + |
| 94 | + local Doubler = function(...) |
| 95 | + return vim9.fn_ref(M, MyDoubler, vim.deepcopy({ 1 }), ...) |
| 96 | + end |
| 97 | + |
| 98 | + vim9.fn.assert_equal(Doubler(), 2) |
| 99 | + |
| 100 | + -- Assert that errors is still empty |
| 101 | + assert.are.same({}, vim.v.errors) |
| 102 | + end) |
| 103 | + |
| 104 | + it('Test_can_do_str_for_vimfuncs', function() |
| 105 | + -- Set errors to empty |
| 106 | + vim.v.errors = {} |
| 107 | + |
| 108 | + -- Actual test |
| 109 | + local Lengther = function(...) |
| 110 | + return vim9.fn_ref(M, 'len', vim.deepcopy({ 'foo' }), ...) |
| 111 | + end |
| 112 | + |
| 113 | + vim9.fn.assert_equal(Lengther(), 3) |
| 114 | + |
| 115 | + -- Assert that errors is still empty |
| 116 | + assert.are.same({}, vim.v.errors) |
| 117 | + end) |
| 118 | + |
| 119 | + -- # Can't do this yet |
| 120 | + -- # def Test_can_do_forward_funcref() |
| 121 | + -- # var something = 'MyDoubler' |
| 122 | + -- # var StrDoubler = function(something, [1]) |
| 123 | + -- # |
| 124 | + -- # def MyDoubler(x: number): number |
| 125 | + -- # return x *2 |
| 126 | + -- # enddef |
| 127 | + -- # |
| 128 | + -- # assert_equal(StrDoubler(), 2) |
| 129 | + -- # enddef |
82 | 130 | end) |
| 131 | +return M |
0 commit comments