Skip to content

Commit

Permalink
Fix SimpleRegex#19, add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaiunrein committed May 17, 2021
1 parent 79a8fd1 commit a313f8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions test/builder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

})
})

0 comments on commit a313f8e

Please sign in to comment.