test: improve reverse reference resolution handling
This commit is contained in:
+19
-19
@@ -802,25 +802,10 @@ export function parseCsv(
|
||||
relax_column_count: true,
|
||||
});
|
||||
|
||||
if (records.length < 2) {
|
||||
throw new Error("CSV must have at least 2 rows: headers and schemas");
|
||||
}
|
||||
|
||||
const headers = records[0];
|
||||
const schemas = records[1];
|
||||
|
||||
if (headers.length !== schemas.length) {
|
||||
throw new Error(
|
||||
`Header count (${headers.length}) does not match schema count (${schemas.length})`,
|
||||
);
|
||||
}
|
||||
|
||||
// Parse reverse reference declarations from comment lines between schema row and data rows
|
||||
// Filter out comment lines from all records, collecting reverse reference declarations
|
||||
const reverseReferences: ReverseReferenceDeclaration[] = [];
|
||||
const dataRows: string[][] = [];
|
||||
for (let i = 2; i < records.length; i++) {
|
||||
const row = records[i];
|
||||
// Check if this is a comment line (starting with the configured comment character)
|
||||
const filteredRecords: string[][] = [];
|
||||
for (const row of records) {
|
||||
const firstCell = (row[0] ?? "").trim();
|
||||
if (comment && firstCell.startsWith(comment)) {
|
||||
const decl = parseReverseReferenceDeclaration(firstCell, comment);
|
||||
@@ -830,9 +815,24 @@ export function parseCsv(
|
||||
// Skip comment lines (whether or not they're reverse ref declarations)
|
||||
continue;
|
||||
}
|
||||
dataRows.push(row);
|
||||
filteredRecords.push(row);
|
||||
}
|
||||
|
||||
if (filteredRecords.length < 2) {
|
||||
throw new Error("CSV must have at least 2 rows: headers and schemas");
|
||||
}
|
||||
|
||||
const headers = filteredRecords[0];
|
||||
const schemas = filteredRecords[1];
|
||||
|
||||
if (headers.length !== schemas.length) {
|
||||
throw new Error(
|
||||
`Header count (${headers.length}) does not match schema count (${schemas.length})`,
|
||||
);
|
||||
}
|
||||
|
||||
const dataRows = filteredRecords.slice(2);
|
||||
|
||||
// Also check schema row cells for comment-prefixed reverse reference declarations
|
||||
// (in case they appear as schema cells rather than separate rows)
|
||||
for (let col = 0; col < schemas.length; col++) {
|
||||
|
||||
Reference in New Issue
Block a user