Permalink
Browse files

replaced iterable matcher with collection matcher

  • Loading branch information...
1 parent 316d1ce commit 2d1b53fb0bc959dd6893a7bb422de1049fe32a54 @danseid committed Dec 7, 2012
View
@@ -146,18 +146,18 @@ Matchers to use on string objects
"string" should contain all of("s", "t", "a") //✘
```
-###Iterable
-Matchers to use on Iterable<T>
+###Collection
+Matchers to use on ```Collection<T>``` object
####contain | !contain item
```kotlin
listOf(1, 2, 3) should contain item 3 //✔
setOf(1, 2, 3) should contain item 2 //✔
listOf("1", "2") should contain item "2" //✔
- listOf(1, 2, 3) should contain item 4
+ listOf(1, 2, 3) should contain item 4 //✘
```
###Map
-Matchers to use on Map<K,V>
+Matchers to use on ```Map<K,V>``` object
####contain | !contain item
```kotlin
mapOf(1 to "1", 2 to "2", 3 to "3") should contain item (1 to "1") //✔
@@ -19,3 +19,12 @@ package org.katchers
* @author Daniel Seidler
* @since 2012/12/07
*/
+
+
+class CollectionContainMatcher<T>(override val target: Collection<T>): Matcher<Collection<T>>{
+ fun item(el: T) = if(!target.contains(el)) fail("$target contains $el", "$target doesn't contain $el")
+}
+
+class CollectionNotContainMatcher<T>(override val target: Collection<T>): Matcher<Collection<T>>{
+ fun item(el: T) = if(target.contains(el)) fail("$target should not contain $el", "$target contains $el")
+}
@@ -1,29 +0,0 @@
-/*
- * Copyright 2012 Daniel Seidler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.katchers
-
-/**
- * @author Daniel Seidler
- * @since 2012/12/06
- */
-
-class IterableContainMatcher<T>(override val target: Iterable<T>): Matcher<Iterable<T>>{
- fun item(el: T) = if(!target.contains(el)) fail("$target contains $el", "$target doesn't contain $el")
-}
-
-class IterableNotContainMatcher<T>(override val target: Iterable<T>): Matcher<Iterable<T>>{
- fun item(el: T) = if(target.contains(el)) fail("$target should not contain $el", "$target contains $el")
-}
@@ -22,7 +22,6 @@ package org.katchers
// Any must be
// Any must
-
public fun <T>T.must(val verb: BE): AnyBeMatcher<T> = AnyBeMatcher(this)
public fun <T>T.must(val verb: NOTBE): AnyNotBeMatcher<T> = AnyNotBeMatcher(this)
public fun <T>T.must(val verb: MATCH): AnyMatchMatcher<T> = AnyMatchMatcher(this)
@@ -42,16 +41,13 @@ public fun String.must(val verb: NOTCONTAIN): StringNotContainMatcher = StringNo
public inline fun Number.must(val verb: BE): NumberBeMatcher = NumberBeMatcher(this)
public inline fun Number.must(val verb: NOTBE): NumberNotBeMatcher = NumberNotBeMatcher(this)
-
//() -> Unit must fail
public fun <T: () -> Any>T.must(verb: NOTFAIL): FunctionNotFailMatcher<T> = FunctionNotFailMatcher(this)
public fun <T: () -> Any>T.must(verb: FAIL): FunctionFailMatcher<T> = FunctionFailMatcher(this)
-
-//Iterables
-public fun <T>Iterable<T>.must(verb: CONTAIN): IterableContainMatcher<T> = IterableContainMatcher<T>(this)
-public fun <T>Iterable<T>.must(verb: NOTCONTAIN): IterableNotContainMatcher<T> = IterableNotContainMatcher<T>(this)
-
+//Collection
+public fun <T>Collection<T>.must(verb: CONTAIN): CollectionContainMatcher<T> = CollectionContainMatcher<T>(this)
+public fun <T>Collection<T>.must(verb: NOTCONTAIN): CollectionNotContainMatcher<T> = CollectionNotContainMatcher<T>(this)
//Maps
public fun <R,T>Map<R,T>.must(verb: CONTAIN): MapContainMatcher<R,T> = MapContainMatcher<R,T>(this)
@@ -48,13 +48,11 @@ public inline fun Number.should(val verb: NOTBE): NumberNotBeMatcher = NumberNot
public fun <T: () -> Any>T.should(verb: NOTFAIL): FunctionNotFailMatcher<T> = FunctionNotFailMatcher(this)
public fun <T: () -> Any>T.should(verb: FAIL): FunctionFailMatcher<T> = FunctionFailMatcher(this)
+//Collection
+public fun <T>Collection<T>.should(verb: CONTAIN): CollectionContainMatcher<T> = CollectionContainMatcher<T>(this)
+public fun <T>Collection<T>.should(verb: NOTCONTAIN): CollectionNotContainMatcher<T> = CollectionNotContainMatcher<T>(this)
-//Iterables
-public fun <T>Iterable<T>.should(verb: CONTAIN): IterableContainMatcher<T> = IterableContainMatcher<T>(this)
-public fun <T>Iterable<T>.should(verb: NOTCONTAIN): IterableNotContainMatcher<T> = IterableNotContainMatcher<T>(this)
-
-
-//Maps
+//Map
public fun <R,T>Map<R,T>.should(verb: CONTAIN): MapContainMatcher<R,T> = MapContainMatcher<R,T>(this)
public fun <R,T>Map<R,T>.should(verb: NOTCONTAIN): MapNotContainMatcher<R,T> = MapNotContainMatcher<R,T>(this)
@@ -30,7 +30,7 @@ Suite.SuiteClasses(
javaClass<NumberMatcherTest>(),
javaClass<NumbersTest>(),
javaClass<NumberRangesMatcherTest>(),
- javaClass<IterableMatcherTest>(),
+ javaClass<CollectionMatcherTest>(),
javaClass<MapMatcherTest>()
@@ -1,36 +0,0 @@
-/*
- * Copyright 2012 Daniel Seidler
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import org.junit.Test as test
-import org.katchers.*
-
-/**
- * @author Daniel Seidler
- * @since 2012/12/06
- */
-public class IterableMatcherTest {
-
- test fun listContainsElement() {
- listOf(1, 2, 3) should contain item 3
- setOf(1, 2, 3) should contain item 2
- listOf("1", "2") should contain item "2"
- { listOf(1, 2, 3) should contain item 4 } should fail with assertionError
-
- listOf(1, 2, 3) should !contain item 4
- listOf("1", "2") should !contain item "3"
- { listOf(1, 2, 3) should !contain item 3 } should fail with assertionError
- }
-
-}

0 comments on commit 2d1b53f

Please sign in to comment.