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

Truncate on bytes or chars #88

Merged
merged 7 commits into from
Mar 3, 2021

Conversation

mrginglymus
Copy link
Contributor

No description provided.

@@ -62,18 +63,30 @@ public String toString() {
}

/**
* Builds the string such that it does not exceed maxSize, including the truncation string.
* Builds the string such that it does not exceed maxSize in bytes, including the truncation string.
*
* @param maxSize the maximum size of the resultant string.
* @return A string comprising as many of the joined chunks that will fit in the given size, plus the truncation
* string if truncation was necessary.
*/
public String build(final int maxSize) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we deprecate this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I think we should.

And instead of passing the chunkOnChars boolean field, would it be better if we expose two methods directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure; preference for names? buildByBytes/buildByChars?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with that.

@codecov
Copy link

codecov bot commented Feb 24, 2021

Codecov Report

Merging #88 (e7e524e) into master (6fda320) will decrease coverage by 1.20%.
The diff coverage is 92.30%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #88      +/-   ##
============================================
- Coverage     87.11%   85.90%   -1.21%     
- Complexity      142      150       +8     
============================================
  Files            16       17       +1     
  Lines           652      731      +79     
  Branches         49       54       +5     
============================================
+ Hits            568      628      +60     
- Misses           66       85      +19     
  Partials         18       18              
Impacted Files Coverage Δ Complexity Δ
...io/jenkins/plugins/checks/api/TruncatedString.java 92.53% <92.30%> (-1.02%) 10.00 <2.00> (+2.00) ⬇️
...o/jenkins/plugins/checks/steps/WithChecksStep.java 66.01% <0.00%> (-9.57%) 2.00% <0.00%> (ø%)
...va/io/jenkins/plugins/checks/api/ChecksOutput.java 95.34% <0.00%> (ø) 8.00% <0.00%> (ø%)
...a/io/jenkins/plugins/checks/api/ChecksDetails.java 100.00% <0.00%> (ø) 10.00% <0.00%> (ø%)
...o/jenkins/plugins/checks/api/ChecksAnnotation.java 100.00% <0.00%> (ø) 12.00% <0.00%> (ø%)
...ava/io/jenkins/plugins/checks/steps/StepUtils.java 100.00% <0.00%> (ø) 4.00% <0.00%> (?%)
...enkins/plugins/checks/steps/PublishChecksStep.java 91.04% <0.00%> (+0.56%) 21.00% <0.00%> (+2.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fda320...1de0792. Read the comment docs.

builder.addText("🕴️🕴️\n"); // 2 + 1
assertThat(builder.build().toString().length()).isEqualTo(11);
assertThat(builder.build().toString().getBytes(StandardCharsets.UTF_8).length).isEqualTo(25);
assertThat(builder.build().build(20, chunkOnChars)).isEqualTo(chunkOnChars ? "☃☃☃\n🕴️🕴️\n" : "☃☃☃\nTruncated");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should mix the tests. This test case is named "shouldTruncateToBytesNotChars" but you are still testing if it truncates by chars correctly, that's a little redundant and confusing. Same for others, maybe split them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, the test name was from before I decided to make it switchable. I will definitely update that.

My argument for having the parametrized like this is better combinatorial coverage, but it also helps highlight the difference in behaviours - ie, given a certain input, the output will look like this or that depending on the chunking mode.

If you'd rather I split it out I can do, but my preference would be to leave it parameterized.

Copy link
Contributor

Choose a reason for hiding this comment

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

but at least we should change the name? maybe shouldTruncateOnBothBytesAndChars

@@ -62,18 +63,30 @@ public String toString() {
}

/**
* Builds the string such that it does not exceed maxSize, including the truncation string.
* Builds the string such that it does not exceed maxSize in bytes, including the truncation string.
*
* @param maxSize the maximum size of the resultant string.
* @return A string comprising as many of the joined chunks that will fit in the given size, plus the truncation
* string if truncation was necessary.
*/
public String build(final int maxSize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I think we should.

And instead of passing the chunkOnChars boolean field, would it be better if we expose two methods directly?

@XiongKezhi XiongKezhi added the bug Something isn't working label Mar 3, 2021
@KalleOlaviNiemitalo
Copy link

This seems a bit incomplete in that TruncatedString now supports counting bytes and chars, but ChecksOutput always tells it to count bytes and does not let checks publisher plugins access the TruncatedString themselves.

I'm not filing an issue about that because I don't know whether any such plugin would even need to count chars:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants