cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

Using CharSequence over String in get(String) #118

Closed KrzysztofKowalczyk closed 4 years ago

KrzysztofKowalczyk commented 5 years ago

An example change to limit some confusing errors caused by get(String).

Why not to use CharSequence everywhere? Don't want to change everything and equality of GStrings is a bit suprising when casting is involved.

For instance:

def a = "foo"
def b = "foo"
assert a == "$a"
assert "$a" == "$a"
assert "$a" == "$b"
// but
assert ((CharSequence)"a") != ((CharSequence)"$b")

Essentially, GString is being automatically converted to String when String is being used but it is not converted when CharSequence is being used. So it would not be equal to equivalent String anymore (wrong type).

Hence if one want to use CharSequence in API first thing to do is to convert it to String.

cjstehno commented 5 years ago

Thanks I will take a look at this and cut a release this week.

cjstehno commented 4 years ago

I am currently working on v2 so this PR is no longer valid, but I will look at incorporating these changes into the release. Thanks!