@@ -4,6 +4,7 @@ import CucumberExpression from '../src/CucumberExpression.js'
44import CucumberExpressionGenerator from '../src/CucumberExpressionGenerator.js'
55import ParameterType from '../src/ParameterType.js'
66import ParameterTypeRegistry from '../src/ParameterTypeRegistry.js'
7+ import { ParameterInfo } from '../src/types.js'
78
89class Currency {
910 constructor ( public readonly s : string ) { }
@@ -15,11 +16,11 @@ describe('CucumberExpressionGenerator', () => {
1516
1617 function assertExpression (
1718 expectedExpression : string ,
18- expectedArgumentNames : string [ ] ,
19+ expectedParameterInfo : ParameterInfo [ ] ,
1920 text : string
2021 ) {
2122 const generatedExpression = generator . generateExpressions ( text ) [ 0 ]
22- assert . deepStrictEqual ( generatedExpression . parameterNames , expectedArgumentNames )
23+ assert . deepStrictEqual ( generatedExpression . parameterInfos , expectedParameterInfo )
2324 assert . strictEqual ( generatedExpression . source , expectedExpression )
2425
2526 const cucumberExpression = new CucumberExpression (
@@ -32,7 +33,7 @@ describe('CucumberExpressionGenerator', () => {
3233 `Expected text '${ text } ' to match generated expression '${ generatedExpression . source } '`
3334 )
3435 }
35- assert . strictEqual ( match . length , expectedArgumentNames . length )
36+ assert . strictEqual ( match . length , expectedParameterInfo . length )
3637 }
3738
3839 beforeEach ( ( ) => {
@@ -63,37 +64,110 @@ describe('CucumberExpressionGenerator', () => {
6364 } )
6465
6566 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+ )
6788 } )
6889
6990 it ( 'generates expression for int float arg' , ( ) => {
7091 assertExpression (
7192 '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+ ] ,
73105 'I have 2 cukes and 1.5 euro'
74106 )
75107 } )
76108
77109 it ( 'generates expression for strings' , ( ) => {
78110 assertExpression (
79111 '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+ ] ,
81124 'I like "bangers" and \'mash\''
82125 )
83126 } )
84127
85128 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+ )
87140 } )
88141
89142 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+ )
91154 } )
92155
93156 it ( 'numbers only second argument when builtin type is not reserved keyword' , ( ) => {
94157 assertExpression (
95158 '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+ ] ,
97171 'I have 2.5 cukes and 1.5 euro'
98172 )
99173 } )
@@ -103,18 +177,38 @@ describe('CucumberExpressionGenerator', () => {
103177 new ParameterType ( 'currency' , / [ A - Z ] { 3 } / , Currency , ( s ) => new Currency ( s ) , true , false )
104178 )
105179
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+ )
107191 } )
108192
109193 it ( 'prefers leftmost match when there is overlap' , ( ) => {
110194 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 )
112196 )
113197 parameterTypeRegistry . defineParameterType (
114198 new ParameterType ( 'date' , / b c / , Date , ( s ) => new Date ( s ) , true , false )
115199 )
116200
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+ )
118212 } )
119213
120214 // TODO: prefers widest match
0 commit comments