Skip to content

Commit

Permalink
Preserve trailing comments. Fixes #38.
Browse files Browse the repository at this point in the history
Also eliminate useless trailing space after `:`
when the node has no `name`.
  • Loading branch information
xeger committed Oct 15, 2023
1 parent c1543e6 commit 85eb3aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion javascript/src/pretty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ function prettyKeywordContainer(
.concat(prettyTags(tags, syntax, level))
.concat(keywordPrefix(level, syntax))
.concat(stepContainer.keyword)
.concat(': ')
.concat(':')
.concat(stepContainer.name ? ' ' : '')
.concat(stepContainer.name)
.concat('\n')
.concat(description)
Expand Down
5 changes: 5 additions & 0 deletions javascript/src/walkGherkinDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function walkGherkinDocument<Acc>(
}
}
}
acc = walkComments(popRemainingContents(), acc);
return acc

function walkComments(comments: readonly messages.Comment[], acc: Acc): Acc {
Expand Down Expand Up @@ -114,6 +115,10 @@ export function walkGherkinDocument<Acc>(
}
return commentsStack.splice(0, count)
}

function popRemainingContents(): readonly messages.Comment[] {
return commentsStack.splice(0, commentsStack.length)
}
}


Expand Down
18 changes: 18 additions & 0 deletions javascript/test/prettyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ Feature: hello
`)
})

it('renders trailing comments', () => {
checkGherkinToAstToGherkin(`# one
Feature: hello
Scenario: one
# one
Given a doc string:
"""
a
\\"\\"\\"
b
"""
# two
# three
# four
`)
});

it('renders descriptions when set', () => {
checkGherkinToAstToGherkin(`Feature: hello
So this is a feature
Expand Down

0 comments on commit 85eb3aa

Please sign in to comment.