@@ -4,6 +4,7 @@ import CucumberExpression from '../src/CucumberExpression.js'
4
4
import CucumberExpressionGenerator from '../src/CucumberExpressionGenerator.js'
5
5
import ParameterType from '../src/ParameterType.js'
6
6
import ParameterTypeRegistry from '../src/ParameterTypeRegistry.js'
7
+ import { ParameterInfo } from '../src/types.js'
7
8
8
9
class Currency {
9
10
constructor ( public readonly s : string ) { }
@@ -15,11 +16,11 @@ describe('CucumberExpressionGenerator', () => {
15
16
16
17
function assertExpression (
17
18
expectedExpression : string ,
18
- expectedArgumentNames : string [ ] ,
19
+ expectedParameterInfo : ParameterInfo [ ] ,
19
20
text : string
20
21
) {
21
22
const generatedExpression = generator . generateExpressions ( text ) [ 0 ]
22
- assert . deepStrictEqual ( generatedExpression . parameterNames , expectedArgumentNames )
23
+ assert . deepStrictEqual ( generatedExpression . parameterInfos , expectedParameterInfo )
23
24
assert . strictEqual ( generatedExpression . source , expectedExpression )
24
25
25
26
const cucumberExpression = new CucumberExpression (
@@ -32,7 +33,7 @@ describe('CucumberExpressionGenerator', () => {
32
33
`Expected text '${ text } ' to match generated expression '${ generatedExpression . source } '`
33
34
)
34
35
}
35
- assert . strictEqual ( match . length , expectedArgumentNames . length )
36
+ assert . strictEqual ( match . length , expectedParameterInfo . length )
36
37
}
37
38
38
39
beforeEach ( ( ) => {
@@ -63,37 +64,110 @@ describe('CucumberExpressionGenerator', () => {
63
64
} )
64
65
65
66
it ( 'generates expression with escaped slashes' , ( ) => {
66
- assertExpression ( 'The {int}\\/{int}\\/{int} hey' , [ 'int' , 'int2' , 'int3' ] , 'The 1814/05/17 hey' )
67
+ assertExpression (
68
+ 'The {int}\\/{int}\\/{int} hey' ,
69
+ [
70
+ {
71
+ type : 'Number' ,
72
+ name : 'int' ,
73
+ count : 1 ,
74
+ } ,
75
+ {
76
+ type : 'Number' ,
77
+ name : 'int' ,
78
+ count : 2 ,
79
+ } ,
80
+ {
81
+ type : 'Number' ,
82
+ name : 'int' ,
83
+ count : 3 ,
84
+ } ,
85
+ ] ,
86
+ 'The 1814/05/17 hey'
87
+ )
67
88
} )
68
89
69
90
it ( 'generates expression for int float arg' , ( ) => {
70
91
assertExpression (
71
92
'I have {int} cukes and {float} euro' ,
72
- [ 'int' , 'float' ] ,
93
+ [
94
+ {
95
+ type : 'Number' ,
96
+ name : 'int' ,
97
+ count : 1 ,
98
+ } ,
99
+ {
100
+ type : 'Number' ,
101
+ name : 'float' ,
102
+ count : 1 ,
103
+ } ,
104
+ ] ,
73
105
'I have 2 cukes and 1.5 euro'
74
106
)
75
107
} )
76
108
77
109
it ( 'generates expression for strings' , ( ) => {
78
110
assertExpression (
79
111
'I like {string} and {string}' ,
80
- [ 'string' , 'string2' ] ,
112
+ [
113
+ {
114
+ type : 'String' ,
115
+ name : 'string' ,
116
+ count : 1 ,
117
+ } ,
118
+ {
119
+ type : 'String' ,
120
+ name : 'string' ,
121
+ count : 2 ,
122
+ } ,
123
+ ] ,
81
124
'I like "bangers" and \'mash\''
82
125
)
83
126
} )
84
127
85
128
it ( 'generates expression with % sign' , ( ) => {
86
- assertExpression ( 'I am {int}%% foobar' , [ 'int' ] , 'I am 20%% foobar' )
129
+ assertExpression (
130
+ 'I am {int}%% foobar' ,
131
+ [
132
+ {
133
+ type : 'Number' ,
134
+ name : 'int' ,
135
+ count : 1 ,
136
+ } ,
137
+ ] ,
138
+ 'I am 20%% foobar'
139
+ )
87
140
} )
88
141
89
142
it ( 'generates expression for just int' , ( ) => {
90
- assertExpression ( '{int}' , [ 'int' ] , '99999' )
143
+ assertExpression (
144
+ '{int}' ,
145
+ [
146
+ {
147
+ type : 'Number' ,
148
+ name : 'int' ,
149
+ count : 1 ,
150
+ } ,
151
+ ] ,
152
+ '99999'
153
+ )
91
154
} )
92
155
93
156
it ( 'numbers only second argument when builtin type is not reserved keyword' , ( ) => {
94
157
assertExpression (
95
158
'I have {float} cukes and {float} euro' ,
96
- [ 'float' , 'float2' ] ,
159
+ [
160
+ {
161
+ type : 'Number' ,
162
+ name : 'float' ,
163
+ count : 1 ,
164
+ } ,
165
+ {
166
+ type : 'Number' ,
167
+ name : 'float' ,
168
+ count : 2 ,
169
+ } ,
170
+ ] ,
97
171
'I have 2.5 cukes and 1.5 euro'
98
172
)
99
173
} )
@@ -103,18 +177,38 @@ describe('CucumberExpressionGenerator', () => {
103
177
new ParameterType ( 'currency' , / [ A - Z ] { 3 } / , Currency , ( s ) => new Currency ( s ) , true , false )
104
178
)
105
179
106
- assertExpression ( 'I have a {currency} account' , [ 'currency' ] , 'I have a EUR account' )
180
+ assertExpression (
181
+ 'I have a {currency} account' ,
182
+ [
183
+ {
184
+ type : 'Currency' ,
185
+ name : 'currency' ,
186
+ count : 1 ,
187
+ } ,
188
+ ] ,
189
+ 'I have a EUR account'
190
+ )
107
191
} )
108
192
109
193
it ( 'prefers leftmost match when there is overlap' , ( ) => {
110
194
parameterTypeRegistry . defineParameterType (
111
- new ParameterType < Currency > ( 'currency' , / c d / , Currency , ( s ) => new Currency ( s ) , true , false )
195
+ new ParameterType ( 'currency' , / c d / , Currency , ( s ) => new Currency ( s ) , true , false )
112
196
)
113
197
parameterTypeRegistry . defineParameterType (
114
198
new ParameterType ( 'date' , / b c / , Date , ( s ) => new Date ( s ) , true , false )
115
199
)
116
200
117
- assertExpression ( 'a {date} d e f g' , [ 'date' ] , 'a b c d e f g' )
201
+ assertExpression (
202
+ 'a {date} d e f g' ,
203
+ [
204
+ {
205
+ type : 'Date' ,
206
+ name : 'date' ,
207
+ count : 1 ,
208
+ } ,
209
+ ] ,
210
+ 'a b c d e f g'
211
+ )
118
212
} )
119
213
120
214
// TODO: prefers widest match
0 commit comments