refactor(Cypress): add nodemodules

This commit is contained in:
2021-09-02 17:18:41 +02:00
parent 1aa57bbd0a
commit bc6e1bc12e
4238 changed files with 340975 additions and 8 deletions

View File

@@ -0,0 +1,419 @@
2.20.3 / 2019-10-11
==================
* Support Node.js 0.10 (Revert #1059)
* Ran "npm unpublish commander@2.20.2". There is no 2.20.2.
2.20.1 / 2019-09-29
==================
* Improve executable subcommand tracking
* Update dev dependencies
2.20.0 / 2019-04-02
==================
* fix: resolve symbolic links completely when hunting for subcommands (#935)
* Update index.d.ts (#930)
* Update Readme.md (#924)
* Remove --save option as it isn't required anymore (#918)
* Add link to the license file (#900)
* Added example of receiving args from options (#858)
* Added missing semicolon (#882)
* Add extension to .eslintrc (#876)
2.19.0 / 2018-10-02
==================
* Removed newline after Options and Commands headers (#864)
* Bugfix - Error output (#862)
* Fix to change default value to string (#856)
2.18.0 / 2018-09-07
==================
* Standardize help output (#853)
* chmod 644 travis.yml (#851)
* add support for execute typescript subcommand via ts-node (#849)
2.17.1 / 2018-08-07
==================
* Fix bug in command emit (#844)
2.17.0 / 2018-08-03
==================
* fixed newline output after help information (#833)
* Fix to emit the action even without command (#778)
* npm update (#823)
2.16.0 / 2018-06-29
==================
* Remove Makefile and `test/run` (#821)
* Make 'npm test' run on Windows (#820)
* Add badge to display install size (#807)
* chore: cache node_modules (#814)
* chore: remove Node.js 4 (EOL), add Node.js 10 (#813)
* fixed typo in readme (#812)
* Fix types (#804)
* Update eslint to resolve vulnerabilities in lodash (#799)
* updated readme with custom event listeners. (#791)
* fix tests (#794)
2.15.0 / 2018-03-07
==================
* Update downloads badge to point to graph of downloads over time instead of duplicating link to npm
* Arguments description
2.14.1 / 2018-02-07
==================
* Fix typing of help function
2.14.0 / 2018-02-05
==================
* only register the option:version event once
* Fixes issue #727: Passing empty string for option on command is set to undefined
* enable eqeqeq rule
* resolves #754 add linter configuration to project
* resolves #560 respect custom name for version option
* document how to override the version flag
* document using options per command
2.13.0 / 2018-01-09
==================
* Do not print default for --no-
* remove trailing spaces in command help
* Update CI's Node.js to LTS and latest version
* typedefs: Command and Option types added to commander namespace
2.12.2 / 2017-11-28
==================
* fix: typings are not shipped
2.12.1 / 2017-11-23
==================
* Move @types/node to dev dependency
2.12.0 / 2017-11-22
==================
* add attributeName() method to Option objects
* Documentation updated for options with --no prefix
* typings: `outputHelp` takes a string as the first parameter
* typings: use overloads
* feat(typings): update to match js api
* Print default value in option help
* Fix translation error
* Fail when using same command and alias (#491)
* feat(typings): add help callback
* fix bug when description is add after command with options (#662)
* Format js code
* Rename History.md to CHANGELOG.md (#668)
* feat(typings): add typings to support TypeScript (#646)
* use current node
2.11.0 / 2017-07-03
==================
* Fix help section order and padding (#652)
* feature: support for signals to subcommands (#632)
* Fixed #37, --help should not display first (#447)
* Fix translation errors. (#570)
* Add package-lock.json
* Remove engines
* Upgrade package version
* Prefix events to prevent conflicts between commands and options (#494)
* Removing dependency on graceful-readlink
* Support setting name in #name function and make it chainable
* Add .vscode directory to .gitignore (Visual Studio Code metadata)
* Updated link to ruby commander in readme files
2.10.0 / 2017-06-19
==================
* Update .travis.yml. drop support for older node.js versions.
* Fix require arguments in README.md
* On SemVer you do not start from 0.0.1
* Add missing semi colon in readme
* Add save param to npm install
* node v6 travis test
* Update Readme_zh-CN.md
* Allow literal '--' to be passed-through as an argument
* Test subcommand alias help
* link build badge to master branch
* Support the alias of Git style sub-command
* added keyword commander for better search result on npm
* Fix Sub-Subcommands
* test node.js stable
* Fixes TypeError when a command has an option called `--description`
* Update README.md to make it beginner friendly and elaborate on the difference between angled and square brackets.
* Add chinese Readme file
2.9.0 / 2015-10-13
==================
* Add option `isDefault` to set default subcommand #415 @Qix-
* Add callback to allow filtering or post-processing of help text #434 @djulien
* Fix `undefined` text in help information close #414 #416 @zhiyelee
2.8.1 / 2015-04-22
==================
* Back out `support multiline description` Close #396 #397
2.8.0 / 2015-04-07
==================
* Add `process.execArg` support, execution args like `--harmony` will be passed to sub-commands #387 @DigitalIO @zhiyelee
* Fix bug in Git-style sub-commands #372 @zhiyelee
* Allow commands to be hidden from help #383 @tonylukasavage
* When git-style sub-commands are in use, yet none are called, display help #382 @claylo
* Add ability to specify arguments syntax for top-level command #258 @rrthomas
* Support multiline descriptions #208 @zxqfox
2.7.1 / 2015-03-11
==================
* Revert #347 (fix collisions when option and first arg have same name) which causes a bug in #367.
2.7.0 / 2015-03-09
==================
* Fix git-style bug when installed globally. Close #335 #349 @zhiyelee
* Fix collisions when option and first arg have same name. Close #346 #347 @tonylukasavage
* Add support for camelCase on `opts()`. Close #353 @nkzawa
* Add node.js 0.12 and io.js to travis.yml
* Allow RegEx options. #337 @palanik
* Fixes exit code when sub-command failing. Close #260 #332 @pirelenito
* git-style `bin` files in $PATH make sense. Close #196 #327 @zhiyelee
2.6.0 / 2014-12-30
==================
* added `Command#allowUnknownOption` method. Close #138 #318 @doozr @zhiyelee
* Add application description to the help msg. Close #112 @dalssoft
2.5.1 / 2014-12-15
==================
* fixed two bugs incurred by variadic arguments. Close #291 @Quentin01 #302 @zhiyelee
2.5.0 / 2014-10-24
==================
* add support for variadic arguments. Closes #277 @whitlockjc
2.4.0 / 2014-10-17
==================
* fixed a bug on executing the coercion function of subcommands option. Closes #270
* added `Command.prototype.name` to retrieve command name. Closes #264 #266 @tonylukasavage
* added `Command.prototype.opts` to retrieve all the options as a simple object of key-value pairs. Closes #262 @tonylukasavage
* fixed a bug on subcommand name. Closes #248 @jonathandelgado
* fixed function normalize doesnt honor option terminator. Closes #216 @abbr
2.3.0 / 2014-07-16
==================
* add command alias'. Closes PR #210
* fix: Typos. Closes #99
* fix: Unused fs module. Closes #217
2.2.0 / 2014-03-29
==================
* add passing of previous option value
* fix: support subcommands on windows. Closes #142
* Now the defaultValue passed as the second argument of the coercion function.
2.1.0 / 2013-11-21
==================
* add: allow cflag style option params, unit test, fixes #174
2.0.0 / 2013-07-18
==================
* remove input methods (.prompt, .confirm, etc)
1.3.2 / 2013-07-18
==================
* add support for sub-commands to co-exist with the original command
1.3.1 / 2013-07-18
==================
* add quick .runningCommand hack so you can opt-out of other logic when running a sub command
1.3.0 / 2013-07-09
==================
* add EACCES error handling
* fix sub-command --help
1.2.0 / 2013-06-13
==================
* allow "-" hyphen as an option argument
* support for RegExp coercion
1.1.1 / 2012-11-20
==================
* add more sub-command padding
* fix .usage() when args are present. Closes #106
1.1.0 / 2012-11-16
==================
* add git-style executable subcommand support. Closes #94
1.0.5 / 2012-10-09
==================
* fix `--name` clobbering. Closes #92
* fix examples/help. Closes #89
1.0.4 / 2012-09-03
==================
* add `outputHelp()` method.
1.0.3 / 2012-08-30
==================
* remove invalid .version() defaulting
1.0.2 / 2012-08-24
==================
* add `--foo=bar` support [arv]
* fix password on node 0.8.8. Make backward compatible with 0.6 [focusaurus]
1.0.1 / 2012-08-03
==================
* fix issue #56
* fix tty.setRawMode(mode) was moved to tty.ReadStream#setRawMode() (i.e. process.stdin.setRawMode())
1.0.0 / 2012-07-05
==================
* add support for optional option descriptions
* add defaulting of `.version()` to package.json's version
0.6.1 / 2012-06-01
==================
* Added: append (yes or no) on confirmation
* Added: allow node.js v0.7.x
0.6.0 / 2012-04-10
==================
* Added `.prompt(obj, callback)` support. Closes #49
* Added default support to .choose(). Closes #41
* Fixed the choice example
0.5.1 / 2011-12-20
==================
* Fixed `password()` for recent nodes. Closes #36
0.5.0 / 2011-12-04
==================
* Added sub-command option support [itay]
0.4.3 / 2011-12-04
==================
* Fixed custom help ordering. Closes #32
0.4.2 / 2011-11-24
==================
* Added travis support
* Fixed: line-buffered input automatically trimmed. Closes #31
0.4.1 / 2011-11-18
==================
* Removed listening for "close" on --help
0.4.0 / 2011-11-15
==================
* Added support for `--`. Closes #24
0.3.3 / 2011-11-14
==================
* Fixed: wait for close event when writing help info [Jerry Hamlet]
0.3.2 / 2011-11-01
==================
* Fixed long flag definitions with values [felixge]
0.3.1 / 2011-10-31
==================
* Changed `--version` short flag to `-V` from `-v`
* Changed `.version()` so it's configurable [felixge]
0.3.0 / 2011-10-31
==================
* Added support for long flags only. Closes #18
0.2.1 / 2011-10-24
==================
* "node": ">= 0.4.x < 0.7.0". Closes #20
0.2.0 / 2011-09-26
==================
* Allow for defaults that are not just boolean. Default peassignment only occurs for --no-*, optional, and required arguments. [Jim Isaacs]
0.1.0 / 2011-08-24
==================
* Added support for custom `--help` output
0.0.5 / 2011-08-18
==================
* Changed: when the user enters nothing prompt for password again
* Fixed issue with passwords beginning with numbers [NuckChorris]
0.0.4 / 2011-08-15
==================
* Fixed `Commander#args`
0.0.3 / 2011-08-15
==================
* Added default option value support
0.0.2 / 2011-08-15
==================
* Added mask support to `Command#password(str[, mask], fn)`
* Added `Command#password(str, fn)`
0.0.1 / 2010-01-03
==================
* Initial release

22
node_modules/cucumber/node_modules/commander/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

428
node_modules/cucumber/node_modules/commander/Readme.md generated vendored Normal file
View File

@@ -0,0 +1,428 @@
# Commander.js
[![Build Status](https://api.travis-ci.org/tj/commander.js.svg?branch=master)](http://travis-ci.org/tj/commander.js)
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://npmcharts.com/compare/commander?minimal=true)
[![Install Size](https://packagephobia.now.sh/badge?p=commander)](https://packagephobia.now.sh/result?p=commander)
[![Join the chat at https://gitter.im/tj/commander.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander).
[API documentation](http://tj.github.com/commander.js/)
## Installation
$ npm install commander
## Option parsing
Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.1.0')
.option('-p, --peppers', 'Add peppers')
.option('-P, --pineapple', 'Add pineapple')
.option('-b, --bbq-sauce', 'Add bbq sauce')
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
.parse(process.argv);
console.log('you ordered a pizza with:');
if (program.peppers) console.log(' - peppers');
if (program.pineapple) console.log(' - pineapple');
if (program.bbqSauce) console.log(' - bbq');
console.log(' - %s cheese', program.cheese);
```
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
Note that multi-word options starting with `--no` prefix negate the boolean value of the following word. For example, `--no-sauce` sets the value of `program.sauce` to false.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.option('--no-sauce', 'Remove sauce')
.parse(process.argv);
console.log('you ordered a pizza');
if (program.sauce) console.log(' with sauce');
else console.log(' without sauce');
```
To get string arguments from options you will need to use angle brackets <> for required inputs or square brackets [] for optional inputs.
e.g. ```.option('-m --myarg [myVar]', 'my super cool description')```
Then to access the input if it was passed in.
e.g. ```var myInput = program.myarg```
**NOTE**: If you pass a argument without using brackets the example above will return true and not the value passed in.
## Version option
Calling the `version` implicitly adds the `-V` and `--version` options to the command.
When either of these options is present, the command prints the version number and exits.
$ ./examples/pizza -V
0.0.1
If you want your program to respond to the `-v` option instead of the `-V` option, simply pass custom flags to the `version` method using the same syntax as the `option` method.
```js
program
.version('0.0.1', '-v, --version')
```
The version flags can be named anything, but the long option is required.
## Command-specific options
You can attach options to a command.
```js
#!/usr/bin/env node
var program = require('commander');
program
.command('rm <dir>')
.option('-r, --recursive', 'Remove recursively')
.action(function (dir, cmd) {
console.log('remove ' + dir + (cmd.recursive ? ' recursively' : ''))
})
program.parse(process.argv)
```
A command's options are validated when the command is used. Any unknown options will be reported as an error. However, if an action-based command does not define an action, then the options are not validated.
## Coercion
```js
function range(val) {
return val.split('..').map(Number);
}
function list(val) {
return val.split(',');
}
function collect(val, memo) {
memo.push(val);
return memo;
}
function increaseVerbosity(v, total) {
return total + 1;
}
program
.version('0.1.0')
.usage('[options] <file ...>')
.option('-i, --integer <n>', 'An integer argument', parseInt)
.option('-f, --float <n>', 'A float argument', parseFloat)
.option('-r, --range <a>..<b>', 'A range', range)
.option('-l, --list <items>', 'A list', list)
.option('-o, --optional [value]', 'An optional value')
.option('-c, --collect [value]', 'A repeatable value', collect, [])
.option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
.parse(process.argv);
console.log(' int: %j', program.integer);
console.log(' float: %j', program.float);
console.log(' optional: %j', program.optional);
program.range = program.range || [];
console.log(' range: %j..%j', program.range[0], program.range[1]);
console.log(' list: %j', program.list);
console.log(' collect: %j', program.collect);
console.log(' verbosity: %j', program.verbose);
console.log(' args: %j', program.args);
```
## Regular Expression
```js
program
.version('0.1.0')
.option('-s --size <size>', 'Pizza size', /^(large|medium|small)$/i, 'medium')
.option('-d --drink [drink]', 'Drink', /^(coke|pepsi|izze)$/i)
.parse(process.argv);
console.log(' size: %j', program.size);
console.log(' drink: %j', program.drink);
```
## Variadic arguments
The last argument of a command can be variadic, and only the last argument. To make an argument variadic you have to
append `...` to the argument name. Here is an example:
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.1.0')
.command('rmdir <dir> [otherDirs...]')
.action(function (dir, otherDirs) {
console.log('rmdir %s', dir);
if (otherDirs) {
otherDirs.forEach(function (oDir) {
console.log('rmdir %s', oDir);
});
}
});
program.parse(process.argv);
```
An `Array` is used for the value of a variadic argument. This applies to `program.args` as well as the argument passed
to your action as demonstrated above.
## Specify the argument syntax
```js
#!/usr/bin/env node
var program = require('commander');
program
.version('0.1.0')
.arguments('<cmd> [env]')
.action(function (cmd, env) {
cmdValue = cmd;
envValue = env;
});
program.parse(process.argv);
if (typeof cmdValue === 'undefined') {
console.error('no command given!');
process.exit(1);
}
console.log('command:', cmdValue);
console.log('environment:', envValue || "no environment given");
```
Angled brackets (e.g. `<cmd>`) indicate required input. Square brackets (e.g. `[env]`) indicate optional input.
## Git-style sub-commands
```js
// file: ./examples/pm
var program = require('commander');
program
.version('0.1.0')
.command('install [name]', 'install one or more packages')
.command('search [query]', 'search with optional query')
.command('list', 'list packages installed', {isDefault: true})
.parse(process.argv);
```
When `.command()` is invoked with a description argument, no `.action(callback)` should be called to handle sub-commands, otherwise there will be an error. This tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools.
The commander will try to search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-command`, like `pm-install`, `pm-search`.
Options can be passed with the call to `.command()`. Specifying `true` for `opts.noHelp` will remove the subcommand from the generated help output. Specifying `true` for `opts.isDefault` will run the subcommand if no other subcommand is specified.
If the program is designed to be installed globally, make sure the executables have proper modes, like `755`.
### `--harmony`
You can enable `--harmony` option in two ways:
* Use `#! /usr/bin/env node --harmony` in the sub-commands scripts. Note some os version dont support this pattern.
* Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning sub-command process.
## Automated --help
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
```
$ ./examples/pizza --help
Usage: pizza [options]
An application for pizzas ordering
Options:
-h, --help output usage information
-V, --version output the version number
-p, --peppers Add peppers
-P, --pineapple Add pineapple
-b, --bbq Add bbq sauce
-c, --cheese <type> Add the specified type of cheese [marble]
-C, --no-cheese You do not want any cheese
```
## Custom help
You can display arbitrary `-h, --help` information
by listening for "--help". Commander will automatically
exit once you are done so that the remainder of your program
does not execute causing undesired behaviors, for example
in the following executable "stuff" will not output when
`--help` is used.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.1.0')
.option('-f, --foo', 'enable some foo')
.option('-b, --bar', 'enable some bar')
.option('-B, --baz', 'enable some baz');
// must be before .parse() since
// node's emit() is immediate
program.on('--help', function(){
console.log('')
console.log('Examples:');
console.log(' $ custom-help --help');
console.log(' $ custom-help -h');
});
program.parse(process.argv);
console.log('stuff');
```
Yields the following help output when `node script-name.js -h` or `node script-name.js --help` are run:
```
Usage: custom-help [options]
Options:
-h, --help output usage information
-V, --version output the version number
-f, --foo enable some foo
-b, --bar enable some bar
-B, --baz enable some baz
Examples:
$ custom-help --help
$ custom-help -h
```
## .outputHelp(cb)
Output help information without exiting.
Optional callback cb allows post-processing of help text before it is displayed.
If you want to display help by default (e.g. if no command was provided), you can use something like:
```js
var program = require('commander');
var colors = require('colors');
program
.version('0.1.0')
.command('getstream [url]', 'get stream URL')
.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp(make_red);
}
function make_red(txt) {
return colors.red(txt); //display the help text in red on the console
}
```
## .help(cb)
Output help information and exit immediately.
Optional callback cb allows post-processing of help text before it is displayed.
## Custom event listeners
You can execute custom actions by listening to command and option events.
```js
program.on('option:verbose', function () {
process.env.VERBOSE = this.verbose;
});
// error on unknown commands
program.on('command:*', function () {
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
process.exit(1);
});
```
## Examples
```js
var program = require('commander');
program
.version('0.1.0')
.option('-C, --chdir <path>', 'change the working directory')
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
.option('-T, --no-tests', 'ignore test hook');
program
.command('setup [env]')
.description('run setup commands for all envs')
.option("-s, --setup_mode [mode]", "Which setup mode to use")
.action(function(env, options){
var mode = options.setup_mode || "normal";
env = env || 'all';
console.log('setup for %s env(s) with %s mode', env, mode);
});
program
.command('exec <cmd>')
.alias('ex')
.description('execute the given remote cmd')
.option("-e, --exec_mode <mode>", "Which exec mode to use")
.action(function(cmd, options){
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
}).on('--help', function() {
console.log('');
console.log('Examples:');
console.log('');
console.log(' $ deploy exec sequential');
console.log(' $ deploy exec async');
});
program
.command('*')
.action(function(env){
console.log('deploying "%s"', env);
});
program.parse(process.argv);
```
More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
## License
[MIT](https://github.com/tj/commander.js/blob/master/LICENSE)

1224
node_modules/cucumber/node_modules/commander/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
{
"_from": "commander@^2.9.0",
"_id": "commander@2.20.3",
"_inBundle": false,
"_integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"_location": "/cucumber/commander",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "commander@^2.9.0",
"name": "commander",
"escapedName": "commander",
"rawSpec": "^2.9.0",
"saveSpec": null,
"fetchSpec": "^2.9.0"
},
"_requiredBy": [
"/cucumber"
],
"_resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"_shasum": "fd485e84c03eb4881c20722ba48035e8531aeb33",
"_spec": "commander@^2.9.0",
"_where": "/home/simon/Documents/lifen-autotest/node_modules/cucumber",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
},
"bugs": {
"url": "https://github.com/tj/commander.js/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "the complete solution for node.js command-line programs",
"devDependencies": {
"@types/node": "^12.7.8",
"eslint": "^6.4.0",
"should": "^13.2.3",
"sinon": "^7.5.0",
"standard": "^14.3.1",
"ts-node": "^8.4.1",
"typescript": "^3.6.3"
},
"files": [
"index.js",
"typings/index.d.ts"
],
"homepage": "https://github.com/tj/commander.js#readme",
"keywords": [
"commander",
"command",
"option",
"parser"
],
"license": "MIT",
"main": "index",
"name": "commander",
"repository": {
"type": "git",
"url": "git+https://github.com/tj/commander.js.git"
},
"scripts": {
"lint": "eslint index.js",
"test": "node test/run.js && npm run test-typings",
"test-typings": "tsc -p tsconfig.json"
},
"typings": "typings/index.d.ts",
"version": "2.20.3"
}

View File

@@ -0,0 +1,310 @@
// Type definitions for commander 2.11
// Project: https://github.com/visionmedia/commander.js
// Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace local {
class Option {
flags: string;
required: boolean;
optional: boolean;
bool: boolean;
short?: string;
long: string;
description: string;
/**
* Initialize a new `Option` with the given `flags` and `description`.
*
* @param {string} flags
* @param {string} [description]
*/
constructor(flags: string, description?: string);
}
class Command extends NodeJS.EventEmitter {
[key: string]: any;
args: string[];
/**
* Initialize a new `Command`.
*
* @param {string} [name]
*/
constructor(name?: string);
/**
* Set the program version to `str`.
*
* This method auto-registers the "-V, --version" flag
* which will print the version number when passed.
*
* @param {string} str
* @param {string} [flags]
* @returns {Command} for chaining
*/
version(str: string, flags?: string): Command;
/**
* Add command `name`.
*
* The `.action()` callback is invoked when the
* command `name` is specified via __ARGV__,
* and the remaining arguments are applied to the
* function for access.
*
* When the `name` is "*" an un-matched command
* will be passed as the first arg, followed by
* the rest of __ARGV__ remaining.
*
* @example
* program
* .version('0.0.1')
* .option('-C, --chdir <path>', 'change the working directory')
* .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
* .option('-T, --no-tests', 'ignore test hook')
*
* program
* .command('setup')
* .description('run remote setup commands')
* .action(function() {
* console.log('setup');
* });
*
* program
* .command('exec <cmd>')
* .description('run the given remote command')
* .action(function(cmd) {
* console.log('exec "%s"', cmd);
* });
*
* program
* .command('teardown <dir> [otherDirs...]')
* .description('run teardown commands')
* .action(function(dir, otherDirs) {
* console.log('dir "%s"', dir);
* if (otherDirs) {
* otherDirs.forEach(function (oDir) {
* console.log('dir "%s"', oDir);
* });
* }
* });
*
* program
* .command('*')
* .description('deploy the given env')
* .action(function(env) {
* console.log('deploying "%s"', env);
* });
*
* program.parse(process.argv);
*
* @param {string} name
* @param {string} [desc] for git-style sub-commands
* @param {CommandOptions} [opts] command options
* @returns {Command} the new command
*/
command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
/**
* Define argument syntax for the top-level command.
*
* @param {string} desc
* @returns {Command} for chaining
*/
arguments(desc: string): Command;
/**
* Parse expected `args`.
*
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
*
* @param {string[]} args
* @returns {Command} for chaining
*/
parseExpectedArgs(args: string[]): Command;
/**
* Register callback `fn` for the command.
*
* @example
* program
* .command('help')
* .description('display verbose help')
* .action(function() {
* // output help here
* });
*
* @param {(...args: any[]) => void} fn
* @returns {Command} for chaining
*/
action(fn: (...args: any[]) => void): Command;
/**
* Define option with `flags`, `description` and optional
* coercion `fn`.
*
* The `flags` string should contain both the short and long flags,
* separated by comma, a pipe or space. The following are all valid
* all will output this way when `--help` is used.
*
* "-p, --pepper"
* "-p|--pepper"
* "-p --pepper"
*
* @example
* // simple boolean defaulting to false
* program.option('-p, --pepper', 'add pepper');
*
* --pepper
* program.pepper
* // => Boolean
*
* // simple boolean defaulting to true
* program.option('-C, --no-cheese', 'remove cheese');
*
* program.cheese
* // => true
*
* --no-cheese
* program.cheese
* // => false
*
* // required argument
* program.option('-C, --chdir <path>', 'change the working directory');
*
* --chdir /tmp
* program.chdir
* // => "/tmp"
*
* // optional argument
* program.option('-c, --cheese [type]', 'add cheese [marble]');
*
* @param {string} flags
* @param {string} [description]
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
* @param {*} [defaultValue]
* @returns {Command} for chaining
*/
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
option(flags: string, description?: string, defaultValue?: any): Command;
/**
* Allow unknown options on the command line.
*
* @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
* @returns {Command} for chaining
*/
allowUnknownOption(arg?: boolean): Command;
/**
* Parse `argv`, settings options and invoking commands when defined.
*
* @param {string[]} argv
* @returns {Command} for chaining
*/
parse(argv: string[]): Command;
/**
* Parse options from `argv` returning `argv` void of these options.
*
* @param {string[]} argv
* @returns {ParseOptionsResult}
*/
parseOptions(argv: string[]): commander.ParseOptionsResult;
/**
* Return an object containing options as key-value pairs
*
* @returns {{[key: string]: any}}
*/
opts(): { [key: string]: any };
/**
* Set the description to `str`.
*
* @param {string} str
* @param {{[argName: string]: string}} argsDescription
* @return {(Command | string)}
*/
description(str: string, argsDescription?: {[argName: string]: string}): Command;
description(): string;
/**
* Set an alias for the command.
*
* @param {string} alias
* @return {(Command | string)}
*/
alias(alias: string): Command;
alias(): string;
/**
* Set or get the command usage.
*
* @param {string} str
* @return {(Command | string)}
*/
usage(str: string): Command;
usage(): string;
/**
* Set the name of the command.
*
* @param {string} str
* @return {Command}
*/
name(str: string): Command;
/**
* Get the name of the command.
*
* @return {string}
*/
name(): string;
/**
* Output help information for this command.
*
* @param {(str: string) => string} [cb]
*/
outputHelp(cb?: (str: string) => string): void;
/** Output help information and exit.
*
* @param {(str: string) => string} [cb]
*/
help(cb?: (str: string) => string): never;
}
}
declare namespace commander {
type Command = local.Command
type Option = local.Option
interface CommandOptions {
noHelp?: boolean;
isDefault?: boolean;
}
interface ParseOptionsResult {
args: string[];
unknown: string[];
}
interface CommanderStatic extends Command {
Command: typeof local.Command;
Option: typeof local.Option;
CommandOptions: CommandOptions;
ParseOptionsResult: ParseOptionsResult;
}
}
declare const commander: commander.CommanderStatic;
export = commander;

View File

@@ -0,0 +1,3 @@
{
"presets": ["env"]
}

View File

@@ -0,0 +1,21 @@
{
"parserOptions": {
"ecmaVersion": 8
},
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": [
"error", {"trailingComma": "es5", "singleQuote": true, "semi": false}
]
},
"env": {
"node": true,
"es6": true
},
"extends": [
"eslint:recommended",
"prettier"
]
}

View File

@@ -0,0 +1,5 @@
PLEASE DO NOT CREATE ISSUES IN THIS REPO.
THIS REPO IS A READ-ONLY MIRROR.
Create your issue in the Cucumber monorepo instead:
https://github.com/cucumber/cucumber/issues

View File

@@ -0,0 +1,5 @@
PLEASE DO NOT CREATE PULL REAUESTS IN THIS REPO.
THIS REPO IS A READ-ONLY MIRROR.
Create your pull request in the Cucumber monorepo instead:
https://github.com/cucumber/cucumber/pulls

View File

@@ -0,0 +1,9 @@
.idea/
.nyc_output/
coverage/
dist/
node_modules/
yarn.lock
npm-debug.log
build/
package-lock.json

View File

@@ -0,0 +1,5 @@
../../LICENSE LICENSE
../../.templates/github/ .github/
../../.templates/javascript/.travis.yml .travis.yml
../../scripts/prettier-all scripts/prettier-all
../examples.txt examples.txt

View File

@@ -0,0 +1 @@
cucumber/cucumber-expressions-javascript.git

View File

@@ -0,0 +1,15 @@
# Please update /.templates/javascript/.travis.yml in the cucumber/cucumber monorepo
# and sync:
#
# source scripts/functions.sh && rsync_files
#
sudo: false
language: node_js
node_js:
- "10"
- "9"
- "8"
- "6"
- "4"
script: make default

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Cucumber Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,26 @@
ASYNC_SUPPORTED := $(shell node --eval "function async foo(){}" 2> /dev/null)
ifdef ASYNC_SUPPORTED
TEST_TARGET=test
else
TEST_TARGET=babel-test
endif
default: $(TEST_TARGET)
.PHONY: default
test: yarn.lock
yarn test
.PHONY: test
babel-test: yarn.lock
yarn build-test
yarn mocha-built
.PHONY: test
yarn.lock: package.json
yarn install --network-concurrency 1
yarn link
clean:
rm -rf node_modules coverage dist
.PHONY: clean

View File

@@ -0,0 +1,5 @@
# Cucumber Expressions for JavaScript
[![Build Status](https://travis-ci.org/cucumber/cucumber-expressions-javascript.svg?branch=master)](https://travis-ci.org/cucumber/cucumber-expressions-javascript)
[The docs are here](http://docs.cucumber.io/cucumber-expressions/).

View File

@@ -0,0 +1,63 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _require = require('./errors'),
CucumberExpressionError = _require.CucumberExpressionError;
var Argument = function () {
_createClass(Argument, null, [{
key: 'build',
value: function build(treeRegexp, text, parameterTypes) {
var group = treeRegexp.match(text);
if (!group) return null;
var argGroups = group.children;
if (argGroups.length !== parameterTypes.length) {
throw new CucumberExpressionError('Expression ' + treeRegexp.regexp + ' has ' + argGroups.length + ' capture groups (' + argGroups.map(function (g) {
return g.value;
}) + '), but there were ' + parameterTypes.length + ' parameter types (' + parameterTypes.map(function (p) {
return p.name;
}) + ')');
}
return parameterTypes.map(function (parameterType, i) {
return new Argument(argGroups[i], parameterType);
});
}
}]);
function Argument(group, parameterType) {
_classCallCheck(this, Argument);
this._group = group;
this._parameterType = parameterType;
}
_createClass(Argument, [{
key: 'getValue',
/**
* Get the value returned by the parameter type's transformer function.
*
* @param thisObj the object in which the transformer function is applied.
*/
value: function getValue(thisObj) {
var groupValues = this._group ? this._group.values : null;
return this._parameterType.transform(thisObj, groupValues);
}
}, {
key: 'group',
get: function get() {
return this._group;
}
}]);
return Argument;
}();
module.exports = Argument;

View File

@@ -0,0 +1,43 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var GeneratedExpression = require('./generated_expression');
var CombinatorialGeneratedExpressionFactory = function () {
function CombinatorialGeneratedExpressionFactory(expressionTemplate, parameterTypeCombinations) {
_classCallCheck(this, CombinatorialGeneratedExpressionFactory);
this._expressionTemplate = expressionTemplate;
this._parameterTypeCombinations = parameterTypeCombinations;
}
_createClass(CombinatorialGeneratedExpressionFactory, [{
key: 'generateExpressions',
value: function generateExpressions() {
var generatedExpressions = [];
this._generatePermutations(generatedExpressions, 0, []);
return generatedExpressions;
}
}, {
key: '_generatePermutations',
value: function _generatePermutations(generatedExpressions, depth, currentParameterTypes) {
if (depth === this._parameterTypeCombinations.length) {
generatedExpressions.push(new GeneratedExpression(this._expressionTemplate, currentParameterTypes));
return;
}
for (var i = 0; i < this._parameterTypeCombinations[depth].length; ++i) {
var newCurrentParameterTypes = currentParameterTypes.slice(); // clone
newCurrentParameterTypes.push(this._parameterTypeCombinations[depth][i]);
this._generatePermutations(generatedExpressions, depth + 1, newCurrentParameterTypes);
}
}
}]);
return CombinatorialGeneratedExpressionFactory;
}();
module.exports = CombinatorialGeneratedExpressionFactory;

View File

@@ -0,0 +1,111 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Argument = require('./argument');
var TreeRegexp = require('./tree_regexp');
var _require = require('./errors'),
UndefinedParameterTypeError = _require.UndefinedParameterTypeError;
// Does not include (){} characters because they have special meaning
var ESCAPE_REGEXP = /([\\^[$.|?*+])/g;
var PARAMETER_REGEXP = /(\\\\)?{([^}]+)}/g;
var OPTIONAL_REGEXP = /(\\\\)?\(([^)]+)\)/g;
var ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP = /([^\s^/]+)((\/[^\s^/]+)+)/g;
var DOUBLE_ESCAPE = '\\\\';
var CucumberExpression = function () {
/**
* @param expression
* @param parameterTypeRegistry
*/
function CucumberExpression(expression, parameterTypeRegistry) {
_classCallCheck(this, CucumberExpression);
this._expression = expression;
this._parameterTypes = [];
expression = this.processEscapes(expression);
expression = this.processOptional(expression);
expression = this.processAlternation(expression);
expression = this.processParameters(expression, parameterTypeRegistry);
expression = '^' + expression + '$';
this._treeRegexp = new TreeRegexp(expression);
}
_createClass(CucumberExpression, [{
key: 'processEscapes',
value: function processEscapes(expression) {
return expression.replace(ESCAPE_REGEXP, '\\$1');
}
}, {
key: 'processOptional',
value: function processOptional(expression) {
return expression.replace(OPTIONAL_REGEXP, function (match, p1, p2) {
return p1 === DOUBLE_ESCAPE ? '\\(' + p2 + '\\)' : '(?:' + p2 + ')?';
});
}
}, {
key: 'processAlternation',
value: function processAlternation(expression) {
return expression.replace(ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP, function (match) {
// replace \/ with /
// replace / with |
var replacement = match.replace(/\//g, '|').replace(/\\\|/g, '/');
return '(?:' + replacement + ')';
});
}
}, {
key: 'processParameters',
value: function processParameters(expression, parameterTypeRegistry) {
var _this = this;
return expression.replace(PARAMETER_REGEXP, function (match, p1, p2) {
if (p1 === DOUBLE_ESCAPE) return '\\{' + p2 + '\\}';
var typeName = p2;
var parameterType = parameterTypeRegistry.lookupByTypeName(typeName);
if (!parameterType) throw new UndefinedParameterTypeError(typeName);
_this._parameterTypes.push(parameterType);
return buildCaptureRegexp(parameterType.regexps);
});
}
}, {
key: 'match',
value: function match(text) {
return Argument.build(this._treeRegexp, text, this._parameterTypes);
}
}, {
key: 'regexp',
get: function get() {
return this._treeRegexp.regexp;
}
}, {
key: 'source',
get: function get() {
return this._expression;
}
}]);
return CucumberExpression;
}();
function buildCaptureRegexp(regexps) {
if (regexps.length === 1) {
return '(' + regexps[0] + ')';
}
var captureGroups = regexps.map(function (group) {
return '(?:' + group + ')';
});
return '(' + captureGroups.join('|') + ')';
}
module.exports = CucumberExpression;

View File

@@ -0,0 +1,213 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var util = require('util');
var ParameterTypeMatcher = require('./parameter_type_matcher');
var ParameterType = require('./parameter_type');
var CombinatorialGeneratedExpressionFactory = require('./combinatorial_generated_expression_factory');
var CucumberExpressionGenerator = function () {
function CucumberExpressionGenerator(parameterTypeRegistry) {
_classCallCheck(this, CucumberExpressionGenerator);
this._parameterTypeRegistry = parameterTypeRegistry;
}
_createClass(CucumberExpressionGenerator, [{
key: 'generateExpressions',
value: function generateExpressions(text) {
var parameterTypeCombinations = [];
var parameterTypeMatchers = this._createParameterTypeMatchers(text);
var expressionTemplate = '';
var pos = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
var matchingParameterTypeMatchers = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = parameterTypeMatchers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var parameterTypeMatcher = _step.value;
var advancedParameterTypeMatcher = parameterTypeMatcher.advanceTo(pos);
if (advancedParameterTypeMatcher.find) {
matchingParameterTypeMatchers.push(advancedParameterTypeMatcher);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (matchingParameterTypeMatchers.length > 0) {
(function () {
matchingParameterTypeMatchers = matchingParameterTypeMatchers.sort(ParameterTypeMatcher.compare);
// Find all the best parameter type matchers, they are all candidates.
var bestParameterTypeMatcher = matchingParameterTypeMatchers[0];
var bestParameterTypeMatchers = matchingParameterTypeMatchers.filter(function (m) {
return ParameterTypeMatcher.compare(m, bestParameterTypeMatcher) === 0;
});
// Build a list of parameter types without duplicates. The reason there
// might be duplicates is that some parameter types have more than one regexp,
// which means multiple ParameterTypeMatcher objects will have a reference to the
// same ParameterType.
// We're sorting the list so preferential parameter types are listed first.
// Users are most likely to want these, so they should be listed at the top.
var parameterTypes = [];
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = bestParameterTypeMatchers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _parameterTypeMatcher = _step2.value;
if (parameterTypes.indexOf(_parameterTypeMatcher.parameterType) === -1) {
parameterTypes.push(_parameterTypeMatcher.parameterType);
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
parameterTypes = parameterTypes.sort(ParameterType.compare);
parameterTypeCombinations.push(parameterTypes);
expressionTemplate += escape(text.slice(pos, bestParameterTypeMatcher.start));
expressionTemplate += '{%s}';
pos = bestParameterTypeMatcher.start + bestParameterTypeMatcher.group.length;
})();
} else {
break;
}
if (pos >= text.length) {
break;
}
}
expressionTemplate += escape(text.slice(pos));
return new CombinatorialGeneratedExpressionFactory(expressionTemplate, parameterTypeCombinations).generateExpressions();
}
/**
* @deprecated
*/
}, {
key: 'generateExpression',
value: function generateExpression(text) {
var _this = this;
return util.deprecate(function () {
return _this.generateExpressions(text)[0];
}, 'CucumberExpressionGenerator.generateExpression: Use CucumberExpressionGenerator.generateExpressions instead')();
}
}, {
key: '_createParameterTypeMatchers',
value: function _createParameterTypeMatchers(text) {
var parameterMatchers = [];
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = this._parameterTypeRegistry.parameterTypes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var parameterType = _step3.value;
if (parameterType.useForSnippets) {
parameterMatchers = parameterMatchers.concat(this._createParameterTypeMatchers2(parameterType, text));
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
return parameterMatchers;
}
}, {
key: '_createParameterTypeMatchers2',
value: function _createParameterTypeMatchers2(parameterType, text) {
// TODO: [].map
var result = [];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = parameterType.regexps[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var regexp = _step4.value;
result.push(new ParameterTypeMatcher(parameterType, regexp, text));
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
return result;
}
}]);
return CucumberExpressionGenerator;
}();
function escape(s) {
return s.replace(/%/g, '%%') // for util.format
.replace(/\(/g, '\\(').replace(/{/g, '\\{').replace(/\//g, '\\/');
}
module.exports = CucumberExpressionGenerator;

View File

@@ -0,0 +1,77 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var CucumberExpressionError = function (_Error) {
_inherits(CucumberExpressionError, _Error);
function CucumberExpressionError() {
_classCallCheck(this, CucumberExpressionError);
return _possibleConstructorReturn(this, (CucumberExpressionError.__proto__ || Object.getPrototypeOf(CucumberExpressionError)).apply(this, arguments));
}
return CucumberExpressionError;
}(Error);
var AmbiguousParameterTypeError = function (_CucumberExpressionEr) {
_inherits(AmbiguousParameterTypeError, _CucumberExpressionEr);
function AmbiguousParameterTypeError() {
_classCallCheck(this, AmbiguousParameterTypeError);
return _possibleConstructorReturn(this, (AmbiguousParameterTypeError.__proto__ || Object.getPrototypeOf(AmbiguousParameterTypeError)).apply(this, arguments));
}
_createClass(AmbiguousParameterTypeError, null, [{
key: 'forConstructor',
value: function forConstructor(keyName, keyValue, parameterTypes, generatedExpressions) {
return new this('parameter type with ' + keyName + '=' + keyValue + ' is used by several parameter types: ' + parameterTypes + ', ' + generatedExpressions);
}
}, {
key: 'forRegExp',
value: function forRegExp(parameterTypeRegexp, expressionRegexp, parameterTypes, generatedExpressions) {
return new this('Your Regular Expression ' + expressionRegexp + '\nmatches multiple parameter types with regexp ' + parameterTypeRegexp + ':\n ' + this._parameterTypeNames(parameterTypes) + '\n\nI couldn\'t decide which one to use. You have two options:\n\n1) Use a Cucumber Expression instead of a Regular Expression. Try one of these:\n ' + this._expressions(generatedExpressions) + '\n\n2) Make one of the parameter types preferential and continue to use a Regular Expression.\n');
}
}, {
key: '_parameterTypeNames',
value: function _parameterTypeNames(parameterTypes) {
return parameterTypes.map(function (p) {
return '{' + p.name + '}';
}).join('\n ');
}
}, {
key: '_expressions',
value: function _expressions(generatedExpressions) {
return generatedExpressions.map(function (e) {
return e.source;
}).join('\n ');
}
}]);
return AmbiguousParameterTypeError;
}(CucumberExpressionError);
var UndefinedParameterTypeError = function (_CucumberExpressionEr2) {
_inherits(UndefinedParameterTypeError, _CucumberExpressionEr2);
function UndefinedParameterTypeError(typeName) {
_classCallCheck(this, UndefinedParameterTypeError);
return _possibleConstructorReturn(this, (UndefinedParameterTypeError.__proto__ || Object.getPrototypeOf(UndefinedParameterTypeError)).call(this, 'Undefined parameter type {' + typeName + '}'));
}
return UndefinedParameterTypeError;
}(CucumberExpressionError);
module.exports = {
AmbiguousParameterTypeError: AmbiguousParameterTypeError,
UndefinedParameterTypeError: UndefinedParameterTypeError,
CucumberExpressionError: CucumberExpressionError
};

View File

@@ -0,0 +1,64 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var util = require('util');
var GeneratedExpression = function () {
function GeneratedExpression(expressionTemplate, parameterTypes) {
_classCallCheck(this, GeneratedExpression);
this._expressionTemplate = expressionTemplate;
this._parameterTypes = parameterTypes;
}
_createClass(GeneratedExpression, [{
key: 'source',
get: function get() {
return util.format.apply(util, [this._expressionTemplate].concat(_toConsumableArray(this._parameterTypes.map(function (t) {
return t.name;
}))));
}
/**
* Returns an array of parameter names to use in generated function/method signatures
*
* @returns {Array.<String>}
*/
}, {
key: 'parameterNames',
get: function get() {
var usageByTypeName = {};
return this._parameterTypes.map(function (t) {
return getParameterName(t.name, usageByTypeName);
});
}
/**
* @returns {Array.<ParameterType>}
*/
}, {
key: 'parameterTypes',
get: function get() {
return this._parameterTypes;
}
}]);
return GeneratedExpression;
}();
function getParameterName(typeName, usageByTypeName) {
var count = usageByTypeName[typeName];
count = count ? count + 1 : 1;
usageByTypeName[typeName] = count;
return count === 1 ? typeName : '' + typeName + count;
}
module.exports = GeneratedExpression;

View File

@@ -0,0 +1,51 @@
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Group = function () {
function Group(value, start, end, children) {
_classCallCheck(this, Group);
this._value = value;
this._start = start;
this._end = end;
this._children = children;
}
_createClass(Group, [{
key: "value",
get: function get() {
return this._value;
}
}, {
key: "start",
get: function get() {
return this._start;
}
}, {
key: "end",
get: function get() {
return this._end;
}
}, {
key: "children",
get: function get() {
return this._children;
}
}, {
key: "values",
get: function get() {
return (this.children.length === 0 ? [this] : this.children).map(function (g) {
return g.value;
}).filter(function (v) {
return v !== undefined;
});
}
}]);
return Group;
}();
module.exports = Group;

View File

@@ -0,0 +1,58 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Group = require('./group');
var GroupBuilder = function () {
function GroupBuilder() {
_classCallCheck(this, GroupBuilder);
this._groupBuilders = [];
this._capturing = true;
}
_createClass(GroupBuilder, [{
key: 'add',
value: function add(groupBuilder) {
this._groupBuilders.push(groupBuilder);
}
}, {
key: 'build',
value: function build(match, nextGroupIndex) {
var groupIndex = nextGroupIndex();
var children = this._groupBuilders.map(function (gb) {
return gb.build(match, nextGroupIndex);
});
return new Group(match[groupIndex], match.index[groupIndex], match.index[groupIndex] + (match[groupIndex] || '').length, children);
}
}, {
key: 'setNonCapturing',
value: function setNonCapturing() {
this._capturing = false;
}
}, {
key: 'moveChildrenTo',
value: function moveChildrenTo(groupBuilder) {
this._groupBuilders.forEach(function (child) {
return groupBuilder.add(child);
});
}
}, {
key: 'capturing',
get: function get() {
return this._capturing;
}
}, {
key: 'children',
get: function get() {
return this._groupBuilders;
}
}]);
return GroupBuilder;
}();
module.exports = GroupBuilder;

View File

@@ -0,0 +1,15 @@
'use strict';
var CucumberExpression = require('./cucumber_expression');
var RegularExpression = require('./regular_expression');
var CucumberExpressionGenerator = require('./cucumber_expression_generator');
var ParameterTypeRegistry = require('./parameter_type_registry');
var ParameterType = require('./parameter_type');
module.exports = {
CucumberExpression: CucumberExpression,
RegularExpression: RegularExpression,
CucumberExpressionGenerator: CucumberExpressionGenerator,
ParameterTypeRegistry: ParameterTypeRegistry,
ParameterType: ParameterType
};

View File

@@ -0,0 +1,116 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _require = require('./errors'),
CucumberExpressionError = _require.CucumberExpressionError;
var ParameterType = function () {
_createClass(ParameterType, null, [{
key: 'compare',
value: function compare(pt1, pt2) {
if (pt1.preferForRegexpMatch && !pt2.preferForRegexpMatch) return -1;
if (pt2.preferForRegexpMatch && !pt1.preferForRegexpMatch) return 1;
return pt1.name.localeCompare(pt2.name);
}
/**
* @param name {String} the name of the type
* @param regexps {Array.<RegExp>,RegExp,Array.<String>,String} that matches the type
* @param type {Function} the prototype (constructor) of the type. May be null.
* @param transform {Function} function transforming string to another type. May be null.
* @param useForSnippets {boolean} true if this should be used for snippets. Defaults to true.
* @param preferForRegexpMatch {boolean} true if this is a preferential type. Defaults to false.
*/
}]);
function ParameterType(name, regexps, type, transform, useForSnippets, preferForRegexpMatch) {
_classCallCheck(this, ParameterType);
if (transform === undefined) transform = function transform(s) {
return s;
};
if (useForSnippets === undefined) useForSnippets = true;
if (preferForRegexpMatch === undefined) preferForRegexpMatch = false;
this._name = name;
this._regexps = stringArray(regexps);
this._type = type;
this._transform = transform;
this._useForSnippets = useForSnippets;
this._preferForRegexpMatch = preferForRegexpMatch;
}
_createClass(ParameterType, [{
key: 'transform',
value: function transform(thisObj, groupValues) {
return this._transform.apply(thisObj, groupValues);
}
}, {
key: 'name',
get: function get() {
return this._name;
}
}, {
key: 'regexps',
get: function get() {
return this._regexps;
}
}, {
key: 'type',
get: function get() {
return this._type;
}
}, {
key: 'preferForRegexpMatch',
get: function get() {
return this._preferForRegexpMatch;
}
}, {
key: 'useForSnippets',
get: function get() {
return this._useForSnippets;
}
}]);
return ParameterType;
}();
function stringArray(regexps) {
var array = Array.isArray(regexps) ? regexps : [regexps];
return array.map(function (r) {
return typeof r === 'string' ? r : regexpSource(r);
});
}
function regexpSource(regexp) {
var flags = regexpFlags(regexp);
var _arr = ['g', 'i', 'm', 'y'];
for (var _i = 0; _i < _arr.length; _i++) {
var flag = _arr[_i];
if (flags.indexOf(flag) !== -1) throw new CucumberExpressionError('ParameterType Regexps can\'t use flag \'' + flag + '\'');
}
return regexp.source;
}
// Backport RegExp.flags for Node 4.x
// https://github.com/nodejs/node/issues/8390
//
// For some strange reason this is not needed for
// `./mocha dist/test`, but it is needed for
// `./mocha dist/test/parameter_type_test.js`
function regexpFlags(regexp) {
var flags = regexp.flags;
if (flags === undefined) {
flags = '';
if (regexp.ignoreCase) flags += 'i';
if (regexp.global) flags += 'g';
if (regexp.multiline) flags += 'm';
}
return flags;
}
module.exports = ParameterType;

View File

@@ -0,0 +1,59 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ParameterTypeMatcher = function () {
function ParameterTypeMatcher(parameter, regexp, text, matchPosition) {
_classCallCheck(this, ParameterTypeMatcher);
this._parameterType = parameter;
this._treeRegexp = regexp;
this._text = text;
this._matchPosition = matchPosition || 0;
var captureGroupRegexp = new RegExp('(' + regexp + ')');
this._match = captureGroupRegexp.exec(text.slice(this._matchPosition));
}
_createClass(ParameterTypeMatcher, [{
key: 'advanceTo',
value: function advanceTo(newMatchPosition) {
return new ParameterTypeMatcher(this._parameterType, this._treeRegexp, this._text, newMatchPosition);
}
}, {
key: 'parameterType',
get: function get() {
return this._parameterType;
}
}, {
key: 'find',
get: function get() {
return this._match && this.group !== '';
}
}, {
key: 'start',
get: function get() {
return this._matchPosition + this._match.index;
}
}, {
key: 'group',
get: function get() {
return this._match[0];
}
}], [{
key: 'compare',
value: function compare(a, b) {
var posComparison = a.start - b.start;
if (posComparison !== 0) return posComparison;
var lengthComparison = b.group.length - a.group.length;
if (lengthComparison !== 0) return lengthComparison;
return 0;
}
}]);
return ParameterTypeMatcher;
}();
module.exports = ParameterTypeMatcher;

View File

@@ -0,0 +1,107 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ParameterType = require('./parameter_type');
var CucumberExpressionGenerator = require('./cucumber_expression_generator.js');
var _require = require('./errors'),
CucumberExpressionError = _require.CucumberExpressionError,
AmbiguousParameterTypeError = _require.AmbiguousParameterTypeError;
var INTEGER_REGEXPS = [/-?\d+/, /\d+/];
var FLOAT_REGEXP = /-?\d*\.\d+/;
var WORD_REGEXP = /\w+/;
var STRING_REGEXP = /"([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)'/;
var ParameterTypeRegistry = function () {
function ParameterTypeRegistry() {
_classCallCheck(this, ParameterTypeRegistry);
this._parameterTypeByName = new Map();
this._parameterTypesByRegexp = new Map();
this.defineParameterType(new ParameterType('int', INTEGER_REGEXPS, Number, parseInt, true, true));
this.defineParameterType(new ParameterType('float', FLOAT_REGEXP, Number, parseFloat, true, false));
this.defineParameterType(new ParameterType('word', WORD_REGEXP, String, function (s) {
return s;
}, false, false));
this.defineParameterType(new ParameterType('string', STRING_REGEXP, String, function (s) {
return s.replace(/\\"/g, '"').replace(/\\'/g, "'");
}, true, false));
}
_createClass(ParameterTypeRegistry, [{
key: 'lookupByTypeName',
value: function lookupByTypeName(typeName) {
return this._parameterTypeByName.get(typeName);
}
}, {
key: 'lookupByRegexp',
value: function lookupByRegexp(parameterTypeRegexp, expressionRegexp, text) {
var parameterTypes = this._parameterTypesByRegexp.get(parameterTypeRegexp);
if (!parameterTypes) return null;
if (parameterTypes.length > 1 && !parameterTypes[0].preferForRegexpMatch) {
// We don't do this check on insertion because we only want to restrict
// ambiguiuty when we look up by Regexp. Users of CucumberExpression should
// not be restricted.
var generatedExpressions = new CucumberExpressionGenerator(this).generateExpressions(text);
throw new AmbiguousParameterTypeError.forRegExp(parameterTypeRegexp, expressionRegexp, parameterTypes, generatedExpressions);
}
return parameterTypes[0];
}
}, {
key: 'defineParameterType',
value: function defineParameterType(parameterType) {
if (this._parameterTypeByName.has(parameterType.name)) throw new Error('There is already a parameter type with name ' + parameterType.name);
this._parameterTypeByName.set(parameterType.name, parameterType);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = parameterType.regexps[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var parameterTypeRegexp = _step.value;
if (!this._parameterTypesByRegexp.has(parameterTypeRegexp)) {
this._parameterTypesByRegexp.set(parameterTypeRegexp, []);
}
var parameterTypes = this._parameterTypesByRegexp.get(parameterTypeRegexp);
var existingParameterType = parameterTypes[0];
if (parameterTypes.length > 0 && existingParameterType.preferForRegexpMatch && parameterType.preferForRegexpMatch) {
throw new CucumberExpressionError('There can only be one preferential parameter type per regexp. ' + ('The regexp /' + parameterTypeRegexp + '/ is used for two preferential parameter types, {' + existingParameterType.name + '} and {' + parameterType.name + '}'));
}
if (parameterTypes.indexOf(parameterType) === -1) {
parameterTypes.push(parameterType);
this._parameterTypesByRegexp.set(parameterTypeRegexp, parameterTypes.sort(ParameterType.compare));
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}, {
key: 'parameterTypes',
get: function get() {
return this._parameterTypeByName.values();
}
}]);
return ParameterTypeRegistry;
}();
module.exports = ParameterTypeRegistry;

View File

@@ -0,0 +1,50 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Argument = require('./argument');
var TreeRegexp = require('./tree_regexp');
var ParameterType = require('./parameter_type');
var RegularExpression = function () {
function RegularExpression(expressionRegexp, parameterTypeRegistry) {
_classCallCheck(this, RegularExpression);
this._expressionRegexp = expressionRegexp;
this._parameterTypeRegistry = parameterTypeRegistry;
this._treeRegexp = new TreeRegexp(expressionRegexp);
}
_createClass(RegularExpression, [{
key: 'match',
value: function match(text) {
var _this = this;
var parameterTypes = this._treeRegexp.groupBuilder.children.map(function (groupBuilder) {
var parameterTypeRegexp = groupBuilder.source;
return _this._parameterTypeRegistry.lookupByRegexp(parameterTypeRegexp, _this._treeRegexp, text) || new ParameterType(parameterTypeRegexp, parameterTypeRegexp, String, function (s) {
return s;
}, false, false);
});
return Argument.build(this._treeRegexp, text, parameterTypes);
}
}, {
key: 'regexp',
get: function get() {
return this._expressionRegexp;
}
}, {
key: 'source',
get: function get() {
return this._expressionRegexp.source;
}
}]);
return RegularExpression;
}();
module.exports = RegularExpression;

View File

@@ -0,0 +1,77 @@
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Regex = require('becke-ch--regex--s0-0-v1--base--pl--lib');
var GroupBuilder = require('./group_builder');
var TreeRegexp = function () {
function TreeRegexp(regexp) {
var _this = this;
_classCallCheck(this, TreeRegexp);
this._re = 'string' === typeof regexp ? new RegExp(regexp) : regexp;
this._regex = new Regex(this._re.source, this._re.flags);
var stack = [new GroupBuilder()];
var groupStartStack = [];
var last = null;
var escaping = false;
var nonCapturingMaybe = false;
this._re.source.split('').forEach(function (c, n) {
if (c === '(' && !escaping) {
stack.push(new GroupBuilder());
groupStartStack.push(n + 1);
nonCapturingMaybe = false;
} else if (c === ')' && !escaping) {
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);
} else {
gb.moveChildrenTo(stack[stack.length - 1]);
}
nonCapturingMaybe = false;
} else if (c === '?' && last === '(') {
nonCapturingMaybe = true;
} else if (c === ':' && nonCapturingMaybe) {
stack[stack.length - 1].setNonCapturing();
nonCapturingMaybe = false;
}
escaping = c === '\\' && !escaping;
last = c;
});
this._groupBuilder = stack.pop();
}
_createClass(TreeRegexp, [{
key: 'match',
value: function match(s) {
var match = this._regex.exec(s);
if (!match) return null;
var groupIndex = 0;
var nextGroupIndex = function nextGroupIndex() {
return groupIndex++;
};
return this._groupBuilder.build(match, nextGroupIndex);
}
}, {
key: 'regexp',
get: function get() {
return this._re;
}
}, {
key: 'groupBuilder',
get: function get() {
return this._groupBuilder;
}
}]);
return TreeRegexp;
}();
module.exports = TreeRegexp;

View File

@@ -0,0 +1,19 @@
I have {int} cuke(s)
I have 22 cukes
[22]
---
I have {int} cuke(s) and some \[]^$.|?*+
I have 1 cuke and some \[]^$.|?*+
[1]
---
/I have (\d+) cukes? in my (\w+) now/
I have 22 cukes in my belly now
[22,"belly"]
---
/I have (-?\d+) cukes? in my (.*) now/
I have 1 cuke in my belly now
[1,"belly"]
---
/^Something( with an optional argument)?$/
Something
[null]

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bash
node_modules/.bin/mocha "$@"

View File

@@ -0,0 +1,80 @@
{
"_from": "cucumber-expressions@^5.0.13",
"_id": "cucumber-expressions@5.0.18",
"_inBundle": false,
"_integrity": "sha1-bHB3nv0668Xp54U5OLERAyJClZY=",
"_location": "/cucumber/cucumber-expressions",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "cucumber-expressions@^5.0.13",
"name": "cucumber-expressions",
"escapedName": "cucumber-expressions",
"rawSpec": "^5.0.13",
"saveSpec": null,
"fetchSpec": "^5.0.13"
},
"_requiredBy": [
"/cucumber"
],
"_resolved": "https://registry.npmjs.org/cucumber-expressions/-/cucumber-expressions-5.0.18.tgz",
"_shasum": "6c70779efd3aebc5e9e7853938b1110322429596",
"_spec": "cucumber-expressions@^5.0.13",
"_where": "/home/simon/Documents/lifen-autotest/node_modules/cucumber",
"author": {
"name": "Cucumber Limited",
"email": "cukes@googlegroups.com"
},
"bugs": {
"url": "https://github.com/cucumber/cucumber-expressions-javascript/issues"
},
"bundleDependencies": false,
"dependencies": {
"becke-ch--regex--s0-0-v1--base--pl--lib": "^1.2.0"
},
"deprecated": false,
"description": "Cucumber Expressions - a simpler alternative to Regular Expressions",
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.1",
"eslint": "^4.19.1",
"eslint-config-eslint": "^4.0.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"mocha": "^5.0.5",
"nyc": "^11.6.0",
"prettier": "^1.11.1"
},
"files": [
"*"
],
"homepage": "https://github.com/cucumber/cucumber-expressions-javascript#readme",
"keywords": [
"cucumber",
"steps",
"regexp",
"regex"
],
"license": "MIT",
"main": "dist/src/index.js",
"name": "cucumber-expressions",
"repository": {
"type": "git",
"url": "git://github.com/cucumber/cucumber-expressions-javascript.git"
},
"scripts": {
"build": "babel src --out-dir dist/src",
"build-test": "babel test --out-dir dist/test",
"coverage": "nyc --reporter=html --reporter=text mocha",
"eslint": "eslint src test",
"eslint-fix": "eslint --fix src test",
"mocha": "mocha",
"mocha-built": "mocha dist/test",
"postinstall": "node scripts/postinstall.js",
"prepare": "yarn build",
"test": "npm run eslint && npm run coverage"
},
"version": "5.0.18"
}

View File

@@ -0,0 +1,10 @@
var path = require('path')
var fs = require('fs')
var exec = require('child_process').exec
fs.access(path.join(__dirname, '..', 'dist'), function(err) {
if (!err) return
exec('yarn build', { cwd: path.join(__dirname, '..') }, function(err) {
if (err) throw err
})
})

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
#
# Reformat and lint all JavaScript with prettier/eslint
#
set -euf -o pipefail
git ls-files . | \
grep "\.jsx\?$" | \
xargs ./node_modules/.bin/eslint --ext=js --ext=jsx --fix

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e
if [[ $(node --version) =~ ^v6 ]]; then
yarn build
yarn build-test
yarn mocha-built
else
yarn test
fi

View File

@@ -0,0 +1,45 @@
const { CucumberExpressionError } = require('./errors')
class Argument {
static build(treeRegexp, text, parameterTypes) {
const group = treeRegexp.match(text)
if (!group) return null
const argGroups = group.children
if (argGroups.length !== parameterTypes.length) {
throw new CucumberExpressionError(
`Expression ${treeRegexp.regexp} has ${
argGroups.length
} capture groups (${argGroups.map(g => g.value)}), but there were ${
parameterTypes.length
} parameter types (${parameterTypes.map(p => p.name)})`
)
}
return parameterTypes.map(
(parameterType, i) => new Argument(argGroups[i], parameterType)
)
}
constructor(group, parameterType) {
this._group = group
this._parameterType = parameterType
}
get group() {
return this._group
}
/**
* Get the value returned by the parameter type's transformer function.
*
* @param thisObj the object in which the transformer function is applied.
*/
getValue(thisObj) {
let groupValues = this._group ? this._group.values : null
return this._parameterType.transform(thisObj, groupValues)
}
}
module.exports = Argument

View File

@@ -0,0 +1,35 @@
const GeneratedExpression = require('./generated_expression')
class CombinatorialGeneratedExpressionFactory {
constructor(expressionTemplate, parameterTypeCombinations) {
this._expressionTemplate = expressionTemplate
this._parameterTypeCombinations = parameterTypeCombinations
}
generateExpressions() {
const generatedExpressions = []
this._generatePermutations(generatedExpressions, 0, [])
return generatedExpressions
}
_generatePermutations(generatedExpressions, depth, currentParameterTypes) {
if (depth === this._parameterTypeCombinations.length) {
generatedExpressions.push(
new GeneratedExpression(this._expressionTemplate, currentParameterTypes)
)
return
}
for (let i = 0; i < this._parameterTypeCombinations[depth].length; ++i) {
const newCurrentParameterTypes = currentParameterTypes.slice() // clone
newCurrentParameterTypes.push(this._parameterTypeCombinations[depth][i])
this._generatePermutations(
generatedExpressions,
depth + 1,
newCurrentParameterTypes
)
}
}
}
module.exports = CombinatorialGeneratedExpressionFactory

View File

@@ -0,0 +1,87 @@
const Argument = require('./argument')
const TreeRegexp = require('./tree_regexp')
const { UndefinedParameterTypeError } = require('./errors')
// Does not include (){} characters because they have special meaning
const ESCAPE_REGEXP = /([\\^[$.|?*+])/g
const PARAMETER_REGEXP = /(\\\\)?{([^}]+)}/g
const OPTIONAL_REGEXP = /(\\\\)?\(([^)]+)\)/g
const ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP = /([^\s^/]+)((\/[^\s^/]+)+)/g
const DOUBLE_ESCAPE = '\\\\'
class CucumberExpression {
/**
* @param expression
* @param parameterTypeRegistry
*/
constructor(expression, parameterTypeRegistry) {
this._expression = expression
this._parameterTypes = []
expression = this.processEscapes(expression)
expression = this.processOptional(expression)
expression = this.processAlternation(expression)
expression = this.processParameters(expression, parameterTypeRegistry)
expression = `^${expression}$`
this._treeRegexp = new TreeRegexp(expression)
}
processEscapes(expression) {
return expression.replace(ESCAPE_REGEXP, '\\$1')
}
processOptional(expression) {
return expression.replace(
OPTIONAL_REGEXP,
(match, p1, p2) => (p1 === DOUBLE_ESCAPE ? `\\(${p2}\\)` : `(?:${p2})?`)
)
}
processAlternation(expression) {
return expression.replace(ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP, match => {
// replace \/ with /
// replace / with |
const replacement = match.replace(/\//g, '|').replace(/\\\|/g, '/')
return `(?:${replacement})`
})
}
processParameters(expression, parameterTypeRegistry) {
return expression.replace(PARAMETER_REGEXP, (match, p1, p2) => {
if (p1 === DOUBLE_ESCAPE) return `\\{${p2}\\}`
const typeName = p2
const parameterType = parameterTypeRegistry.lookupByTypeName(typeName)
if (!parameterType) throw new UndefinedParameterTypeError(typeName)
this._parameterTypes.push(parameterType)
return buildCaptureRegexp(parameterType.regexps)
})
}
match(text) {
return Argument.build(this._treeRegexp, text, this._parameterTypes)
}
get regexp() {
return this._treeRegexp.regexp
}
get source() {
return this._expression
}
}
function buildCaptureRegexp(regexps) {
if (regexps.length === 1) {
return `(${regexps[0]})`
}
const captureGroups = regexps.map(group => {
return `(?:${group})`
})
return `(${captureGroups.join('|')})`
}
module.exports = CucumberExpression

View File

@@ -0,0 +1,120 @@
const util = require('util')
const ParameterTypeMatcher = require('./parameter_type_matcher')
const ParameterType = require('./parameter_type')
const CombinatorialGeneratedExpressionFactory = require('./combinatorial_generated_expression_factory')
class CucumberExpressionGenerator {
constructor(parameterTypeRegistry) {
this._parameterTypeRegistry = parameterTypeRegistry
}
generateExpressions(text) {
const parameterTypeCombinations = []
const parameterTypeMatchers = this._createParameterTypeMatchers(text)
let expressionTemplate = ''
let pos = 0
// eslint-disable-next-line no-constant-condition
while (true) {
let matchingParameterTypeMatchers = []
for (const parameterTypeMatcher of parameterTypeMatchers) {
const advancedParameterTypeMatcher = parameterTypeMatcher.advanceTo(pos)
if (advancedParameterTypeMatcher.find) {
matchingParameterTypeMatchers.push(advancedParameterTypeMatcher)
}
}
if (matchingParameterTypeMatchers.length > 0) {
matchingParameterTypeMatchers = matchingParameterTypeMatchers.sort(
ParameterTypeMatcher.compare
)
// Find all the best parameter type matchers, they are all candidates.
const bestParameterTypeMatcher = matchingParameterTypeMatchers[0]
const bestParameterTypeMatchers = matchingParameterTypeMatchers.filter(
m => ParameterTypeMatcher.compare(m, bestParameterTypeMatcher) === 0
)
// Build a list of parameter types without duplicates. The reason there
// might be duplicates is that some parameter types have more than one regexp,
// which means multiple ParameterTypeMatcher objects will have a reference to the
// same ParameterType.
// We're sorting the list so preferential parameter types are listed first.
// Users are most likely to want these, so they should be listed at the top.
let parameterTypes = []
for (const parameterTypeMatcher of bestParameterTypeMatchers) {
if (
parameterTypes.indexOf(parameterTypeMatcher.parameterType) === -1
) {
parameterTypes.push(parameterTypeMatcher.parameterType)
}
}
parameterTypes = parameterTypes.sort(ParameterType.compare)
parameterTypeCombinations.push(parameterTypes)
expressionTemplate += escape(
text.slice(pos, bestParameterTypeMatcher.start)
)
expressionTemplate += '{%s}'
pos =
bestParameterTypeMatcher.start + bestParameterTypeMatcher.group.length
} else {
break
}
if (pos >= text.length) {
break
}
}
expressionTemplate += escape(text.slice(pos))
return new CombinatorialGeneratedExpressionFactory(
expressionTemplate,
parameterTypeCombinations
).generateExpressions()
}
/**
* @deprecated
*/
generateExpression(text) {
return util.deprecate(
() => this.generateExpressions(text)[0],
'CucumberExpressionGenerator.generateExpression: Use CucumberExpressionGenerator.generateExpressions instead'
)()
}
_createParameterTypeMatchers(text) {
let parameterMatchers = []
for (const parameterType of this._parameterTypeRegistry.parameterTypes) {
if (parameterType.useForSnippets) {
parameterMatchers = parameterMatchers.concat(
this._createParameterTypeMatchers2(parameterType, text)
)
}
}
return parameterMatchers
}
_createParameterTypeMatchers2(parameterType, text) {
// TODO: [].map
const result = []
for (const regexp of parameterType.regexps) {
result.push(new ParameterTypeMatcher(parameterType, regexp, text))
}
return result
}
}
function escape(s) {
return s
.replace(/%/g, '%%') // for util.format
.replace(/\(/g, '\\(')
.replace(/{/g, '\\{')
.replace(/\//g, '\\/')
}
module.exports = CucumberExpressionGenerator

View File

@@ -0,0 +1,55 @@
class CucumberExpressionError extends Error {}
class AmbiguousParameterTypeError extends CucumberExpressionError {
static forConstructor(
keyName,
keyValue,
parameterTypes,
generatedExpressions
) {
return new this(
`parameter type with ${keyName}=${keyValue} is used by several parameter types: ${parameterTypes}, ${generatedExpressions}`
)
}
static forRegExp(
parameterTypeRegexp,
expressionRegexp,
parameterTypes,
generatedExpressions
) {
return new this(
`Your Regular Expression ${expressionRegexp}
matches multiple parameter types with regexp ${parameterTypeRegexp}:
${this._parameterTypeNames(parameterTypes)}
I couldn't decide which one to use. You have two options:
1) Use a Cucumber Expression instead of a Regular Expression. Try one of these:
${this._expressions(generatedExpressions)}
2) Make one of the parameter types preferential and continue to use a Regular Expression.
`
)
}
static _parameterTypeNames(parameterTypes) {
return parameterTypes.map(p => `{${p.name}}`).join('\n ')
}
static _expressions(generatedExpressions) {
return generatedExpressions.map(e => e.source).join('\n ')
}
}
class UndefinedParameterTypeError extends CucumberExpressionError {
constructor(typeName) {
super(`Undefined parameter type {${typeName}}`)
}
}
module.exports = {
AmbiguousParameterTypeError,
UndefinedParameterTypeError,
CucumberExpressionError,
}

View File

@@ -0,0 +1,44 @@
const util = require('util')
class GeneratedExpression {
constructor(expressionTemplate, parameterTypes) {
this._expressionTemplate = expressionTemplate
this._parameterTypes = parameterTypes
}
get source() {
return util.format(
this._expressionTemplate,
...this._parameterTypes.map(t => t.name)
)
}
/**
* Returns an array of parameter names to use in generated function/method signatures
*
* @returns {Array.<String>}
*/
get parameterNames() {
const usageByTypeName = {}
return this._parameterTypes.map(t =>
getParameterName(t.name, usageByTypeName)
)
}
/**
* @returns {Array.<ParameterType>}
*/
get parameterTypes() {
return this._parameterTypes
}
}
function getParameterName(typeName, usageByTypeName) {
let count = usageByTypeName[typeName]
count = count ? count + 1 : 1
usageByTypeName[typeName] = count
return count === 1 ? typeName : `${typeName}${count}`
}
module.exports = GeneratedExpression

View File

@@ -0,0 +1,32 @@
class Group {
constructor(value, start, end, children) {
this._value = value
this._start = start
this._end = end
this._children = children
}
get value() {
return this._value
}
get start() {
return this._start
}
get end() {
return this._end
}
get children() {
return this._children
}
get values() {
return (this.children.length === 0 ? [this] : this.children)
.map(g => g.value)
.filter(v => v !== undefined)
}
}
module.exports = Group

View File

@@ -0,0 +1,43 @@
const Group = require('./group')
class GroupBuilder {
constructor() {
this._groupBuilders = []
this._capturing = true
}
add(groupBuilder) {
this._groupBuilders.push(groupBuilder)
}
build(match, nextGroupIndex) {
const groupIndex = nextGroupIndex()
const children = this._groupBuilders.map(gb =>
gb.build(match, nextGroupIndex)
)
return new Group(
match[groupIndex],
match.index[groupIndex],
match.index[groupIndex] + (match[groupIndex] || '').length,
children
)
}
setNonCapturing() {
this._capturing = false
}
get capturing() {
return this._capturing
}
get children() {
return this._groupBuilders
}
moveChildrenTo(groupBuilder) {
this._groupBuilders.forEach(child => groupBuilder.add(child))
}
}
module.exports = GroupBuilder

View File

@@ -0,0 +1,13 @@
const CucumberExpression = require('./cucumber_expression')
const RegularExpression = require('./regular_expression')
const CucumberExpressionGenerator = require('./cucumber_expression_generator')
const ParameterTypeRegistry = require('./parameter_type_registry')
const ParameterType = require('./parameter_type')
module.exports = {
CucumberExpression,
RegularExpression,
CucumberExpressionGenerator,
ParameterTypeRegistry,
ParameterType,
}

View File

@@ -0,0 +1,96 @@
const { CucumberExpressionError } = require('./errors')
class ParameterType {
static compare(pt1, pt2) {
if (pt1.preferForRegexpMatch && !pt2.preferForRegexpMatch) return -1
if (pt2.preferForRegexpMatch && !pt1.preferForRegexpMatch) return 1
return pt1.name.localeCompare(pt2.name)
}
/**
* @param name {String} the name of the type
* @param regexps {Array.<RegExp>,RegExp,Array.<String>,String} that matches the type
* @param type {Function} the prototype (constructor) of the type. May be null.
* @param transform {Function} function transforming string to another type. May be null.
* @param useForSnippets {boolean} true if this should be used for snippets. Defaults to true.
* @param preferForRegexpMatch {boolean} true if this is a preferential type. Defaults to false.
*/
constructor(
name,
regexps,
type,
transform,
useForSnippets,
preferForRegexpMatch
) {
if (transform === undefined) transform = s => s
if (useForSnippets === undefined) useForSnippets = true
if (preferForRegexpMatch === undefined) preferForRegexpMatch = false
this._name = name
this._regexps = stringArray(regexps)
this._type = type
this._transform = transform
this._useForSnippets = useForSnippets
this._preferForRegexpMatch = preferForRegexpMatch
}
get name() {
return this._name
}
get regexps() {
return this._regexps
}
get type() {
return this._type
}
get preferForRegexpMatch() {
return this._preferForRegexpMatch
}
get useForSnippets() {
return this._useForSnippets
}
transform(thisObj, groupValues) {
return this._transform.apply(thisObj, groupValues)
}
}
function stringArray(regexps) {
const array = Array.isArray(regexps) ? regexps : [regexps]
return array.map(r => (typeof r === 'string' ? r : regexpSource(r)))
}
function regexpSource(regexp) {
const flags = regexpFlags(regexp)
for (const flag of ['g', 'i', 'm', 'y']) {
if (flags.indexOf(flag) !== -1)
throw new CucumberExpressionError(
`ParameterType Regexps can't use flag '${flag}'`
)
}
return regexp.source
}
// Backport RegExp.flags for Node 4.x
// https://github.com/nodejs/node/issues/8390
//
// For some strange reason this is not needed for
// `./mocha dist/test`, but it is needed for
// `./mocha dist/test/parameter_type_test.js`
function regexpFlags(regexp) {
let flags = regexp.flags
if (flags === undefined) {
flags = ''
if (regexp.ignoreCase) flags += 'i'
if (regexp.global) flags += 'g'
if (regexp.multiline) flags += 'm'
}
return flags
}
module.exports = ParameterType

View File

@@ -0,0 +1,46 @@
class ParameterTypeMatcher {
constructor(parameter, regexp, text, matchPosition) {
this._parameterType = parameter
this._treeRegexp = regexp
this._text = text
this._matchPosition = matchPosition || 0
const captureGroupRegexp = new RegExp(`(${regexp})`)
this._match = captureGroupRegexp.exec(text.slice(this._matchPosition))
}
get parameterType() {
return this._parameterType
}
advanceTo(newMatchPosition) {
return new ParameterTypeMatcher(
this._parameterType,
this._treeRegexp,
this._text,
newMatchPosition
)
}
get find() {
return this._match && this.group !== ''
}
get start() {
return this._matchPosition + this._match.index
}
get group() {
return this._match[0]
}
static compare(a, b) {
const posComparison = a.start - b.start
if (posComparison !== 0) return posComparison
const lengthComparison = b.group.length - a.group.length
if (lengthComparison !== 0) return lengthComparison
return 0
}
}
module.exports = ParameterTypeMatcher

View File

@@ -0,0 +1,105 @@
const ParameterType = require('./parameter_type')
const CucumberExpressionGenerator = require('./cucumber_expression_generator.js')
const {
CucumberExpressionError,
AmbiguousParameterTypeError,
} = require('./errors')
const INTEGER_REGEXPS = [/-?\d+/, /\d+/]
const FLOAT_REGEXP = /-?\d*\.\d+/
const WORD_REGEXP = /\w+/
const STRING_REGEXP = /"([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)'/
class ParameterTypeRegistry {
constructor() {
this._parameterTypeByName = new Map()
this._parameterTypesByRegexp = new Map()
this.defineParameterType(
new ParameterType('int', INTEGER_REGEXPS, Number, parseInt, true, true)
)
this.defineParameterType(
new ParameterType('float', FLOAT_REGEXP, Number, parseFloat, true, false)
)
this.defineParameterType(
new ParameterType('word', WORD_REGEXP, String, s => s, false, false)
)
this.defineParameterType(
new ParameterType(
'string',
STRING_REGEXP,
String,
s => s.replace(/\\"/g, '"').replace(/\\'/g, "'"),
true,
false
)
)
}
get parameterTypes() {
return this._parameterTypeByName.values()
}
lookupByTypeName(typeName) {
return this._parameterTypeByName.get(typeName)
}
lookupByRegexp(parameterTypeRegexp, expressionRegexp, text) {
const parameterTypes = this._parameterTypesByRegexp.get(parameterTypeRegexp)
if (!parameterTypes) return null
if (parameterTypes.length > 1 && !parameterTypes[0].preferForRegexpMatch) {
// We don't do this check on insertion because we only want to restrict
// ambiguiuty when we look up by Regexp. Users of CucumberExpression should
// not be restricted.
const generatedExpressions = new CucumberExpressionGenerator(
this
).generateExpressions(text)
throw new AmbiguousParameterTypeError.forRegExp(
parameterTypeRegexp,
expressionRegexp,
parameterTypes,
generatedExpressions
)
}
return parameterTypes[0]
}
defineParameterType(parameterType) {
if (this._parameterTypeByName.has(parameterType.name))
throw new Error(
`There is already a parameter type with name ${parameterType.name}`
)
this._parameterTypeByName.set(parameterType.name, parameterType)
for (const parameterTypeRegexp of parameterType.regexps) {
if (!this._parameterTypesByRegexp.has(parameterTypeRegexp)) {
this._parameterTypesByRegexp.set(parameterTypeRegexp, [])
}
const parameterTypes = this._parameterTypesByRegexp.get(
parameterTypeRegexp
)
const existingParameterType = parameterTypes[0]
if (
parameterTypes.length > 0 &&
existingParameterType.preferForRegexpMatch &&
parameterType.preferForRegexpMatch
) {
throw new CucumberExpressionError(
'There can only be one preferential parameter type per regexp. ' +
`The regexp /${parameterTypeRegexp}/ is used for two preferential parameter types, {${
existingParameterType.name
}} and {${parameterType.name}}`
)
}
if (parameterTypes.indexOf(parameterType) === -1) {
parameterTypes.push(parameterType)
this._parameterTypesByRegexp.set(
parameterTypeRegexp,
parameterTypes.sort(ParameterType.compare)
)
}
}
}
}
module.exports = ParameterTypeRegistry

View File

@@ -0,0 +1,47 @@
const Argument = require('./argument')
const TreeRegexp = require('./tree_regexp')
const ParameterType = require('./parameter_type')
class RegularExpression {
constructor(expressionRegexp, parameterTypeRegistry) {
this._expressionRegexp = expressionRegexp
this._parameterTypeRegistry = parameterTypeRegistry
this._treeRegexp = new TreeRegexp(expressionRegexp)
}
match(text) {
const parameterTypes = this._treeRegexp.groupBuilder.children.map(
groupBuilder => {
const parameterTypeRegexp = groupBuilder.source
return (
this._parameterTypeRegistry.lookupByRegexp(
parameterTypeRegexp,
this._treeRegexp,
text
) ||
new ParameterType(
parameterTypeRegexp,
parameterTypeRegexp,
String,
s => s,
false,
false
)
)
}
)
return Argument.build(this._treeRegexp, text, parameterTypes)
}
get regexp() {
return this._expressionRegexp
}
get source() {
return this._expressionRegexp.source
}
}
module.exports = RegularExpression

View File

@@ -0,0 +1,58 @@
const Regex = require('becke-ch--regex--s0-0-v1--base--pl--lib')
const GroupBuilder = require('./group_builder')
class TreeRegexp {
constructor(regexp) {
this._re = 'string' === typeof regexp ? new RegExp(regexp) : regexp
this._regex = new Regex(this._re.source, this._re.flags)
const stack = [new GroupBuilder()]
const groupStartStack = []
let last = null
let escaping = false
let nonCapturingMaybe = false
this._re.source.split('').forEach((c, n) => {
if (c === '(' && !escaping) {
stack.push(new GroupBuilder())
groupStartStack.push(n + 1)
nonCapturingMaybe = false
} else if (c === ')' && !escaping) {
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)
} else {
gb.moveChildrenTo(stack[stack.length - 1])
}
nonCapturingMaybe = false
} else if (c === '?' && last === '(') {
nonCapturingMaybe = true
} else if (c === ':' && nonCapturingMaybe) {
stack[stack.length - 1].setNonCapturing()
nonCapturingMaybe = false
}
escaping = c === '\\' && !escaping
last = c
})
this._groupBuilder = stack.pop()
}
get regexp() {
return this._re
}
get groupBuilder() {
return this._groupBuilder
}
match(s) {
const match = this._regex.exec(s)
if (!match) return null
let groupIndex = 0
const nextGroupIndex = () => groupIndex++
return this._groupBuilder.build(match, nextGroupIndex)
}
}
module.exports = TreeRegexp

View File

@@ -0,0 +1,7 @@
const assert = require('assert')
// A better assert.error that allows an exact error message
module.exports = (fn, message) => {
const regexp = new RegExp(message.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'))
assert.throws(fn, regexp)
}

View File

@@ -0,0 +1,69 @@
/* eslint-env mocha */
const assert = require('assert')
const ParameterType = require('../src/parameter_type')
const CombinatorialGeneratedExpressionFactory = require('../src/combinatorial_generated_expression_factory')
describe('CucumberExpressionGenerator', () => {
it('generates multiple expressions', () => {
const parameterTypeCombinations = [
[
new ParameterType(
'color',
/red|blue|yellow/,
null,
s => s,
false,
true
),
new ParameterType(
'csscolor',
/red|blue|yellow/,
null,
s => s,
false,
true
),
],
[
new ParameterType(
'date',
/\d{4}-\d{2}-\d{2}/,
null,
s => s,
false,
true
),
new ParameterType(
'datetime',
/\d{4}-\d{2}-\d{2}/,
null,
s => s,
false,
true
),
new ParameterType(
'timestamp',
/\d{4}-\d{2}-\d{2}/,
null,
s => s,
false,
true
),
],
]
const factory = new CombinatorialGeneratedExpressionFactory(
'I bought a {%s} ball on {%s}',
parameterTypeCombinations
)
const expressions = factory.generateExpressions().map(ge => ge.source)
assert.deepEqual(expressions, [
'I bought a {color} ball on {date}',
'I bought a {color} ball on {datetime}',
'I bought a {color} ball on {timestamp}',
'I bought a {csscolor} ball on {date}',
'I bought a {csscolor} ball on {datetime}',
'I bought a {csscolor} ball on {timestamp}',
])
})
})

View File

@@ -0,0 +1,215 @@
/* eslint-env mocha */
const assert = require('assert')
const CucumberExpressionGenerator = require('../src/cucumber_expression_generator')
const CucumberExpression = require('../src/cucumber_expression')
const ParameterType = require('../src/parameter_type')
const ParameterTypeRegistry = require('../src/parameter_type_registry')
class Currency {}
describe('CucumberExpressionGenerator', () => {
let parameterTypeRegistry, generator
function assertExpression(expectedExpression, expectedArgumentNames, text) {
const generatedExpression = generator.generateExpressions(text)[0]
assert.deepEqual(generatedExpression.parameterNames, expectedArgumentNames)
assert.equal(generatedExpression.source, expectedExpression)
const cucumberExpression = new CucumberExpression(
generatedExpression.source,
parameterTypeRegistry
)
const match = cucumberExpression.match(text)
if (match === null) {
assert.fail(
`Expected text '${text}' to match generated expression '${
generatedExpression.source
}'`
)
}
assert.equal(match.length, expectedArgumentNames.length)
}
beforeEach(() => {
parameterTypeRegistry = new ParameterTypeRegistry()
generator = new CucumberExpressionGenerator(parameterTypeRegistry)
})
it('documents expression generation', () => {
const parameterRegistry = new ParameterTypeRegistry()
/// [generate-expression]
const generator = new CucumberExpressionGenerator(parameterRegistry)
const undefinedStepText = 'I have 2 cucumbers and 1.5 tomato'
const generatedExpression = generator.generateExpressions(
undefinedStepText
)[0]
assert.equal(
generatedExpression.source,
'I have {int} cucumbers and {float} tomato'
)
assert.equal(generatedExpression.parameterNames[0], 'int')
assert.equal(generatedExpression.parameterTypes[1].name, 'float')
/// [generate-expression]
})
it('generates expression for no args', () => {
assertExpression('hello', [], 'hello')
})
it('generates expression with escaped left parenthesis', () => {
assertExpression('\\(iii)', [], '(iii)')
})
it('generates expression with escaped left curly brace', () => {
assertExpression('\\{iii}', [], '{iii}')
})
it('generates expression with escaped slashes', () => {
assertExpression(
'The {int}\\/{int}\\/{int} hey',
['int', 'int2', 'int3'],
'The 1814/05/17 hey'
)
})
it('generates expression for int float arg', () => {
assertExpression(
'I have {int} cukes and {float} euro',
['int', 'float'],
'I have 2 cukes and 1.5 euro'
)
})
it('generates expression for strings', () => {
assertExpression(
'I like {string} and {string}',
['string', 'string2'],
'I like "bangers" and \'mash\''
)
})
it('generates expression with % sign', () => {
assertExpression('I am {int}%% foobar', ['int'], 'I am 20%% foobar')
})
it('generates expression for just int', () => {
assertExpression('{int}', ['int'], '99999')
})
it('numbers only second argument when builtin type is not reserved keyword', () => {
assertExpression(
'I have {float} cukes and {float} euro',
['float', 'float2'],
'I have 2.5 cukes and 1.5 euro'
)
})
it('generates expression for custom type', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'currency',
/[A-Z]{3}/,
Currency,
s => new Currency(s),
true,
false
)
)
assertExpression(
'I have a {currency} account',
['currency'],
'I have a EUR account'
)
})
it('prefers leftmost match when there is overlap', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'currency',
/cd/,
Currency,
s => new Currency(s),
true,
false
)
)
parameterTypeRegistry.defineParameterType(
new ParameterType('date', /bc/, Date, s => new Date(s), true, false)
)
assertExpression('a{date}defg', ['date'], 'abcdefg')
})
// TODO: prefers widest match
it('generates all combinations of expressions when several parameter types match', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'currency',
/x/,
null,
s => new Currency(s),
true,
false
)
)
parameterTypeRegistry.defineParameterType(
new ParameterType('date', /x/, null, s => new Date(s), true, false)
)
const generatedExpressions = generator.generateExpressions(
'I have x and x and another x'
)
const expressions = generatedExpressions.map(e => e.source)
assert.deepEqual(expressions, [
'I have {currency} and {currency} and another {currency}',
'I have {currency} and {currency} and another {date}',
'I have {currency} and {date} and another {currency}',
'I have {currency} and {date} and another {date}',
'I have {date} and {currency} and another {currency}',
'I have {date} and {currency} and another {date}',
'I have {date} and {date} and another {currency}',
'I have {date} and {date} and another {date}',
])
})
it('exposes parameter type names in generated expression', () => {
const expression = generator.generateExpressions(
'I have 2 cukes and 1.5 euro'
)[0]
const typeNames = expression.parameterTypes.map(parameter => parameter.name)
assert.deepEqual(typeNames, ['int', 'float'])
})
it('ignores parameter types with optional capture groups', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'optional-flight',
/(1st flight)?/,
null,
s => s,
true,
false
)
)
parameterTypeRegistry.defineParameterType(
new ParameterType(
'optional-hotel',
/(1st hotel)?/,
null,
s => s,
true,
false
)
)
const expression = generator.generateExpressions(
'I reach Stage4: 1st flight-1st hotl'
)[0]
assert.equal(
expression.source,
'I reach Stage{int}: {int}st flight{int}st hotl'
)
})
})

View File

@@ -0,0 +1,48 @@
/* eslint-env mocha */
const assert = require('assert')
const CucumberExpression = require('../src/cucumber_expression')
const ParameterTypeRegistry = require('../src/parameter_type_registry')
describe('CucumberExpression', () => {
describe('RegExp translation', () => {
it('translates no arguments', () => {
assertRegexp(
'I have 10 cukes in my belly now',
/^I have 10 cukes in my belly now$/
)
})
it('translates alternation', () => {
assertRegexp(
'I had/have a great/nice/charming friend',
/^I (?:had|have) a (?:great|nice|charming) friend$/
)
})
it('translates alternation with non-alpha', () => {
assertRegexp('I said Alpha1/Beta1', /^I said (?:Alpha1|Beta1)$/)
})
it('translates parameters', () => {
assertRegexp(
"I have {float} cukes at {int} o'clock",
/^I have (-?\d*\.\d+) cukes at ((?:-?\d+)|(?:\d+)) o'clock$/
)
})
it('translates parenthesis to non-capturing optional capture group', () => {
assertRegexp(
'I have many big(ish) cukes',
/^I have many big(?:ish)? cukes$/
)
})
})
})
const assertRegexp = (expression, expectedRegexp) => {
const cucumberExpression = new CucumberExpression(
expression,
new ParameterTypeRegistry()
)
assert.deepEqual(cucumberExpression.regexp, expectedRegexp)
}

View File

@@ -0,0 +1,212 @@
/* eslint-env mocha */
const assert = require('assert')
const {
CucumberExpression,
ParameterTypeRegistry,
ParameterType,
} = require('../src/index')
describe('CucumberExpression', () => {
it('documents match arguments', () => {
const parameterTypeRegistry = new ParameterTypeRegistry()
/// [capture-match-arguments]
const expr = 'I have {int} cuke(s)'
const expression = new CucumberExpression(expr, parameterTypeRegistry)
const args = expression.match('I have 7 cukes')
assert.equal(7, args[0].getValue(null))
/// [capture-match-arguments]
})
it('matches word', () => {
assert.deepEqual(match('three {word} mice', 'three blind mice'), ['blind'])
})
it('matches double quoted string', () => {
assert.deepEqual(match('three {string} mice', 'three "blind" mice'), [
'blind',
])
})
it('matches multiple double quoted strings', () => {
assert.deepEqual(
match(
'three {string} and {string} mice',
'three "blind" and "crippled" mice'
),
['blind', 'crippled']
)
})
it('matches single quoted string', () => {
assert.deepEqual(match('three {string} mice', "three 'blind' mice"), [
'blind',
])
})
it('matches multiple single quoted strings', () => {
assert.deepEqual(
match(
'three {string} and {string} mice',
"three 'blind' and 'crippled' mice"
),
['blind', 'crippled']
)
})
it('does not match misquoted string', () => {
assert.deepEqual(match('three {string} mice', 'three "blind\' mice'), null)
})
it('matches single quoted string with double quotes', () => {
assert.deepEqual(match('three {string} mice', 'three \'"blind"\' mice'), [
'"blind"',
])
})
it('matches double quoted string with single quotes', () => {
assert.deepEqual(match('three {string} mice', 'three "\'blind\'" mice'), [
"'blind'",
])
})
it('matches double quoted string with escaped double quote', () => {
assert.deepEqual(match('three {string} mice', 'three "bl\\"nd" mice'), [
'bl"nd',
])
})
it('matches single quoted string with escaped single quote', () => {
assert.deepEqual(match('three {string} mice', "three 'bl\\'nd' mice"), [
"bl'nd",
])
})
it('matches single quoted string with escaped single quote', () => {
assert.deepEqual(match('three {string} mice', "three 'bl\\'nd' mice"), [
"bl'nd",
])
})
it('matches escaped parenthesis', () => {
assert.deepEqual(
match(
'three \\(exceptionally) {string} mice',
'three (exceptionally) "blind" mice'
),
['blind']
)
})
it('matches escaped slash', () => {
assert.deepEqual(match('12\\/2020', '12/2020'), [])
})
it('matches int', () => {
assert.deepEqual(match('{int}', '22'), [22])
})
it("doesn't match float as int", () => {
assert.deepEqual(match('{int}', '1.22'), null)
})
it('matches float', () => {
assert.deepEqual(match('{float}', '0.22'), [0.22])
assert.deepEqual(match('{float}', '.22'), [0.22])
})
it('throws unknown parameter type', () => {
try {
match('{unknown}', 'something')
assert.fail()
} catch (expected) {
assert.equal(expected.message, 'Undefined parameter type {unknown}')
}
})
it('exposes source', () => {
const expr = 'I have {int} cuke(s)'
assert.equal(
new CucumberExpression(expr, new ParameterTypeRegistry()).source,
expr
)
})
// JavaScript-specific
it('delegates transform to custom object', () => {
const parameterTypeRegistry = new ParameterTypeRegistry()
parameterTypeRegistry.defineParameterType(
new ParameterType(
'widget',
/\w+/,
null,
function(s) {
return this.createWidget(s)
},
false,
true
)
)
const expression = new CucumberExpression(
'I have a {widget}',
parameterTypeRegistry
)
const world = {
createWidget(s) {
return `widget:${s}`
},
}
const args = expression.match(`I have a bolt`)
assert.equal(args[0].getValue(world), 'widget:bolt')
})
describe('escapes special characters', () => {
;['\\', '[', ']', '^', '$', '.', '|', '?', '*', '+'].forEach(character => {
it(`escapes ${character}`, () => {
const expr = `I have {int} cuke(s) and ${character}`
const expression = new CucumberExpression(
expr,
new ParameterTypeRegistry()
)
const arg1 = expression.match(`I have 800 cukes and ${character}`)[0]
assert.equal(arg1.getValue(null), 800)
})
})
it(`escapes .`, () => {
const expr = `I have {int} cuke(s) and .`
const expression = new CucumberExpression(
expr,
new ParameterTypeRegistry()
)
assert.equal(expression.match(`I have 800 cukes and 3`), null)
const arg1 = expression.match(`I have 800 cukes and .`)[0]
assert.equal(arg1.getValue(null), 800)
})
it(`escapes |`, () => {
const expr = `I have {int} cuke(s) and a|b`
const expression = new CucumberExpression(
expr,
new ParameterTypeRegistry()
)
assert.equal(expression.match(`I have 800 cukes and a`), null)
assert.equal(expression.match(`I have 800 cukes and b`), null)
const arg1 = expression.match(`I have 800 cukes and a|b`)[0]
assert.equal(arg1.getValue(null), 800)
})
})
})
const match = (expression, text) => {
const cucumberExpression = new CucumberExpression(
expression,
new ParameterTypeRegistry()
)
const args = cucumberExpression.match(text)
if (!args) return null
return args.map(arg => arg.getValue(null))
}

View File

@@ -0,0 +1,251 @@
/* eslint-env mocha */
'use strict'
const assert = require('assert')
const assertThrows = require('./assert_throws')
const CucumberExpression = require('../src/cucumber_expression')
const RegularExpression = require('../src/regular_expression')
const ParameterTypeRegistry = require('../src/parameter_type_registry')
const ParameterType = require('../src/parameter_type')
require('babel-polyfill')
class Color {
/// [color-constructor]
constructor(name) {
this.name = name
}
/// [color-constructor]
}
class CssColor {
constructor(name) {
this.name = name
}
}
describe('Custom parameter type', () => {
let parameterTypeRegistry
beforeEach(() => {
parameterTypeRegistry = new ParameterTypeRegistry()
/* eslint-disable prettier/prettier */
/// [add-color-parameter-type]
parameterTypeRegistry.defineParameterType(
new ParameterType(
'color', // name
/red|blue|yellow/, // regexp
Color, // type
s => new Color(s), // transformer
false, // useForSnippets
true // preferForRegexpMatch
)
)
/// [add-color-parameter-type]
/* eslint-enable prettier/prettier */
})
describe('CucumberExpression', () => {
it('matches parameters with custom parameter type', () => {
const expression = new CucumberExpression(
'I have a {color} ball',
parameterTypeRegistry
)
const value = expression.match('I have a red ball')[0].getValue(null)
assert.equal(value.name, 'red')
})
it('matches parameters with multiple capture groups', () => {
class Coordinate {
constructor(x, y, z) {
this.x = x
this.y = y
this.z = z
}
}
parameterTypeRegistry.defineParameterType(
new ParameterType(
'coordinate',
/(\d+),\s*(\d+),\s*(\d+)/,
Coordinate,
(x, y, z) => new Coordinate(parseInt(x), parseInt(y), parseInt(z)),
true,
true
)
)
const expression = new CucumberExpression(
'A {int} thick line from {coordinate} to {coordinate}',
parameterTypeRegistry
)
const args = expression.match('A 5 thick line from 10,20,30 to 40,50,60')
const thick = args[0].getValue(null)
assert.equal(thick, 5)
const from = args[1].getValue(null)
assert.equal(from.x, 10)
assert.equal(from.y, 20)
assert.equal(from.z, 30)
const to = args[2].getValue(null)
assert.equal(to.x, 40)
assert.equal(to.y, 50)
assert.equal(to.z, 60)
})
it('matches parameters with custom parameter type using optional capture group', () => {
parameterTypeRegistry = new ParameterTypeRegistry()
parameterTypeRegistry.defineParameterType(
new ParameterType(
'color',
[/red|blue|yellow/, /(?:dark|light) (?:red|blue|yellow)/],
Color,
s => new Color(s),
false,
true
)
)
const expression = new CucumberExpression(
'I have a {color} ball',
parameterTypeRegistry
)
const value = expression.match('I have a dark red ball')[0].getValue(null)
assert.equal(value.name, 'dark red')
})
it('defers transformation until queried from argument', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'throwing',
/bad/,
null,
s => {
throw new Error(`Can't transform [${s}]`)
},
false,
true
)
)
const expression = new CucumberExpression(
'I have a {throwing} parameter',
parameterTypeRegistry
)
const args = expression.match('I have a bad parameter')
assertThrows(() => args[0].getValue(null), "Can't transform [bad]")
})
describe('conflicting parameter type', () => {
it('is detected for type name', () => {
assertThrows(
() =>
parameterTypeRegistry.defineParameterType(
new ParameterType(
'color',
/.*/,
CssColor,
s => new CssColor(s),
false,
true
)
),
'There is already a parameter type with name color'
)
})
it('is not detected for type', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'whatever',
/.*/,
Color,
s => new Color(s),
false,
true
)
)
})
it('is not detected for regexp', () => {
parameterTypeRegistry.defineParameterType(
new ParameterType(
'css-color',
/red|blue|yellow/,
CssColor,
s => new CssColor(s),
true,
false
)
)
assert.equal(
new CucumberExpression(
'I have a {css-color} ball',
parameterTypeRegistry
)
.match('I have a blue ball')[0]
.getValue(null).constructor,
CssColor
)
assert.equal(
new CucumberExpression(
'I have a {css-color} ball',
parameterTypeRegistry
)
.match('I have a blue ball')[0]
.getValue(null).name,
'blue'
)
assert.equal(
new CucumberExpression('I have a {color} ball', parameterTypeRegistry)
.match('I have a blue ball')[0]
.getValue(null).constructor,
Color
)
assert.equal(
new CucumberExpression('I have a {color} ball', parameterTypeRegistry)
.match('I have a blue ball')[0]
.getValue(null).name,
'blue'
)
})
})
// JavaScript-specific
it('creates arguments using async transform', async () => {
parameterTypeRegistry = new ParameterTypeRegistry()
/// [add-async-parameter-type]
parameterTypeRegistry.defineParameterType(
new ParameterType(
'asyncColor',
/red|blue|yellow/,
Color,
async s => new Color(s),
false,
true
)
)
/// [add-async-parameter-type]
const expression = new CucumberExpression(
'I have a {asyncColor} ball',
parameterTypeRegistry
)
const args = await expression.match('I have a red ball')
const value = await args[0].getValue(null)
assert.equal(value.name, 'red')
})
})
describe('RegularExpression', () => {
it('matches arguments with custom parameter type', () => {
const expression = new RegularExpression(
/I have a (red|blue|yellow) ball/,
parameterTypeRegistry
)
const value = expression.match('I have a red ball')[0].getValue(null)
assert.equal(value.constructor, Color)
assert.equal(value.name, 'red')
})
})
})

View File

@@ -0,0 +1,30 @@
/* eslint-env mocha */
const fs = require('fs')
const assert = require('assert')
const CucumberExpression = require('../src/cucumber_expression')
const RegularExpression = require('../src/regular_expression')
const ParameterTypeRegistry = require('../src/parameter_type_registry')
describe('examples.txt', () => {
const match = (expression_text, text) => {
const m = /\/(.*)\//.exec(expression_text)
const expression = m
? new RegularExpression(new RegExp(m[1]), new ParameterTypeRegistry())
: new CucumberExpression(expression_text, new ParameterTypeRegistry())
const args = expression.match(text)
if (!args) return null
return args.map(arg => arg.getValue(null))
}
const examples = fs.readFileSync('examples.txt', 'utf-8')
const chunks = examples.split(/^---/m)
for (const chunk of chunks) {
const [expressionText, text, expectedArgs] = chunk.trim().split(/\n/m)
it(`Works with: ${expressionText}`, () => {
assert.deepEqual(
JSON.stringify(match(expressionText, text)),
expectedArgs
)
})
}
})

View File

@@ -0,0 +1,99 @@
/* eslint-env mocha */
const assert = require('assert')
const ParameterTypeRegistry = require('../src/parameter_type_registry')
const ParameterType = require('../src/parameter_type')
class Name {}
class Person {}
class Place {}
const CAPITALISED_WORD = /[A-Z]+\w+/
describe('ParameterTypeRegistry', () => {
let registry
beforeEach(() => {
registry = new ParameterTypeRegistry()
})
it('does not allow more than one preferential parameter type for each regexp', () => {
registry.defineParameterType(
new ParameterType(
'name',
CAPITALISED_WORD,
Name,
s => new Name(s),
true,
true
)
)
registry.defineParameterType(
new ParameterType(
'person',
CAPITALISED_WORD,
Person,
s => new Person(s),
true,
false
)
)
try {
registry.defineParameterType(
new ParameterType(
'place',
CAPITALISED_WORD,
Place,
s => new Place(s),
true,
true
)
)
throw new Error('Should have failed')
} catch (err) {
assert.equal(
err.message,
`There can only be one preferential parameter type per regexp. The regexp ${CAPITALISED_WORD} is used for two preferential parameter types, {name} and {place}`
)
}
})
it('looks up preferential parameter type by regexp', () => {
const name = new ParameterType(
'name',
/[A-Z]+\w+/,
null,
s => new Name(s),
true,
false
)
const person = new ParameterType(
'person',
/[A-Z]+\w+/,
null,
s => new Person(s),
true,
true
)
const place = new ParameterType(
'place',
/[A-Z]+\w+/,
null,
s => new Place(s),
true,
false
)
registry.defineParameterType(name)
registry.defineParameterType(person)
registry.defineParameterType(place)
assert.equal(
registry.lookupByRegexp(
'[A-Z]+\\w+',
/([A-Z]+\w+) and ([A-Z]+\w+)/,
'Lisa and Bob'
),
person
)
})
})

View File

@@ -0,0 +1,20 @@
/* eslint-env mocha */
const assertThrows = require('./assert_throws')
const ParameterType = require('../src/parameter_type')
describe('ParameterType', () => {
it('does not allow ignore flag on regexp', () => {
assertThrows(
() =>
new ParameterType(
'case-insensitive',
/[a-z]+/i,
String,
s => s,
true,
true
),
"ParameterType Regexps can't use flag 'i'"
)
})
})

View File

@@ -0,0 +1,79 @@
/* eslint-env mocha */
const assert = require('assert')
const RegularExpression = require('../src/regular_expression')
const ParameterTypeRegistry = require('../src/parameter_type_registry')
describe('RegularExpression', () => {
it('documents match arguments', () => {
const parameterRegistry = new ParameterTypeRegistry()
/// [capture-match-arguments]
const expr = /I have (\d+) cukes? in my (\w+) now/
const expression = new RegularExpression(expr, parameterRegistry)
const args = expression.match('I have 7 cukes in my belly now')
assert.equal(7, args[0].getValue(null))
assert.equal('belly', args[1].getValue(null))
/// [capture-match-arguments]
})
it('does no transform by default', () => {
assert.deepEqual(match(/(\d\d)/, '22')[0], '22')
})
it('transforms negative int', () => {
assert.deepEqual(match(/(-?\d+)/, '-22')[0], -22)
})
it('transforms positive int', () => {
assert.deepEqual(match(/(\d+)/, '22')[0], 22)
})
it('transforms float without integer part', () => {
assert.deepEqual(match(/(-?\d*\.?\d+)/, '.22')[0], 0.22)
})
it('transforms float with sign', () => {
assert.deepEqual(match(/(-?\d*\.?\d+)/, '-1.22')[0], -1.22)
})
it('returns null when there is no match', () => {
assert.equal(match(/hello/, 'world'), null)
})
it('matches nested capture group without match', () => {
assert.deepEqual(match(/^a user( named "([^"]*)")?$/, 'a user'), [null])
})
it('matches nested capture group with match', () => {
assert.deepEqual(match(/^a user( named "([^"]*)")?$/, 'a user named "Charlie"'), ['Charlie'])
})
it('ignores non capturing groups', () => {
assert.deepEqual(
match(
/(\S+) ?(can|cannot)? (?:delete|cancel) the (\d+)(?:st|nd|rd|th) (attachment|slide) ?(?:upload)?/,
'I can cancel the 1st slide upload'
),
['I', 'can', 1, 'slide']
)
})
it('works with escaped parenthesis', () => {
assert.deepEqual(match(/Across the line\(s\)/, 'Across the line(s)'), [])
})
it('exposes regexp and source', () => {
const regexp = /I have (\d+) cukes? in my (.+) now/
let expression = new RegularExpression(regexp, new ParameterTypeRegistry())
assert.deepEqual(expression.regexp, regexp)
assert.deepEqual(expression.source, regexp.source)
})
})
const match = (regexp, text) => {
const parameterRegistry = new ParameterTypeRegistry()
const regularExpression = new RegularExpression(regexp, parameterRegistry)
const args = regularExpression.match(text)
if (!args) return null
return args.map(arg => arg.getValue(null))
}

View File

@@ -0,0 +1,92 @@
/* eslint-env mocha */
const assert = require('assert')
const TreeRegexp = require('../src/tree_regexp')
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', () => {
const tr = new TreeRegexp(/(a(?:b)?)(c)/)
const group = tr.match('ac')
assert.equal(group.value, 'ac')
assert.equal(group.children[0].value, 'a')
assert.deepEqual(group.children[0].children, [])
assert.equal(group.children[1].value, 'c')
})
it('ignores non-capturing groups', () => {
const tr = new TreeRegexp(/(a(?:b)?)(c)/)
const group = tr.match('ac')
assert.equal(group.value, 'ac')
assert.equal(group.children[0].value, 'a')
assert.deepEqual(group.children[0].children, [])
assert.equal(group.children[1].value, 'c')
})
it('matches optional group', () => {
const tr = new TreeRegexp(/^Something( with an optional argument)?/)
const group = tr.match('Something')
assert.equal(group.children[0].value, null)
})
it('matches nested groups', () => {
const tr = new TreeRegexp(
/^A (\d+) thick line from ((\d+),\s*(\d+),\s*(\d+)) to ((\d+),\s*(\d+),\s*(\d+))/
)
const group = tr.match('A 5 thick line from 10,20,30 to 40,50,60')
assert.equal(group.children[0].value, '5')
assert.equal(group.children[1].value, '10,20,30')
assert.equal(group.children[1].children[0].value, '10')
assert.equal(group.children[1].children[1].value, '20')
assert.equal(group.children[1].children[2].value, '30')
assert.equal(group.children[2].value, '40,50,60')
assert.equal(group.children[2].children[0].value, '40')
assert.equal(group.children[2].children[1].value, '50')
assert.equal(group.children[2].children[2].value, '60')
})
it('detects multiple non capturing groups', () => {
const tr = new TreeRegexp(/(?:a)(:b)(\?c)(d)/)
const group = tr.match('a:b?cd')
assert.equal(group.children.length, 3)
})
it('works with escaped backslash', () => {
const tr = new TreeRegexp(/foo\\(bar|baz)/)
const group = tr.match('foo\\bar')
assert.equal(group.children.length, 1)
})
it('works with escaped slash', () => {
const tr = new TreeRegexp(/^I go to '\/(.+)'$/)
const group = tr.match("I go to '/hello'")
assert.equal(group.children.length, 1)
})
it('works with digit and word', () => {
const tr = new TreeRegexp(/^(\d) (\w+)$/)
const group = tr.match('2 you')
assert.equal(group.children.length, 2)
})
it('captures non capturing groups with capturing groups inside', () => {
const tr = new TreeRegexp('the stdout(?: from "(.*?)")?')
const group = tr.match('the stdout')
assert.equal(group.value, 'the stdout')
assert.equal(group.children[0].value, null)
assert.equal(group.children.length, 1)
})
it('works with flags', () => {
const tr = new TreeRegexp(/HELLO/i)
const group = tr.match('hello')
assert.equal(group.value, 'hello')
})
})

File diff suppressed because it is too large Load Diff

147
node_modules/cucumber/node_modules/figures/index.js generated vendored Normal file
View File

@@ -0,0 +1,147 @@
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
const platform = process.platform;
const main = {
tick: '✔',
cross: '✖',
star: '★',
square: '▇',
squareSmall: '◻',
squareSmallFilled: '◼',
play: '▶',
circle: '◯',
circleFilled: '◉',
circleDotted: '◌',
circleDouble: '◎',
circleCircle: 'ⓞ',
circleCross: 'ⓧ',
circlePipe: 'Ⓘ',
circleQuestionMark: '?⃝',
bullet: '●',
dot: '',
line: '─',
ellipsis: '…',
pointer: '',
pointerSmall: '',
info: '',
warning: '⚠',
hamburger: '☰',
smiley: '㋡',
mustache: '෴',
heart: '♥',
arrowUp: '↑',
arrowDown: '↓',
arrowLeft: '←',
arrowRight: '→',
radioOn: '◉',
radioOff: '◯',
checkboxOn: '☒',
checkboxOff: '☐',
checkboxCircleOn: 'ⓧ',
checkboxCircleOff: 'Ⓘ',
questionMarkPrefix: '?⃝',
oneHalf: '½',
oneThird: '⅓',
oneQuarter: '¼',
oneFifth: '⅕',
oneSixth: '⅙',
oneSeventh: '⅐',
oneEighth: '⅛',
oneNinth: '⅑',
oneTenth: '⅒',
twoThirds: '⅔',
twoFifths: '⅖',
threeQuarters: '¾',
threeFifths: '⅗',
threeEighths: '⅜',
fourFifths: '⅘',
fiveSixths: '⅚',
fiveEighths: '⅝',
sevenEighths: '⅞'
};
const win = {
tick: '√',
cross: '×',
star: '*',
square: '█',
squareSmall: '[ ]',
squareSmallFilled: '[█]',
play: '►',
circle: '( )',
circleFilled: '(*)',
circleDotted: '( )',
circleDouble: '( )',
circleCircle: '(○)',
circleCross: '(×)',
circlePipe: '(│)',
circleQuestionMark: '(?)',
bullet: '*',
dot: '.',
line: '─',
ellipsis: '...',
pointer: '>',
pointerSmall: '»',
info: 'i',
warning: '‼',
hamburger: '≡',
smiley: '☺',
mustache: '┌─┐',
heart: main.heart,
arrowUp: main.arrowUp,
arrowDown: main.arrowDown,
arrowLeft: main.arrowLeft,
arrowRight: main.arrowRight,
radioOn: '(*)',
radioOff: '( )',
checkboxOn: '[×]',
checkboxOff: '[ ]',
checkboxCircleOn: '(×)',
checkboxCircleOff: '( )',
questionMarkPrefix: '',
oneHalf: '1/2',
oneThird: '1/3',
oneQuarter: '1/4',
oneFifth: '1/5',
oneSixth: '1/6',
oneSeventh: '1/7',
oneEighth: '1/8',
oneNinth: '1/9',
oneTenth: '1/10',
twoThirds: '2/3',
twoFifths: '2/5',
threeQuarters: '3/4',
threeFifths: '3/5',
threeEighths: '3/8',
fourFifths: '4/5',
fiveSixths: '5/6',
fiveEighths: '5/8',
sevenEighths: '7/8'
};
if (platform === 'linux') {
// the main one doesn't look that good on Ubuntu
main.questionMarkPrefix = '?';
}
const figures = platform === 'win32' ? win : main;
const fn = str => {
if (figures === main) {
return str;
}
Object.keys(main).forEach(key => {
if (main[key] === figures[key]) {
return;
}
str = str.replace(new RegExp(escapeStringRegexp(main[key]), 'g'), figures[key]);
});
return str;
};
module.exports = Object.assign(fn, figures);

21
node_modules/cucumber/node_modules/figures/license generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,79 @@
{
"_from": "figures@2.0.0",
"_id": "figures@2.0.0",
"_inBundle": false,
"_integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=",
"_location": "/cucumber/figures",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "figures@2.0.0",
"name": "figures",
"escapedName": "figures",
"rawSpec": "2.0.0",
"saveSpec": null,
"fetchSpec": "2.0.0"
},
"_requiredBy": [
"/cucumber"
],
"_resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
"_shasum": "3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962",
"_spec": "figures@2.0.0",
"_where": "/home/simon/Documents/lifen-autotest/node_modules/cucumber",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/figures/issues"
},
"bundleDependencies": false,
"dependencies": {
"escape-string-regexp": "^1.0.5"
},
"deprecated": false,
"description": "Unicode symbols with Windows CMD fallbacks",
"devDependencies": {
"ava": "*",
"markdown-table": "^1.0.0",
"require-uncached": "^1.0.2",
"xo": "*"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"homepage": "https://github.com/sindresorhus/figures#readme",
"keywords": [
"unicode",
"cli",
"cmd",
"command-line",
"characters",
"char",
"symbol",
"symbols",
"figure",
"figures",
"fallback"
],
"license": "MIT",
"name": "figures",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/figures.git"
},
"scripts": {
"make": "./makefile.js",
"test": "xo && ava"
},
"version": "2.0.0",
"xo": {
"esnext": true
}
}

120
node_modules/cucumber/node_modules/figures/readme.md generated vendored Normal file
View File

@@ -0,0 +1,120 @@
# figures [![Build Status: Linux](https://travis-ci.org/sindresorhus/figures.svg?branch=master)](https://travis-ci.org/sindresorhus/figures) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/mb743hl70269be3r/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/figures/branch/master)
> Unicode symbols with Windows CMD fallbacks
[![](screenshot.png)](index.js)
[*and more...*](index.js)
Windows CMD only supports a [limited character set](http://en.wikipedia.org/wiki/Code_page_437).
## Install
```
$ npm install --save figures
```
## Usage
See the [source](index.js) for supported symbols.
```js
const figures = require('figures');
console.log(figures('✔︎ check'));
// On real OSes: ✔︎ check
// On Windows: √ check
console.log(figures.tick);
// On real OSes: ✔︎
// On Windows: √
```
## API
### figures(input)
Returns the input with replaced fallback unicode symbols on Windows.
All the below [figures](#figures) are attached to the main export as shown in the example above.
#### input
Type: `string`
String where the unicode symbols will be replaced with fallback symbols depending on the OS.
## Figures
| Name | Real OSes | Windows |
| ------------------ | :-------: | :-----: |
| tick | ✔ | √ |
| cross | ✖ | × |
| star | ★ | * |
| square | ▇ | █ |
| squareSmall | ◻ | [ ] |
| squareSmallFilled | ◼ | [█] |
| play | ▶ | ► |
| circle | ◯ | ( ) |
| circleFilled | ◉ | (*) |
| circleDotted | ◌ | ( ) |
| circleDouble | ◎ | ( ) |
| circleCircle | ⓞ | (○) |
| circleCross | ⓧ | (×) |
| circlePipe | Ⓘ | (│) |
| circleQuestionMark | ?⃝ | (?) |
| bullet | ● | * |
| dot | | . |
| line | ─ | ─ |
| ellipsis | … | ... |
| pointer | | > |
| pointerSmall | | » |
| info | | i |
| warning | ⚠ | ‼ |
| hamburger | ☰ | ≡ |
| smiley | ㋡ | ☺ |
| mustache | ෴ | ┌─┐ |
| heart | ♥ | ♥ |
| arrowUp | ↑ | ↑ |
| arrowDown | ↓ | ↓ |
| arrowLeft | ← | ← |
| arrowRight | → | → |
| radioOn | ◉ | (*) |
| radioOff | ◯ | ( ) |
| checkboxOn | ☒ | [×] |
| checkboxOff | ☐ | [ ] |
| checkboxCircleOn | ⓧ | (×) |
| checkboxCircleOff | Ⓘ | ( ) |
| questionMarkPrefix | ?⃝ | |
| oneHalf | ½ | 1/2 |
| oneThird | ⅓ | 1/3 |
| oneQuarter | ¼ | 1/4 |
| oneFifth | ⅕ | 1/5 |
| oneSixth | ⅙ | 1/6 |
| oneSeventh | ⅐ | 1/7 |
| oneEighth | ⅛ | 1/8 |
| oneNinth | ⅑ | 1/9 |
| oneTenth | ⅒ | 1/10 |
| twoThirds | ⅔ | 2/3 |
| twoFifths | ⅖ | 2/5 |
| threeQuarters | ¾ | 3/4 |
| threeFifths | ⅗ | 3/5 |
| threeEighths | ⅜ | 3/8 |
| fourFifths | ⅘ | 4/5 |
| fiveSixths | ⅚ | 5/6 |
| fiveEighths | ⅝ | 5/8 |
| sevenEighths | ⅞ | 7/8 |
## Related
- [log-symbols](https://github.com/sindresorhus/log-symbols) - Colored symbols for various log levels
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

View File

@@ -0,0 +1,27 @@
'use strict';
module.exports = (str, count, opts) => {
// Support older versions: use the third parameter as options.indent
// TODO: Remove the workaround in the next major version
const options = typeof opts === 'object' ? Object.assign({indent: ' '}, opts) : {indent: opts || ' '};
count = count === undefined ? 1 : count;
if (typeof str !== 'string') {
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``);
}
if (typeof count !== 'number') {
throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);
}
if (typeof options.indent !== 'string') {
throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``);
}
if (count === 0) {
return str;
}
const regex = options.includeEmptyLines ? /^/mg : /^(?!\s*$)/mg;
return str.replace(regex, options.indent.repeat(count));
}
;

View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,68 @@
{
"_from": "indent-string@^3.1.0",
"_id": "indent-string@3.2.0",
"_inBundle": false,
"_integrity": "sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok=",
"_location": "/cucumber/indent-string",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "indent-string@^3.1.0",
"name": "indent-string",
"escapedName": "indent-string",
"rawSpec": "^3.1.0",
"saveSpec": null,
"fetchSpec": "^3.1.0"
},
"_requiredBy": [
"/cucumber"
],
"_resolved": "https://registry.npmjs.org/indent-string/-/indent-string-3.2.0.tgz",
"_shasum": "4a5fd6d27cc332f37e5419a504dbb837105c9289",
"_spec": "indent-string@^3.1.0",
"_where": "/home/simon/Documents/lifen-autotest/node_modules/cucumber",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/indent-string/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Indent each line in a string",
"devDependencies": {
"ava": "*",
"xo": "*"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"homepage": "https://github.com/sindresorhus/indent-string#readme",
"keywords": [
"indent",
"string",
"str",
"pad",
"align",
"line",
"text",
"each",
"every"
],
"license": "MIT",
"name": "indent-string",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/indent-string.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "3.2.0"
}

View File

@@ -0,0 +1,72 @@
# indent-string [![Build Status](https://travis-ci.org/sindresorhus/indent-string.svg?branch=master)](https://travis-ci.org/sindresorhus/indent-string)
> Indent each line in a string
## Install
```
$ npm install indent-string
```
## Usage
```js
const indentString = require('indent-string');
indentString('Unicorns\nRainbows', 4);
//=> ' Unicorns'
//=> ' Rainbows'
indentString('Unicorns\nRainbows', 4, {indent: '♥'});
//=> '♥♥♥♥Unicorns'
//=> '♥♥♥♥Rainbows'
```
## API
### indentString(input, [count], [options])
#### input
Type: `string`
String you want to indent.
#### count
Type: `number`<br>
Default: `1`
How many times you want `indent` repeated.
#### options
Type: `Object`<br>
##### indent
Type: `string`<br>
Default: `' '`
String to use for the indent.
##### includeEmptyLines
Type: `boolean`<br>
Default: `false`
Also indent empty lines.
## Related
- [indent-string-cli](https://github.com/sindresorhus/indent-string-cli) - CLI for this module
- [strip-indent](https://github.com/sindresorhus/strip-indent) - Strip leading whitespace from every line in a string
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

21
node_modules/cucumber/node_modules/is-stream/index.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
'use strict';
var isStream = module.exports = function (stream) {
return stream !== null && typeof stream === 'object' && typeof stream.pipe === 'function';
};
isStream.writable = function (stream) {
return isStream(stream) && stream.writable !== false && typeof stream._write === 'function' && typeof stream._writableState === 'object';
};
isStream.readable = function (stream) {
return isStream(stream) && stream.readable !== false && typeof stream._read === 'function' && typeof stream._readableState === 'object';
};
isStream.duplex = function (stream) {
return isStream.writable(stream) && isStream.readable(stream);
};
isStream.transform = function (stream) {
return isStream.duplex(stream) && typeof stream._transform === 'function' && typeof stream._transformState === 'object';
};

21
node_modules/cucumber/node_modules/is-stream/license generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,70 @@
{
"_from": "is-stream@^1.1.0",
"_id": "is-stream@1.1.0",
"_inBundle": false,
"_integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
"_location": "/cucumber/is-stream",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "is-stream@^1.1.0",
"name": "is-stream",
"escapedName": "is-stream",
"rawSpec": "^1.1.0",
"saveSpec": null,
"fetchSpec": "^1.1.0"
},
"_requiredBy": [
"/cucumber"
],
"_resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"_shasum": "12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44",
"_spec": "is-stream@^1.1.0",
"_where": "/home/simon/Documents/lifen-autotest/node_modules/cucumber",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/is-stream/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Check if something is a Node.js stream",
"devDependencies": {
"ava": "*",
"tempfile": "^1.1.0",
"xo": "*"
},
"engines": {
"node": ">=0.10.0"
},
"files": [
"index.js"
],
"homepage": "https://github.com/sindresorhus/is-stream#readme",
"keywords": [
"stream",
"type",
"streams",
"writable",
"readable",
"duplex",
"transform",
"check",
"detect",
"is"
],
"license": "MIT",
"name": "is-stream",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/is-stream.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "1.1.0"
}

42
node_modules/cucumber/node_modules/is-stream/readme.md generated vendored Normal file
View File

@@ -0,0 +1,42 @@
# is-stream [![Build Status](https://travis-ci.org/sindresorhus/is-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/is-stream)
> Check if something is a [Node.js stream](https://nodejs.org/api/stream.html)
## Install
```
$ npm install --save is-stream
```
## Usage
```js
const fs = require('fs');
const isStream = require('is-stream');
isStream(fs.createReadStream('unicorn.png'));
//=> true
isStream({});
//=> false
```
## API
### isStream(stream)
#### isStream.writable(stream)
#### isStream.readable(stream)
#### isStream.duplex(stream)
#### isStream.transform(stream)
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)