MCPcopy Create free account
hub / github.com/BowenFu/matchit.cpp / TEST

Function TEST

test/matchit/legacy.cpp:24–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22int64_t func2() { return 12; }
23
24TEST(Match, test1)
25{
26 auto const matchFunc = [](int32_t input)
27 {
28 Id<int32_t> ii;
29 return match(input)(
30 pattern | 1 = func1, pattern | 2 = func2, pattern | or_(56, 59) = func2,
31 pattern | (_ < 0) = expr(-1), pattern | (_ < 10) = expr(-10),
32 pattern | and_(_<17, _> 15) = expr(16),
33 pattern | app(_ * _, _ > 1000) = expr(1000),
34 pattern | app(_ * _, ii) = expr(ii), pattern | ii = -ii,
35 pattern | _ = expr(111));
36 };
37 EXPECT_EQ(matchFunc(1), 1);
38 EXPECT_EQ(matchFunc(2), 12);
39 EXPECT_EQ(matchFunc(11), 121); // Id matched.
40 EXPECT_EQ(matchFunc(59), 12); // or_ matched.
41 EXPECT_EQ(matchFunc(-5), -1); // meet matched.
42 EXPECT_EQ(matchFunc(10), 100); // app matched.
43 EXPECT_EQ(matchFunc(100), 1000); // app > meet matched.
44 EXPECT_EQ(matchFunc(5), -10); // _ < 10 matched.
45 EXPECT_EQ(matchFunc(16), 16); // and_ matched.
46}
47
48TEST(Match, test2)
49{

Callers

nothing calls this directly

Calls 10

or_Function · 0.85
appFunction · 0.85
whenFunction · 0.85
fibFunction · 0.70
matchFunction · 0.50
exprFunction · 0.50
and_Function · 0.50
dsFunction · 0.50
matchedFunction · 0.50
not_Function · 0.50

Tested by

no test coverage detected