petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
254 stars 28 forks source link

Not require argument matchers for all arguments #48

Closed lkysow closed 6 years ago

lkysow commented 6 years ago

I often want to mix Any matchers (ex. AnyString()) with specific matchers ex. foo.

petergtz commented 6 years ago

I'm not sure I understand this one. Are you asking for something like this:

When(contactList.getContactByFullName("Dan", AnyString())).thenReturn(Contact{...})

If so, that's unfortunately not possible with the current syntax. It's a technical limitation defined by how the framework works. It simply wouldn't know afterwards which matcher should go to which parameter.

That's why the only way to do this is through:

When(contactList.getContactByFullName(EqString("Dan"), AnyString())).thenReturn(Contact{...})
lkysow commented 6 years ago

Yes, that's what I'm asking for. I figured there was a very good reason why we couldn't accomplish it but maybe we could keep this open to see if someone can find a way?

petergtz commented 6 years ago

@lkysow OK, yes, makes sense. I'm definitely open for suggestions. I haven't even thought about this one, because Mockito which I borrowed most of the syntax from has also not solved this one. But again, I'm open for suggestions.

lkysow commented 6 years ago

I think that given the Eq matchers are autogenerated this isn't really an issue any more so you could close?

petergtz commented 6 years ago

Agree, let's close it for now. And I'll keep in the back of my head and am in general happy to re-open this when someone has a good idea to accomplish this.