1- import { datasetNamed } from '../../utils ' ;
1+ import { datasetExpander } from '../../TestParser/DatasetExpander ' ;
22import type { AstNode , CallNode , ExpressionStatementNode } from '../AstParser/AstNode' ;
33import { evaluate } from '../Expressions/PhpExpression' ;
44import type { PHP } from '../PHP' ;
@@ -134,6 +134,7 @@ function resolveDatasets(sources: AstNode[]): string[] {
134134 return cartesianProduct ( datasets ) ;
135135 }
136136
137+ // Cartesian failed (e.g. closure/generator can't be statically resolved); fall back to independent resolution
137138 return sources . flatMap ( ( source ) => resolvePestLabels ( source ) ) ;
138139}
139140
@@ -154,18 +155,43 @@ function resolvePestLabels(node: AstNode): string[] {
154155 if ( ! formatted ) {
155156 return [ ] ;
156157 }
157- labels . push ( datasetNamed ( formatted ) ) ;
158+ labels . push ( datasetExpander . named ( formatted ) ) ;
158159 } else {
159- labels . push ( datasetNamed ( `dataset "${ key } "` ) ) ;
160+ labels . push ( datasetExpander . named ( `dataset "${ key } "` ) ) ;
160161 }
161162 }
162- return labels ;
163+ return deduplicateLabels ( labels ) ;
163164}
164165
166+ function deduplicateLabels ( labels : string [ ] ) : string [ ] {
167+ const counts = new Map < string , number > ( ) ;
168+ for ( const label of labels ) {
169+ counts . set ( label , ( counts . get ( label ) ?? 0 ) + 1 ) ;
170+ }
171+
172+ const indices = new Map < string , number > ( ) ;
173+ return labels . map ( ( label ) => {
174+ if ( ( counts . get ( label ) ?? 0 ) <= 1 ) {
175+ return label ;
176+ }
177+ const idx = ( indices . get ( label ) ?? 0 ) + 1 ;
178+ indices . set ( label , idx ) ;
179+ return `${ label } #${ idx } ` ;
180+ } ) ;
181+ }
182+
183+ const MAX_DATASET_ITEMS = 3 ;
184+
165185function formatPestValue ( value : unknown ) : string | undefined {
166186 if ( value instanceof Map || Array . isArray ( value ) ) {
167187 const items = value instanceof Map ? [ ...value . values ( ) ] : value ;
168- return `(${ items . map ( ( v ) => ( typeof v === 'string' ? `'${ v } '` : String ( v ) ) ) . join ( ', ' ) } )` ;
188+ const truncated = items . length > MAX_DATASET_ITEMS ;
189+ const visible = items . slice ( 0 , MAX_DATASET_ITEMS ) ;
190+ const parts = visible . map ( ( v ) => ( typeof v === 'string' ? `'${ v } '` : String ( v ) ) ) ;
191+ if ( truncated ) {
192+ parts . push ( '…' ) ;
193+ }
194+ return `(${ parts . join ( ', ' ) } )` ;
169195 }
170196 if ( typeof value === 'string' ) {
171197 return `('${ value } ')` ;
@@ -178,7 +204,9 @@ function cartesianProduct(datasets: string[][]): string[] {
178204 for ( let i = 1 ; i < datasets . length ; i ++ ) {
179205 combinations = combinations . flatMap ( ( combo ) => datasets [ i ] . map ( ( v ) => [ ...combo , v ] ) ) ;
180206 }
181- return combinations . map ( ( combo ) => datasetNamed ( combo . map ( ( v ) => `('${ v } ')` ) . join ( ' / ' ) ) ) ;
207+ return combinations . map ( ( combo ) =>
208+ datasetExpander . named ( combo . map ( ( v ) => `('${ v } ')` ) . join ( ' / ' ) ) ,
209+ ) ;
182210}
183211
184212function unwrapClosureBody ( node : AstNode ) : AstNode | undefined {
0 commit comments