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

Simplify TextProvider, Fix all @text ending with space #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

literalplus
Copy link
Contributor

This PR simplifies TextProvider to be a lot clearer and also avoid swallowing an unnecessary exception.

Furthermore, it changes its behaviour so that created text does not always have a space at the end. Usually, people don't mean to add an unnecessary space at the end of their text argument if they don't put more text.

The motivation for this commit is that I am currently experiencing the space problem in my usage of this library.

Thanks!

@wizjany
Copy link

wizjany commented Aug 6, 2016

isn't the point of swallowing that exception to allow for an empty string?

@literalplus
Copy link
Contributor Author

literalplus commented Aug 7, 2016

Wouldn't work: there's a break in the catch statement, causing first never
being set to false.

Also, what's the use case?

-- Above message was sent from my mobile phone. There may and will be all
kinds of errors included.

On 6 Aug 2016 22:14, "Wizjany" notifications@github.com wrote:

isn't the point of swallowing that exception to allow for an empty string?

@wizjany
Copy link

wizjany commented Aug 7, 2016

right, so it breaks the while loop and the stringbuilder will have no elements, making the toString return "", which is a completely valid arg (assuming there's no non-empty validators)

use case would be allowing an empty text arg. you could probably also use an @optional @text, but that allows it to be null afaik, meaning you need to check if it was specified or not.

@literalplus
Copy link
Contributor Author

literalplus commented Aug 7, 2016

It breaks the while loop, first is true, so the condition on the if
statement passes, and a MissingArgumentException is thrown.

-- Above message was sent from my mobile phone. There may and will be all
kinds of errors included.

On 7 Aug 2016 02:32, "Wizjany" notifications@github.com wrote:

right, so it breaks the while loop and the stringbuilder will have no
elements, making the toString return "", which is a completely valid arg
(assuming there's no non-empty validators
https://github.com/sk89q/Intake/blob/master/intake/src/main/java/com/sk89q/intake/parametric/provider/StringProvider.java#L72
)

use case would be allowing an empty text arg. you could probably also use
an @optional https://github.com/optional @text https://github.com/text,
but that allows it to be null afaik, meaning you need to check if it was
specified or not.

@wizjany
Copy link

wizjany commented Aug 7, 2016

Ah, missed that check. Yes, both of the first conditionals would need to be changed, however i think there should still be a mechanism for allowing an empty string.

@literalplus
Copy link
Contributor Author

Having scanned these few lines on code so often in the past day, I doubt
there's a mechanism if the next() and hasNext() methods do what I think
they do.

I'll check out the whole project and write a unit test to see if any of the
implementations allow empty strings.

-- Above message was sent from my mobile phone. There may and will be all
kinds of errors included.

On 7 Aug 2016 03:45, "Wizjany" notifications@github.com wrote:

Ah, missed that check. Yes, both of the first conditionals would need to
be changed, however i think there should still be a mechanism for allowing
an empty string.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#25 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAhY_osnhv90qY1uF6ht_K1ajCTzQkqQks5qdTjTgaJpZM4JeUNx
.

literalplus and others added 2 commits August 7, 2016 16:26
This commit simplifies TextProvider to be a lot clearer and also avoid swallowing an unnecessary exception.

Furthermore, it changes its behaviour so that created text does not always have a space at the end. Usually, people don't mean to add an unnecessary space at the end of their text argument if they don't put more text.

The motivation for this commit is that I am currently experiencing the space problem in my usage of this library.

Thanks!
@literalplus
Copy link
Contributor Author

literalplus commented Aug 7, 2016

Okay, actually, you were right. Both implementations do allow to specify empty text. However, this only works by having a trailing space at the end of the command line, which I doubt is something the average user would think of.

Anyways, I provided unit tests for the behaviour of the class. They fail for the previous version because that one always ends the input with a space no matter what. From my point of view, that is clearly incorrect behaviour. As a developer, I would assume that if I pass some args with text, I would get with text instead of with text (note the trailing space). I cannot imagine a use case where you'd want that trailing space even if the user didn't even specify it.

The reason both implementations allow for empty strings (somewhat) is the way Java's String#split(...) method works: If a trailing space is found, an empty string is appended to the array. Provided tests verify that my changes do not break the possibility to provide an empty string, and that they in fact fix what I believe is incorrect behaviour.

Update: Here are the test results for old and new implementations, for reference.

literalplus added a commit to literalplus/intake-spigot that referenced this pull request Aug 11, 2016
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