From 5e7e75ecc9660988f26489b390ff685dd68de364 Mon Sep 17 00:00:00 2001 From: name_snrl Date: Sun, 10 Mar 2024 16:51:08 +0500 Subject: [PATCH 1/2] fix #440 --- lua/nvim-autopairs/conds.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/nvim-autopairs/conds.lua b/lua/nvim-autopairs/conds.lua index dc10eeb1..a07518e0 100644 --- a/lua/nvim-autopairs/conds.lua +++ b/lua/nvim-autopairs/conds.lua @@ -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') @@ -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') From 07054388af616843c6232f6f742777a1231a268f Mon Sep 17 00:00:00 2001 From: name_snrl Date: Fri, 15 Mar 2024 14:59:43 +0500 Subject: [PATCH 2/2] add test case --- tests/nvim-autopairs_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/nvim-autopairs_spec.lua b/tests/nvim-autopairs_spec.lua index ac2bbe98..ff25a1d3 100644 --- a/tests/nvim-autopairs_spec.lua +++ b/tests/nvim-autopairs_spec.lua @@ -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, @@ -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)