Skip to content

Commit

Permalink
opposite direction for length in before_regex() condition (#441)
Browse files Browse the repository at this point in the history
* fix #440

* add test case
  • Loading branch information
name-snrl committed Mar 20, 2024
1 parent 797260f commit dbfc1c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/nvim-autopairs/conds.lua
Expand Up @@ -40,6 +40,7 @@ end
cond.before_regex = function(regex, length)
length = length or 1
if length < 0 then length = nil end
length = length and -length
---@param opts CondOpts
return function(opts)
log.debug('before_regex')
Expand Down Expand Up @@ -117,6 +118,7 @@ end
cond.not_before_regex = function(regex, length)
length = length or 1
if length < 0 then length = nil end
length = length and -length
---@param opts CondOpts
return function(opts)
log.debug('not_before_regex')
Expand Down
12 changes: 12 additions & 0 deletions tests/nvim-autopairs_spec.lua
Expand Up @@ -8,6 +8,7 @@ local utils = require('nvim-autopairs.utils')
_G.npairs = npairs;

-- use only = true to test 1 case
-- stylua: ignore
local data = {
{
-- only = true,
Expand Down Expand Up @@ -808,6 +809,17 @@ local data = {
before = [[('|') ]],
after = [[(''|) ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('123456', '789'):with_pair(cond.before_regex('^12345$', 5)),
})
end,
name = '87 test before_regex with a specific string length',
key = [[123456]],
before = [[ some text before| ]],
after = [[ some text before123456|789 ]],
},
}

local run_data = _G.Test_filter(data)
Expand Down

0 comments on commit dbfc1c3

Please sign in to comment.