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

datatable/java: DataTable print with configurable indent + without escaping #1624

Merged
merged 17 commits into from
Jul 1, 2021

Conversation

artysidorenko
Copy link
Contributor

Summary

Updates DataTable with a new print method allowing to configure custom indention, and skip escaping the cell contents.

Details

  • makes the TablePrinter class configurable, via a new TablePrinterBuilder class.
  • adds a new method printFormatted() to the DataTable class, as it already includes similar publicly-exposed print() methods
  • above method configures the TablePrinter with custom indent + removing cell-escaping.

(I'm still not too familiar with the codebase; the above felt like reasonable decisions, but am happy to incorporate feedback if you prefer doing it different)

Motivation and Context

Relates to issue-2320 on cucumber-jvm.

Ultimate aim is to include data-tables in the printed test output. E.g. in the following feature, current behaviour prints out only the step definition, but it skips the info in the table.

Given I have a list of people
  | NAME  | AGE |
  | John  | 25  |
  | Sally | 28  |

How Has This Been Tested?

Added 2 unit tests. can_print_table_with_escape_characters_regular confirms the escape-cell behaviour of the original print() method. And can_print_table_with_escape_characters_formatted tests the behaviour of the new printFormatted() method.

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • The change has been ported to Java.
  • The change has been ported to Ruby.
  • The change has been ported to JavaScript.
  • The change has been ported to Go.
  • The change has been ported to .NET.
  • I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have updated the CHANGELOG accordingly.

(don't think it requires documentation/porting to other languages as it's a small change?)

@mpkorstanje mpkorstanje self-assigned this Jun 23, 2021
Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rewritten the rendering logic from scratch to make the table printer thread-safe. Coincidently this also simplified the code a whole lot. Added a few tests to confirm I didn't break anything.

Thing I'm still wondering about is the naming. I'm not happy about the Printer suffix.

Comparable bits of code in the JDK are named Formatter and use the format(Thing) : String formatTo(Thing, Appendable).

@artysidorenko
Copy link
Contributor Author

Looks good, thanks!

The only difference I noticed is that the comparable java.util.Formatter tends to keep the appendable as a property of the instance, but I think the formatTo method makes the behaviour pretty clear here 👍

@mpkorstanje mpkorstanje merged commit 3a1eec4 into cucumber:main Jul 1, 2021
@aslakhellesoy
Copy link
Contributor

Hi @artysidorenko,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

@mpkorstanje
Copy link
Contributor

I'll have to find some time to make the release.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jul 3, 2021

Done. Unfortunately there are some breaking changes that precede your change. If you want to continue this in Cucumber JVM. I would suggest branching of this commit in the v7.x.x branch. Not everything may work, there is a bit of a re-factoring coming through.

@mpkorstanje
Copy link
Contributor

Nevermind that. Branch of main. v7 is too broken.

mpkorstanje pushed a commit to cucumber/cucumber-jvm that referenced this pull request Aug 8, 2021
* updates PrettyFormatter.printStep to process the DataTable if one is present in the step object
* uses DataTableFormatter exposed in cucumber/common#1624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants