Skip to content

Commit eb2f057

Browse files
authored
Fix #11, add test cases relative to #11, release 0.2.2 (#16)
1 parent 93e1c74 commit eb2f057

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

lib/Language/Helpers/buildQuery.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ function buildQuery(query, builder = new Builder()) {
4242
// Now, append that method to the builder object.
4343
method.setParameters(parameters).callMethodOn(builder)
4444
} catch (e) {
45-
if (Array.isArray(parameters[0])) {
45+
const lastIndex = parameters.length - 1
46+
if (Array.isArray(parameters[lastIndex])) {
47+
if (lastIndex !== 0) {
48+
method.setParameters(parameters.slice(0, lastIndex))
49+
}
4650
method.callMethodOn(builder)
47-
builder.and(buildQuery(parameters[0], new NonCapture()))
51+
builder.and(buildQuery(parameters[lastIndex], new NonCapture()))
4852
} else {
4953
throw new SyntaxException(`Invalid parameter given for ${method.origin}`)
5054
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "srl",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Simple Regex Language",
55
"main": "lib/SRL.js",
66
"scripts": {

test/issue-11-test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const assert = require('assert')
4+
const SRL = require('../')
5+
6+
describe('Fix issue 11', () => {
7+
it('Numerical quantifies & non-capturing group', () => {
8+
const query = new SRL('digit, exactly 5 times, (letter, twice) optional')
9+
assert.ok(query.isMatching('12345'))
10+
assert.ok(query.isMatching('12345aa'))
11+
})
12+
13+
it('Complicated case', () => {
14+
const query = new SRL('begin with, digit, exactly 5 times, ( literally \'-\', digit, exactly 4 times ), optional, must end')
15+
assert.ok(query.isMatching('12345-1234'))
16+
})
17+
})
18+
19+

test/parseParentheses-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe('ParseParentheses Test', () => {
1818
assert.deepEqual(parseParentheses('foo (0)'), [ 'foo', [ '0' ] ])
1919

2020
assert.deepEqual(
21-
parseParentheses('foo (bar (nested)) baz'),
22-
[ 'foo', [ 'bar', [ 'nested' ] ], 'baz' ]
21+
parseParentheses('foo (bar (nested)) baz'),
22+
[ 'foo', [ 'bar', [ 'nested' ] ], 'baz' ]
2323
)
2424

2525
assert.deepEqual(

0 commit comments

Comments
 (0)