Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opposite direction for length in before_regex() condition #441

Merged
merged 2 commits into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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