From a313f8ee03a96301a18d9ac7a10e23770eb0206f Mon Sep 17 00:00:00 2001 From: Nicolai Unrein Date: Mon, 17 May 2021 17:14:50 +0200 Subject: [PATCH] Fix #19, add test case --- lib/Builder.js | 2 ++ test/builder-test.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Builder.js b/lib/Builder.js index 96398ad..495c95d 100644 --- a/lib/Builder.js +++ b/lib/Builder.js @@ -704,6 +704,8 @@ class Builder { clone._modifiers = this._modifiers clone._lastMethodType = this._lastMethodType clone._group = this._group + clone._captureNames = Array.from(this._captureNames) + clone._implodeString = this.implodeString return clone } diff --git a/test/builder-test.js b/test/builder-test.js index dbfb3ed..9da9c5d 100644 --- a/test/builder-test.js +++ b/test/builder-test.js @@ -178,4 +178,18 @@ describe('Builder isMatching', () => { assert.deepEqual(regex, /(?:foo)/) }) + + it('Stores named captures', () => { + const regex_new = new SRL("capture (anything once or more) as first"); + const testcase = 'hello world'; + + let matches_new = regex_new.getMatch(testcase) + assert.equal(matches_new["first"], 'hello world') + + const regex_cached = new SRL("capture (anything once or more) as first"); + + let matches_cached = regex_cached.getMatch(testcase) + assert.equal(matches_cached["first"], 'hello world') + + }) })