-
Notifications
You must be signed in to change notification settings - Fork 79
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 .Exists() to assertions #46
Comments
A question -- what exactly would this test? is it a non-null check? I don't know that the Exists test makes sense for Go... Usually it means a check if variable exists at all in the current scope, correct? Pretty hard to get something like that past the Go compiler, unless there's some obvious case I'm overlooking |
@t3hmrman we came up with two scenarios where this may be useful:
strings having >0 length What do you think? |
So I think the only place it makes sense is when dealing with pointers -- that's the only place it feels like to me that checking if something "exists" makes sense. You get a pointer to the thing, and you want to make sure that the thing is actually there (and not null/nil, the empty thing), then you check if it "exists". If it were to take on only that meaning, it would be synonymous with a not-null check. But then again, if that were the case, then I would rather write something like g.Assert(err).IsNotNull() and get that easy readability... I think a lot of the point of matchers is the readability they add, and that has a lot to do with the semantics of the statement. If you have something like g.Assert(str).Exists(), I don't think it would be as clear as something like g.Assert(len(str)).IsGreaterThanZero() or something like that. Matchers give us that declarative use, but I think you lose some of that for Exists on other types. I am hung up on the english semantics of it -- exists just doesn't feel like something I would need to check in Go. The functionality you're suggesting though would go great with just the general Assert function. like if I could do g.Assert(x) by itself, and be assured that it had all those other implementations I could do stuff like: or something, but even that's a little cludgy, and not really declarative enough. |
Maybe something like |
So we can do:
This should decide what to do for each type.
The text was updated successfully, but these errors were encountered: