package co.unruly.control.Result;

import org.junit.Test;

import java.util.function.Function;

import static co.unruly.control.Result.Match.ifIs;
import static co.unruly.control.Result.Match.ifType;
import static co.unruly.control.Result.Match.match;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class MatchTest {

    @Test
    public void canMatchOnType() {
        Function<A, String> matchByType = match(
            ifType(B.class, B::messageForB),
            ifType(C.class, C::messageForC)
        ).otherwise(A::message);

        assertThat(matchByType.apply(new A("Cheese")), is("Cheese"));
        assertThat(matchByType.apply(new B("Ketchup")), is("I'm a B and I say Ketchup"));
        assertThat(matchByType.apply(new C("Pickles")), is("I'm a C and I say Pickles"));
    }

    static class A {
        private final String msg;


        A(String msg) {
            this.msg = msg;
        }

        String message() {
            return msg;
        }
    }

    static class B extends A {

        B(String msg) {
            super(msg);
        }

        String messageForB() {
            return "I'm a B and I say " + message();
        }
    }

    static class C extends A {

        C(String msg) {
            super(msg);
        }

        String messageForC() {
            return "I'm a C and I say " + message();
        }
    }

}
@@ -138,117 +138,9 @@
 tch.
-ifIs;%0Aimport static co.unruly.control.Result.Match.ifType;%0Aimport static co.unruly.control.Result.Match.match
+*
 ;%0Aim
@@ -291,16 +291,30 @@
 chOnType
+WithFlowTyping
 () %7B%0A   
@@ -638,24 +638,24 @@
 Ketchup%22));%0A
-
         asse
@@ -731,32 +731,1491 @@
 kles%22));%0A    %7D%0A%0A
+    @Test%0A    public void canMatchOnValue() %7B%0A        Function%3CInteger, String%3E matchByType = match(%0A            ifEquals(4, x -%3E x + %22 sure looks like a 4 to me!%22),%0A            ifEquals(7, x -%3E x + %22 looks like one of them gosh-darned 7s?%22)%0A        ).otherwise(x -%3E %22I have no idea what a %22 + x + %22 is though...%22);%0A%0A        assertThat(matchByType.apply(3), is(%22I have no idea what a 3 is though...%22));%0A        assertThat(matchByType.apply(4), is(%224 sure looks like a 4 to me!%22));%0A        assertThat(matchByType.apply(6), is(%22I have no idea what a 6 is though...%22));%0A        assertThat(matchByType.apply(7), is(%227 looks like one of them gosh-darned 7s?%22));%0A    %7D%0A%0A    @Test%0A    public void canMatchOnTest() %7B%0A        Function%3CInteger, String%3E matchByType = match(%0A            ifIs((Integer x) -%3E x %25 2 == 0, x -%3E x + %22, well, that's one of those even numbers%22),%0A            ifIs(x -%3E x %3C 0,                x -%3E x + %22 is one of those banker's negative number thingies%22)%0A        ).otherwise(x -%3E x + %22 is a regular, god-fearing number for god-fearing folks%22);%0A%0A        assertThat(matchByType.apply(2), is(%222, well, that's one of those even numbers%22));%0A        assertThat(matchByType.apply(-6), is(%22-6, well, that's one of those even numbers%22));%0A        assertThat(matchByType.apply(3), is(%223 is a regular, god-fearing number for god-fearing folks%22));%0A        assertThat(matchByType.apply(-9), is(%22-9 is one of those banker's negative number thingies%22));%0A    %7D%0A%0A
     static class

Add tests for matching on value and arbitrary predicate