// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java
// public interface Strings {
// 
//     static WithoutCapture<String, List<String>> Regex(String expression) {
//         return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression)));
//     }
// 
//     class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> {
//         private final Pattern expression;
// 
//         public RegularExpression(Pattern expression) {
//             this.expression = expression;
//         }
// 
//         @Override
//         public Optional<Result.WithoutCapture<List<String>>> unapply(String s) {
//             final Matcher matcher = expression.matcher(s);
//             if (matcher.matches()) {
//                 final List<String> strings = new ArrayList<>();
//                 for (int i = 0; i <= matcher.groupCount(); i += 1) {
//                     strings.add(s.substring(matcher.start(i), matcher.end(i)));
//                 }
//                 return Optional.of(Result.success(strings));
//             } else {
//                 return Optional.empty();
//             }
//         }
//     }
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Case.WithoutCapture<T, T> Any() {
//     return new Case0<T, T>(Optional::of).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Var.WithoutInnerCapture<T, T> Var() {
//     return Var(Any());
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java
// static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) {
//     return Entry(Constant(o1), Constant(o2));
// }
// 
// Path: src/main/java/org/smallibs/suitcase/utils/Functions.java
// public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) {
//     return params -> function.apply(params._1, params._2);
// }


import static org.smallibs.suitcase.utils.Functions.function;
import junit.framework.TestCase;
import org.junit.Test;
import org.smallibs.suitcase.cases.lang.Strings;
import java.util.HashMap;
import java.util.Map;
import static org.smallibs.suitcase.cases.core.Cases.Any;
import static org.smallibs.suitcase.cases.core.Cases.Var;
import static org.smallibs.suitcase.cases.lang.Maps.Entry;
    public void shouldRetrieveAndCaptureEntryUsingKeyRegexp() throws Exception {
        final Matcher<Map<String, String>, Boolean> matcher = Matcher.create();

        matcher.caseOf(Entry(Strings.Regex("1|2"), Var())).when(s -> s.equals("a")).then(true);

        final HashMap<String, String> map = new HashMap<String, String>() {{
            this.put("1", "a");
        }};

        TestCase.assertTrue(matcher.match(map));
    }

    @Test
    public void shouldNotRetrieveEntryUsingRegexp() throws Exception {
        final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();

        matcher.caseOf(Entry(1, Var("b"))).then(true);
        matcher.caseOf(Any()).then(false);

        final HashMap<Integer, String> map = new HashMap<Integer, String>() {{
            this.put(1, "a");
        }};

        TestCase.assertFalse(matcher.match(map));
    }

    @Test
    public void shouldMatchNonEmptyMap() throws Exception {
        final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();

// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java
// public interface Strings {
// 
//     static WithoutCapture<String, List<String>> Regex(String expression) {
//         return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression)));
//     }
// 
//     class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> {
//         private final Pattern expression;
// 
//         public RegularExpression(Pattern expression) {
//             this.expression = expression;
//         }
// 
//         @Override
//         public Optional<Result.WithoutCapture<List<String>>> unapply(String s) {
//             final Matcher matcher = expression.matcher(s);
//             if (matcher.matches()) {
//                 final List<String> strings = new ArrayList<>();
//                 for (int i = 0; i <= matcher.groupCount(); i += 1) {
//                     strings.add(s.substring(matcher.start(i), matcher.end(i)));
//                 }
//                 return Optional.of(Result.success(strings));
//             } else {
//                 return Optional.empty();
//             }
//         }
//     }
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Case.WithoutCapture<T, T> Any() {
//     return new Case0<T, T>(Optional::of).$();
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// static <T> Var.WithoutInnerCapture<T, T> Var() {
//     return Var(Any());
// }
// 
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java
// static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) {
//     return Entry(Constant(o1), Constant(o2));
// }
// 
// Path: src/main/java/org/smallibs/suitcase/utils/Functions.java
// public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) {
//     return params -> function.apply(params._1, params._2);
// }


// Path: src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java
import static org.smallibs.suitcase.utils.Functions.function;
import junit.framework.TestCase;
import org.junit.Test;
import org.smallibs.suitcase.cases.lang.Strings;
import java.util.HashMap;
import java.util.Map;
import static org.smallibs.suitcase.cases.core.Cases.Any;
import static org.smallibs.suitcase.cases.core.Cases.Var;
import static org.smallibs.suitcase.cases.lang.Maps.Entry;

    public void shouldRetrieveAndCaptureEntryUsingKeyRegexp() throws Exception {
        final Matcher<Map<String, String>, Boolean> matcher = Matcher.create();

        matcher.caseOf(Entry(Strings.Regex("1|2"), Var())).when(s -> s.equals("a")).then(true);

        final HashMap<String, String> map = new HashMap<String, String>() {{
            this.put("1", "a");
        }};

        TestCase.assertTrue(matcher.match(map));
    }

    @Test
    public void shouldNotRetrieveEntryUsingRegexp() throws Exception {
        final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();

        matcher.caseOf(Entry(1, Var("b"))).then(true);
        matcher.caseOf(Any()).then(false);

        final HashMap<Integer, String> map = new HashMap<Integer, String>() {{
            this.put(1, "a");
        }};

        TestCase.assertFalse(matcher.match(map));
    }

    @Test
    public void shouldMatchNonEmptyMap() throws Exception {
        final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();

        matcher.caseOf(Entry(Any(), Any())).then(true);