| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- //
- // match.t.h
- // case-matcher
- //
- // Created by Sam Jaffe on 2/3/17.
- //
- #pragma once
- #include "match.hpp"
- #include <cxxtest/TestSuite.h>
- struct example {
- example(long in) : i(in) {}
- long i;
- };
- bool operator==(example const & a, example const & b) {
- return a.i == b.i;
- }
- class case_matcher_TestSuite : public CxxTest::TestSuite {
- public:
- example const ex{1};
- bool const b{true};
- public:
- void test_match_explicit_case() {
- match(ex, b) {
- with(example{1}, true) {}
- nomatch() { TS_FAIL("Unable to match"); }
- TS_ASSERT( ! _matcher_local.unmatched() );
- }
- }
-
- void test_nomatch_incorrect_case() {
- match(ex, b) {
- with(example{1}, false) { TS_FAIL("Incorrect match!"); }
- TS_ASSERT( _matcher_local.unmatched() );
- }
- }
-
- void test_match_fallback_case() {
- match(ex, b) {
- with(example{1}, false) { TS_FAIL("Incorrect match!"); }
- with(example{1}, true) {}
- TS_ASSERT( !_matcher_local.unmatched() );
- }
- }
-
- void test_match_any_case() {
- match(ex, b) {
- with(example{1}, false) { TS_FAIL("Incorrect match!"); }
- with(matcher::any, true) {}
- TS_ASSERT( !_matcher_local.unmatched() );
- }
- }
-
- void test_match_multiple_cases() {
- int hits{0};
- match(ex, b) {
- with(matcher::any, true) { ++hits; }
- and_with(example{1}, matcher::any) { ++hits; }
- }
- TS_ASSERT_EQUALS(hits, 2);
- }
- };
|