Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new line for comments in data tables #18

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/GherkinAST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,8 @@ export class TypedStep
}

get lastLine(): number {
const dataTableLength = this.dataTable?.rows.length ?? 0;
const docStringLength = this.docString
? this.docString.content.split('\n').length + 2
: 0;
const dataTableLength = this.dataTable?.nbRows ?? 0;
const docStringLength = this.docString?.nbRows ?? 0;

return this.location.line + dataTableLength + docStringLength;
}
Expand Down Expand Up @@ -469,6 +467,10 @@ export class TypedDocString
this.content = originalNode.content;
this.delimiter = originalNode.delimiter;
}

get nbRows(): number {
return this.content.split('\n').length + 2;
}
}

export class TypedDataTable
Expand All @@ -485,6 +487,17 @@ export class TypedDataTable
this.rows = originalNode.rows.map((r) => new TypedTableRow(r, columnSizes));
}

get nbRows(): number {
return (
this.rows.reduce((acc, row) => {
// @ts-expect-error comments are added by prettier directly
const commentLines: number = row.comments?.length ?? 0;

return acc + commentLines + 1;
}, 0) ?? 0
);
}

get children(): ReadonlyArray<TypedTableRow> {
return this.rows;
}
Expand Down
44 changes: 44 additions & 0 deletions tests/plugin/__snapshots__/jsfmt.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,50 @@ Feature: A comment before a "Given" should stay before the "Given".
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`;

exports[`data_table_with_comments.feature 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Feature: accountability
Scenario: Scenario Outline name
Given context
Then table node with a comment:
| amountForPro | 0 |
# a comment in between
| collectedFeeAmount | 95 |
Then result

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
options: {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Feature: accountability

Scenario: Scenario Outline name
Given context
Then table node with a comment:
| amountForPro | 0 |
# a comment in between
| collectedFeeAmount | 95 |
Then result

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
options: {
"forceNewlineBetweenStepBlocks": true
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Feature: accountability

Scenario: Scenario Outline name
Given context
Then table node with a comment:
| amountForPro | 0 |
# a comment in between
| collectedFeeAmount | 95 |
Then result

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`;

exports[`datatable_with_PHP_FQCN.feature 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source
Expand Down
8 changes: 8 additions & 0 deletions tests/plugin/data_table_with_comments.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: accountability
Scenario: Scenario Outline name
Given context
Then table node with a comment:
| amountForPro | 0 |
# a comment in between
| collectedFeeAmount | 95 |
Then result