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

Add StringSubject.isEqualToIgnoreCase #181

Closed
wants to merge 1 commit into from

Conversation

ooxi
Copy link

@ooxi ooxi commented May 12, 2015

Sometimes you have to test for string equality while not caring about case sensitivity e.g. when you work with data coming from a case insensitive source (like MySQL with some collation). Includes unit tests.

CLA will follow.

Sometimes you have to test for string equality while not caring about case sensitivity e.g. when you work with data coming from a case insensitive source (like MySQL with some collation). Includes unit tests.
@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@ooxi
Copy link
Author

ooxi commented May 12, 2015

I signed it!

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@kluever
Copy link
Member

kluever commented May 12, 2015

Hi ooxi,

We discussed this idea a long time ago (internally), and these are the notes I was able to dig up:

Can we come up with a better name?

  • isEqualIgnoringCase(String)?
  • isEqualToIgnoringCase(String)?

But this raises the usual internationalization questions. We'd need to support ASCII only (by rejecting strings with non-ASCII characters or by just leaving those characters alone?) or else provide an ICU4J extension to Truth.

We should probably look at potential callers to see how many there are and whether they need i18n.

So I've got a job running right now to see how many callers we'd potentially have for this method...will get back to you.

@kluever
Copy link
Member

kluever commented May 12, 2015

Of all the calls to String.equalsIgnoreCase(String) in google's code base, only 1.25% were being used in conjunction with JUnit's assertTrue/assertFalse, so I'm a bit skeptical about this feature...

Can you explain a bit more about "MySQL with collation" and why it's case insensitive?

@ooxi
Copy link
Author

ooxi commented May 13, 2015

A couple of applictions use database schemata with a case insensitive charset, for example OXID eShop (an e-commerce system using MySQL as database backend) or SAP Business One (a business management software using MSSQL as database backend). Both use text identifiers for object identification so if you want to check if order X references customer Y you have to check for "Y" in a case insensitive fashion.

I can understand if this feature gets rejected because of naming or i18n issues. But when developing with a case insensitive source a feature like this sure has many use cases :)

@kluever
Copy link
Member

kluever commented May 13, 2015

Thanks for that additional info. I'm gonna leave this FR open for now. If we get additional, substantial requests for this feature, we'll re-investigate. Thanks again!

@dimo414
Copy link
Contributor

dimo414 commented May 23, 2017

I think something like fuzzy Truth is the way forward here, if we decide this is worth doing.

@ooxi
Copy link
Author

ooxi commented May 26, 2017

I did not know about fuzzy truth when posting this pull request. I will play around with it but it really looks like covering my usecase quite nicely while being much more general

@ooxi
Copy link
Author

ooxi commented May 26, 2017

While Fuzzy Truth handles this problem quite nice it does not solve my use case since StringSubject does not implement comparingValuesUsing.

@dimo414
Copy link
Contributor

dimo414 commented May 26, 2017

Right, Fuzzy Truth is a relatively new feature, and it's currently only for use with collections. By "way forward" I meant that adding similar functionality to StringSubject would probably make more sense than adding individual comparison modifiers (e.g. what about .containsIgnoreCase(), or locale-aware case-insensitive assertions).

@ooxi
Copy link
Author

ooxi commented May 27, 2017

@dimo414 I agree that enabling fuzzy test behavior injection into other subjects would not only solve my use case but be easily expandable and thus quite likely the right way forward

@cpovirk
Copy link
Member

cpovirk commented Sep 19, 2018

Case-insensitive comparisons finally made Truth 0.41:
https://google.github.io/truth/api/latest/com/google/common/truth/StringSubject.html#ignoringCase--

@cpovirk cpovirk closed this Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants