Skip to content
Browse files

removed compilation errors

  • Loading branch information...
1 parent 38e4c0b commit 9fb359a1ca93be8ec303f96c5f18fa6649a7eab6 Daniel Seidler @Work committed Nov 20, 2012
View
14 src/main/kotlin/spec/matchers/AnyMatcher.kt
@@ -15,19 +15,17 @@ trait Matcher {
}
open class AnyBeMatcher<T>(val target: T): Matcher {
- fun equal(value: T) {
- { if (value != target) fail(value, target) }
- }
- open fun any(values: List<T>) {
+ inline fun equal(value: T) = if (value != target) fail(value, target)
+
+ open inline fun any(values: List<T>) {
if(!values.any { it == target }) fail("any of $values", target)
}
}
open class AnyNotBeMatcher<T>(val target: T): Matcher {
- fun equal(value: T) {
- if (value == target) fail(value, target)
- }
- open fun any(values: List<T>) {
+ inline fun equal(value: T) = if (value == target) fail(value, target)
+
+ open inline fun any(values: List<T>) {
if(values any { it == target }) fail("not any of $values", target)
}
}
View
6 src/main/kotlin/spec/matchers/HelperFunctions.kt
@@ -8,13 +8,11 @@ package spec.matchers
import kotlin.test.*
-fun <T>fail(expected: T, got: T) : Unit {
+inline fun <T>fail(expected: T, got: T) : Unit {
fail("""
expected: <$expected>
got: <$got>
""")
}
-fun <T>of(vararg values: T) : List<T> {
- return values.toList()
-}
+inline fun <T>of(vararg values: T): List<T> = values.toList()
View
29 src/main/kotlin/spec/matchers/Should.kt
@@ -1,24 +1,25 @@
package spec.matchers
-
/**.
* User: Daniel Seidler
* Date: 15.11.12
* Time: 12:22
*/
-public fun <T>T.should(val verb: BE): AnyBeMatcher<T> {
- return AnyBeMatcher(this)
-}
-
-public fun <T>T.should(val verb: NOTBE): AnyNotBeMatcher<T> {
- return AnyNotBeMatcher(this)
-}
+// ANY MATCHER
+public fun <T>T.should(val verb: BE): AnyBeMatcher<T> = AnyBeMatcher(this)
+public fun <T>T.should(val verb: NOTBE): AnyNotBeMatcher<T> = AnyNotBeMatcher(this)
+//STRING MATCHER
+public fun String.should(val verb: HAVE): StringHaveMatcher = StringHaveMatcher(this)
+public fun String.should(val verb: NOTHAVE): StringNotHaveMatcher = StringNotHaveMatcher(this)
+public fun String.should(val verb: START): StringStartMatcher = StringStartMatcher(this)
+public fun String.should(val verb: NOTSTART): StringNotStartMatcher = StringNotStartMatcher(this)
+public fun String.should(val verb: END): StringEndMatcher = StringEndMatcher(this)
+public fun String.should(val verb: NOTEND): StringNotEndMatcher = StringNotEndMatcher(this)
+public fun String.should(val verb: CONTAIN): StringContainMatcher = StringContainMatcher(this)
+public fun String.should(val verb: NOTCONTAIN): StringNotContainMatcher = StringNotContainMatcher(this)
-public fun String.should(verb: Verb): StringMatcher {
- return StringMatcher(this, verb)
-}
-public fun <R>jet.Function0<R>.should(verb: Verb): FunctionFailMatcher<R>{
- return FunctionFailMatcher(this)
-}
+//FUNCTION MATCHER
+public fun <R>jet.Function0<R>.should(verb: FAIL): FunctionFailMatcher<R> = FunctionFailMatcher(this)
+public fun <R>jet.Function0<R>.should(verb: NOTFAIL): FunctionNotFailMatcher<R> = FunctionNotFailMatcher(this)
View
8 src/main/kotlin/spec/matchers/StringMatcher.kt
@@ -53,15 +53,11 @@ class StringMatcher(target: String, verb: Verb): AnyMatcher<String>(target, verb
*/
class StringHaveMatcher(val target: String): Matcher{
- fun length(expected: Int) {
-
- }
+ inline fun length(expected: Int) = target.length() should be equal expected
}
class StringNotHaveMatcher(val target: String): Matcher{
- fun length(expected: Int) {
-
- }
+ inline fun length(expected: Int) = target.length() should !be equal expected
}
class StringStartMatcher(val target: String): Matcher{
View
4 src/test/kotlin/ShouldTest.kt
@@ -12,8 +12,4 @@ public class ShouldTest {
test fun shouldBeAnyMatcher() {
assertTrue(Any().should(be) is AnyBeMatcher<Any>)
}
-
- test fun shouldBeStringMatcher() {
- assertTrue(String().should(be) is StringMatcher)
- }
}
View
4 src/test/kotlin/StringMatcherTest.kt
@@ -13,6 +13,10 @@ public class StringMatcherTest {
"a" should have length 1
"a" should !have length 0
"" should !have length 1
+
+ {"" should have length 1} should fail with AssertionError();
+ {"" should !have length 0} should fail with AssertionError()
+
}
test fun with() {

0 comments on commit 9fb359a

Please sign in to comment.
Something went wrong with that request. Please try again.