Skip to content
This repository
Browse code

removed compilation errors

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

0 comments on commit 9fb359a

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