Skip to content

TomlTransformer implementation#1572

Merged
snuyanzin merged 1 commit into
datafaker-net:mainfrom
badoken:main
Jun 24, 2025
Merged

TomlTransformer implementation#1572
snuyanzin merged 1 commit into
datafaker-net:mainfrom
badoken:main

Conversation

@badoken

@badoken badoken commented Jun 22, 2025

Copy link
Copy Markdown
Contributor

Adding to the collection of Transformers (JsonTransformer, YamlTransformer etc.)
TOML support, to generate data in TOML format (specs).

The format is often used in Python and Rust.

The implementation is based on YamlTransformer and its tests structure

@what-the-diff

what-the-diff Bot commented Jun 22, 2025

Copy link
Copy Markdown

PR Summary

  • Introduction of TomlTransformer Class
    A new class TomlTransformer has been introduced which facilitates the conversion of input into TOML (Tom's Obvious, Minimal Language) format. This makes it more convenient to handle representations of data structures in a readable format.

  • Extended Functionality for TomlTransformer
    Additional methods have been implemented in the TomlTransformer class, which allow for string representation generation from inputs. Moreover, there's an option for generating representations up to a certain limit as well.

  • Handling of Nested Structures and Collections
    The capability to serialize complex nested structures and collections in the TOML format has been introduced. This gives a standardized presentation to these entities and enhances readability.

  • Special Methods for Handing Arrays and Formatting Values
    New methods have been implemented specifically for handling arrays and formatting values, giving more flexibility in how these components can be manipulated.

  • Introduction of TomlTest, and Implementation of Various Tests
    A new TomlTest test class has been introduced to ensure the smooth functioning of the TomlTransformer. A variety of tests, including those for complex nested schemas and collections, have been implemented for thorough validation.

Overall, the PR focuses on enhancing the transformation process into TOML format, adding flexibility and making data representation more standardized and readable.

@codecov-commenter

codecov-commenter commented Jun 22, 2025

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 84.93151% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.44%. Comparing base (d5a38a8) to head (5710ab6).
⚠️ Report is 226 commits behind head on main.

Files with missing lines Patch % Lines
...net/datafaker/transformations/TomlTransformer.java 84.93% 6 Missing and 5 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1572      +/-   ##
============================================
- Coverage     92.51%   92.44%   -0.07%     
- Complexity     3332     3358      +26     
============================================
  Files           330      331       +1     
  Lines          6547     6620      +73     
  Branches        640      655      +15     
============================================
+ Hits           6057     6120      +63     
- Misses          338      344       +6     
- Partials        152      156       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

writeSchema(sb, input, schema, "");
int len = sb.length();
int sepLen = LINE_SEPARATOR.length();
if (len >= sepLen && sb.substring(len - sepLen).equals(LINE_SEPARATOR)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (len >= sepLen && sb.substring(len - sepLen).equals(LINE_SEPARATOR)) {
if (sb.endsWith(LINE_SEPARATOR)) {

could it be simplified like that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a StringBuilder, that doesn't have endsWith, unfortunately.
It can be first built, then checked with nicer endsWith and then the string can be cut again, but I assume that would be a bit less performant due to the string rebuild twice.
Let me know if you think it still makes sense to change

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ah, that's true

then if it is StringBuilder I think it is possible to use indexOf/lastIndexOf, something like

if (len >= sepLen && sb.lastIndexOf(LINE_SEPARATOR, len - sepLen) >= 0)

then no need to create new strings
WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, updated 👍

@snuyanzin

Copy link
Copy Markdown
Collaborator

great to see new formats appearing
can you please also
1 update doc (https://github.com/datafaker-net/datafaker/blob/main/docs/documentation/schemas.md)
2. rebase the PR (in order to eliminate merge commit from the PR)

@badoken

badoken commented Jun 22, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @snuyanzin for the review, I've rebased the PR and extended the doc

@snuyanzin

Copy link
Copy Markdown
Collaborator

Thank you for your contribution @badoken

@snuyanzin
snuyanzin merged commit 50d7af3 into datafaker-net:main Jun 24, 2025
26 checks passed
@asolntsev asolntsev added this to the 2.4.4 milestone Jun 24, 2025
@asolntsev asolntsev added the enhancement New feature or request label Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants