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

AVRO-4058: [C++] Improve readability of SchemaTests #3167

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

pascalginter
Copy link
Contributor

@pascalginter pascalginter commented Sep 20, 2024

AVRO-4058 (Preparation)

Migrated the vast majority of json schema definitions to raw string literals to improve their readability. Notable exception are schemas heavily relying on escaped characters that test the json after compilation are compact

What is the purpose of the change

Improve readability of json schemas in SchemaTests.cc (Similar work was already done in CodecTests.cc in PR #2762)

I did this work in preparation of adding some new tests in the context of AVRO-4058

Verifying this change

(Please pick one of the following options)

This change is a trivial rework / code cleanup without any test coverage.

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

@github-actions github-actions bot added the C++ Pull Requests for C++ binding label Sep 20, 2024
@@ -315,11 +436,13 @@ static void testRoundTrip(const char *schema) {
compiledSchema.toJson(os);
std::string result = os.str();
result.erase(std::remove_if(result.begin(), result.end(), ::isspace), result.end()); // Remove whitespace
BOOST_CHECK(result == std::string(schema));
std::string trimmedSchema = schema;
trimmedSchema.erase(std::remove_if(trimmedSchema.begin(), trimmedSchema.end(), ::isspace), trimmedSchema.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

Every time I see someone do something like this I worry...

std::isspace
The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

In this case it is (mostly) okay as the schemas all have chars which meet these requirements, but if toJson ever has a bug which doesn't meet this requirement, we now have undefined behavior.

std::string trimmedSchema = schema;
boost::algorithm::replace_all(trimmedSchema, " ", "");
boost::algorithm::replace_all(trimmedSchema, "\n", "");

... and now that I've written that, I see you just followed the bad example above...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, I was not aware of the issues with std::isspace

@martin-g martin-g merged commit 86fb29c into apache:main Sep 24, 2024
4 checks passed
@martin-g martin-g changed the title [C++] Improve readability of SchemaTests AVRO-4058: [C++] Improve readability of SchemaTests Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ Pull Requests for C++ binding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants