cucumber-expressions
Advanced tools
Comparing version 4.0.3 to 4.0.4
@@ -107,3 +107,3 @@ 'use strict'; | ||
expressionTemplate += text.slice(pos, bestParameterTypeMatcher.start); | ||
expressionTemplate += escapeForUtilFormat(text.slice(pos, bestParameterTypeMatcher.start)); | ||
expressionTemplate += '{%s}'; | ||
@@ -122,3 +122,3 @@ | ||
expressionTemplate += text.slice(pos); | ||
expressionTemplate += escapeForUtilFormat(text.slice(pos)); | ||
return new CombinatorialGeneratedExpressionFactory(expressionTemplate, parameterTypeCombinations).generateExpressions(); | ||
@@ -210,2 +210,6 @@ } | ||
function escapeForUtilFormat(s) { | ||
return s.replace(/%/g, '%%'); | ||
} | ||
module.exports = CucumberExpressionGenerator; |
@@ -48,2 +48,7 @@ 'use strict'; | ||
} | ||
}, { | ||
key: 'children', | ||
get: function get() { | ||
return this._groupBuilders; | ||
} | ||
}]); | ||
@@ -50,0 +55,0 @@ |
@@ -23,19 +23,12 @@ 'use strict'; | ||
value: function match(text) { | ||
var parameterTypes = []; | ||
var _this = this; | ||
var CAPTURE_GROUP_PATTERN = /\((?!\?:)([^(]+)\)/g; | ||
var parameterTypes = this._treeRegexp.groupBuilder.children.map(function (groupBuilder) { | ||
var parameterTypeRegexp = groupBuilder.source; | ||
var match = void 0; | ||
while ((match = CAPTURE_GROUP_PATTERN.exec(this._treeRegexp.regexp.source)) !== null) { | ||
var parameterTypeRegexp = match[1]; | ||
return _this._parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, _this._treeRegexp, text) || new ParameterType(parameterTypeRegexp, parameterTypeRegexp, String, function (s) { | ||
return s; | ||
}, false, false); | ||
}); | ||
var parameterType = this._parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, this._treeRegexp, text); | ||
if (!parameterType) { | ||
parameterType = new ParameterType(parameterTypeRegexp, parameterTypeRegexp, String, function (s) { | ||
return s; | ||
}, false, false); | ||
} | ||
parameterTypes.push(parameterType); | ||
} | ||
return Argument.build(this._treeRegexp, text, parameterTypes); | ||
@@ -42,0 +35,0 @@ } |
@@ -12,2 +12,4 @@ 'use strict'; | ||
function TreeRegexp(regexp) { | ||
var _this = this; | ||
_classCallCheck(this, TreeRegexp); | ||
@@ -19,11 +21,16 @@ | ||
var stack = [new GroupBuilder()]; | ||
var groupStartStack = []; | ||
var last = null; | ||
var nonCapturingMaybe = false; | ||
this._re.source.split('').forEach(function (c) { | ||
this._re.source.split('').forEach(function (c, n) { | ||
if (c === '(' && last !== '\\') { | ||
stack.push(new GroupBuilder()); | ||
groupStartStack.push(n + 1); | ||
nonCapturingMaybe = false; | ||
} else if (c === ')' && last !== '\\') { | ||
var gb = stack.pop(); | ||
var groupStart = groupStartStack.pop(); | ||
if (gb.capturing) { | ||
gb.source = _this._re.source.substring(groupStart, n); | ||
stack[stack.length - 1].add(gb); | ||
@@ -61,2 +68,7 @@ } else { | ||
} | ||
}, { | ||
key: 'groupBuilder', | ||
get: function get() { | ||
return this._groupBuilder; | ||
} | ||
}]); | ||
@@ -63,0 +75,0 @@ |
{ | ||
"name": "cucumber-expressions", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "Cucumber Expressions - a simpler alternative to Regular Expressions", | ||
@@ -13,3 +13,3 @@ "main": "dist/index.js", | ||
"mocha": "mocha", | ||
"coverage": "node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- test", | ||
"coverage": "nyc --reporter=html --reporter=text mocha", | ||
"precommit": "lint-staged" | ||
@@ -40,7 +40,5 @@ }, | ||
"eslint-plugin-prettier": "^2.0.1", | ||
"husky": "^0.13.3", | ||
"istanbul": "1.0.0-alpha.2", | ||
"lint-staged": "^3.4.1", | ||
"mocha": "^3.2.0", | ||
"prettier": "^1.3.1" | ||
"mocha": "^4.0.0", | ||
"nyc": "^11.2.1", | ||
"prettier": "^1.7.4" | ||
}, | ||
@@ -47,0 +45,0 @@ "files": [ |
@@ -57,3 +57,5 @@ const util = require('util') | ||
expressionTemplate += text.slice(pos, bestParameterTypeMatcher.start) | ||
expressionTemplate += escapeForUtilFormat( | ||
text.slice(pos, bestParameterTypeMatcher.start) | ||
) | ||
expressionTemplate += '{%s}' | ||
@@ -72,3 +74,3 @@ | ||
expressionTemplate += text.slice(pos) | ||
expressionTemplate += escapeForUtilFormat(text.slice(pos)) | ||
return new CombinatorialGeneratedExpressionFactory( | ||
@@ -112,2 +114,6 @@ expressionTemplate, | ||
function escapeForUtilFormat(s) { | ||
return s.replace(/%/g, '%%') | ||
} | ||
module.exports = CucumberExpressionGenerator |
@@ -34,2 +34,6 @@ const Group = require('./group') | ||
get children() { | ||
return this._groupBuilders | ||
} | ||
moveChildrenTo(groupBuilder) { | ||
@@ -36,0 +40,0 @@ this._groupBuilders.forEach(child => groupBuilder.add(child)) |
@@ -13,30 +13,23 @@ const Argument = require('./argument') | ||
match(text) { | ||
const parameterTypes = [] | ||
const parameterTypes = this._treeRegexp.groupBuilder.children.map( | ||
groupBuilder => { | ||
const parameterTypeRegexp = groupBuilder.source | ||
const CAPTURE_GROUP_PATTERN = /\((?!\?:)([^(]+)\)/g | ||
let match | ||
while ( | ||
(match = CAPTURE_GROUP_PATTERN.exec(this._treeRegexp.regexp.source)) !== | ||
null | ||
) { | ||
const parameterTypeRegexp = match[1] | ||
let parameterType = this._parameterTypeRegistry.lookupByRegexp( | ||
parameterTypeRegexp, | ||
this._treeRegexp, | ||
text | ||
) | ||
if (!parameterType) { | ||
parameterType = new ParameterType( | ||
parameterTypeRegexp, | ||
parameterTypeRegexp, | ||
String, | ||
s => s, | ||
false, | ||
false | ||
return ( | ||
this._parameterTypeRegistry.lookupByRegexp( | ||
parameterTypeRegexp, | ||
this._treeRegexp, | ||
text | ||
) || | ||
new ParameterType( | ||
parameterTypeRegexp, | ||
parameterTypeRegexp, | ||
String, | ||
s => s, | ||
false, | ||
false | ||
) | ||
) | ||
} | ||
parameterTypes.push(parameterType) | ||
} | ||
) | ||
@@ -43,0 +36,0 @@ return Argument.build(this._treeRegexp, text, parameterTypes) |
@@ -10,11 +10,16 @@ const Regex = require('becke-ch--regex--s0-0-v1--base--pl--lib') | ||
const stack = [new GroupBuilder()] | ||
const groupStartStack = [] | ||
let last = null | ||
let nonCapturingMaybe = false | ||
this._re.source.split('').forEach(c => { | ||
this._re.source.split('').forEach((c, n) => { | ||
if (c === '(' && last !== '\\') { | ||
stack.push(new GroupBuilder()) | ||
groupStartStack.push(n + 1) | ||
nonCapturingMaybe = false | ||
} else if (c === ')' && last !== '\\') { | ||
const gb = stack.pop() | ||
const groupStart = groupStartStack.pop() | ||
if (gb.capturing) { | ||
gb.source = this._re.source.substring(groupStart, n) | ||
stack[stack.length - 1].add(gb) | ||
@@ -40,2 +45,6 @@ } else { | ||
get groupBuilder() { | ||
return this._groupBuilder | ||
} | ||
match(s) { | ||
@@ -42,0 +51,0 @@ const match = this._regex.exec(s) |
@@ -53,2 +53,6 @@ /* eslint-env mocha */ | ||
it('generates expression for strings', () => { | ||
assertExpression('I am {int}%% foobar', ['int'], 'I am 20%% foobar') | ||
}) | ||
it('generates expression for strings with % sign', () => { | ||
assertExpression( | ||
@@ -55,0 +59,0 @@ 'I like {string} and {string}', |
@@ -30,14 +30,16 @@ /* eslint-env mocha */ | ||
parameterTypeRegistry = new ParameterTypeRegistry() | ||
/* eslint-disable prettier/prettier */ | ||
/// [add-color-parameter-type] | ||
parameterTypeRegistry.defineParameterType( | ||
new ParameterType( | ||
'color', | ||
/red|blue|yellow/, | ||
Color, | ||
s => new Color(s), | ||
false, | ||
true | ||
'color', // name | ||
/red|blue|yellow/, // regexp | ||
Color, // type | ||
s => new Color(s), // transform | ||
false, // useForSnippets | ||
true // preferForRegexpMatch | ||
) | ||
) | ||
/// [add-color-parameter-type] | ||
/* eslint-enable prettier/prettier */ | ||
}) | ||
@@ -44,0 +46,0 @@ |
@@ -53,2 +53,6 @@ /* eslint-env mocha */ | ||
it('works with escaped parenthesis', () => { | ||
assert.deepEqual(match(/Across the line\(s\)/, 'Across the line(s)'), []) | ||
}) | ||
it('exposes regexp and source', () => { | ||
@@ -55,0 +59,0 @@ const regexp = /I have (\d+) cukes? in my (.+) now/ |
@@ -6,2 +6,9 @@ /* eslint-env mocha */ | ||
describe('TreeRegexp', () => { | ||
it('exposes group source', () => { | ||
const tr = new TreeRegexp(/(a(?:b)?)(c)/) | ||
assert.deepEqual( | ||
tr.groupBuilder.children.map(gb => gb.source)[('a(?:b)?', 'c')] | ||
) | ||
}) | ||
it('builds tree', () => { | ||
@@ -8,0 +15,0 @@ const tr = new TreeRegexp(/(a(?:b)?)(c)/) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95819
9
2381
51