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

itemIndexOf, itemLastIndexOf matchers #27

Open
jeromedecoster opened this issue Apr 29, 2010 · 2 comments
Open

itemIndexOf, itemLastIndexOf matchers #27

jeromedecoster opened this issue Apr 29, 2010 · 2 comments

Comments

@jeromedecoster
Copy link

Hello,

I don't know if it's possible with the actual base Matchers, but it could be usefull to have something like this :

itemIndexOf, itemLastIndexOf

// I don't know if it's the best implementation :
assertThat(["a", "b", "c"], itemIndexOf("b", equalTo(0))) // FALSE
assertThat(["a", "b", "c"], itemIndexOf("b", lessThanOrEqualTo(1))) // TRUE
assertThat(["a", "b", "c"], itemIndexOf("e", equalTo(-1))) // TRUE

Usefull to :

  • test position an item in an array ("b" at [1])
  • test a position of 2 items in an array ("a" before "b")

Thanks !

@drewbourne
Copy link
Owner

I like this, and it is not possible with the existing matchers. Names will probably be indexOf() and lastIndexOf() to be similar to the Array/String methods of the same names.

assertThat(["a", "b", "c"], indexOf("b", equalTo(1)));
assertThat(["a", "b", "c"], indexOf("b", lessThanOrEqualTo(1)));
assertThat(["a", "b", "c"], indexOf("e", -1));
assertThat(["a", "b", "b"], lastIndexOf("b", greaterThanOrEqualTo(2)));

@jeromedecoster
Copy link
Author

Hey cool :)

If i'm not wrong, it miss a Matcher with 2 parameters ?

something like "CompareMatcher" or "CombinedMatcher" (I don't know if it's the best implementation) :
public class CompareMatcher implements Matcher
{
public function CompareMatcher(obj1:Object, obj2:Object)

What do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants