File tree 2 files changed +10
-9
lines changed
2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -6,34 +6,35 @@ The function passed to `defineSupportCode` is called with an object as the first
6
6
7
7
---
8
8
9
- #### ` addTransform({captureGroupRegexps , typeName, transformer})`
9
+ #### ` defineParameterType({regexp , typeName, transformer})`
10
10
11
11
Add a new transform to convert a capture group into something else.
12
12
13
- * ` captureGroupRegexps ` : An array of regular expressions to apply the transformer to
14
- * ` transformer ` : A function which transforms the captured group from a string into what is passed to the step definition
13
+ * ` regexp ` : A regular expression (or array of regular expressions) that match the parameter
15
14
* ` typeName ` : string used to refer to this type in cucumber expressions
15
+ * ` transformer ` : An optional function which transforms the captured argument from a string into what is passed to the step definition.
16
+ If no transform function is specified, the captured argument is left as a string.
16
17
17
18
The built in transforms are:
18
19
19
20
``` javascript
20
21
// Float
21
22
{
22
- captureGroupRegexps : [ ' -?\\ d*\\ .?\\ d+ ' ] ,
23
+ regexp : / -? \d * \. ? \d + / ,
23
24
transformer: parseFloat,
24
25
typeName: ' float'
25
26
}
26
27
27
- // Int
28
+ // Integer
28
29
{
29
- captureGroupRegexps : [ ' -?\\ d+ ' ] ,
30
+ regexp : / -? \d + / ,
30
31
transformer: parseInt,
31
32
typeName: ' int'
32
33
}
33
34
34
35
// String in double quotes
35
36
{
36
- captureGroupRegexps : [ ' "[^"]*" ' ] ,
37
+ regexp : / "[^ "] + " / ,
37
38
transformer: JSON .parse ,
38
39
typeName: ' stringInDoubleQuotes'
39
40
}
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ function build() {
4
4
const parameterTypeRegistry = new ParameterTypeRegistry ( )
5
5
const stringInDoubleQuotesParameterType = new ParameterType (
6
6
'stringInDoubleQuotes' ,
7
- function ( ) { } ,
8
- ' "[^"]*"' ,
7
+ null ,
8
+ / " [ ^ " ] + " / ,
9
9
JSON . parse
10
10
)
11
11
parameterTypeRegistry . defineParameterType ( stringInDoubleQuotesParameterType )
You can’t perform that action at this time.
0 commit comments