Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created July 28, 2020 12:22
Show Gist options
  • Save mbrandonw/fd78446ec6e43fb316684f8a71c2bd34 to your computer and use it in GitHub Desktop.
Save mbrandonw/fd78446ec6e43fb316684f8a71c2bd34 to your computer and use it in GitHub Desktop.

FB7828757

LocalizedStringKey equatable doesn't work as expected

It can be useful to assert again LocalizedStringKey in unit tests. Sometimes there is significant logic that goes into constructing a localized string and so it’s good to be able to write tests against that.

However, as soon as you apply some formatting to a string it seems to break equatability:

LocalizedStringKey("\(1)") == LocalizedStringKey("\(1)") // false

That is false when it seems reasonable that it would be true.

Ideally not only would that work, but you should also be able to test a non-formatted string against a formatted string so that you can verify that your logic executed correctly:

LocalizedStringKey("1") == LocalizedStringKey("\(1)") // false

But that is false too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment