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

Fix #19, add test case #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ class Builder {
clone._modifiers = this._modifiers
clone._lastMethodType = this._lastMethodType
clone._group = this._group
clone._captureNames = Array.from(this._captureNames)

return clone
}
Expand Down
28 changes: 28 additions & 0 deletions test/builder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,32 @@ 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')

})
it('Stores named captures with implodeString', () => {
const query = "begin with literally 'hello '\ncapture (anything once or more) as first";
const regex_new = new SRL(query);
const testcase = 'hello world';

let matches_new = regex_new.getMatch(testcase)
assert.equal(matches_new["first"], 'world')

const regex_cached = new SRL(query);

let matches_cached = regex_cached.getMatch(testcase)
assert.equal(matches_cached["first"], 'world')

})
})