MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / TEST

Function TEST

oneflow/maybe/just_test.cpp:26–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24using namespace oneflow::maybe;
25
26TEST(Just, MaybeBasic) {
27 using Error = simple::StackedError<std::string>;
28 using MaybeInt = Maybe<int, Error>;
29
30 auto f = [](int x) -> MaybeInt {
31 if (x > 10 || x < 0) { return Error{"not in range"}; }
32
33 return x + 10;
34 };
35
36 auto g = [&f](int x) -> MaybeInt {
37 if (x == 15) { return Error{"invalid value"}; }
38
39 return JUST(f(x)) * 2;
40 };
41
42 auto h = [&g](int x) -> MaybeInt { return JUST(g(x)) + 2; };
43
44 ASSERT_EQ(CHECK_JUST(h(0)), 22);
45
46 ASSERT_DEATH( // NOLINT(cppcoreguidelines-avoid-goto)
47 CHECK_JUST(h(11)),
48 R"(not in range.*(lambda|operator\(\)).*f\(x\).*(lambda|operator\(\)).*g\(x\).*TestBody.*h\(11\))");
49
50 ASSERT_DEATH( // NOLINT(cppcoreguidelines-avoid-goto)
51 CHECK_JUST(h(15)), R"(invalid value.*(lambda|operator\(\)).*g\(x\).*TestBody.*h\(15\))");
52
53 ASSERT_EQ(details::JustPrivateScope::StackedError(h(12)).StackSize(), 2);
54 ASSERT_EQ(details::JustPrivateScope::StackedError(h(15)).StackSize(), 1);
55}
56
57TEST(Just, MaybeVoid) {
58 using Error = simple::StackedError<std::string>;

Callers

nothing calls this directly

Calls 8

gFunction · 0.85
to_stringFunction · 0.85
StackedErrorFunction · 0.70
ErrorFunction · 0.70
fFunction · 0.50
StackSizeMethod · 0.45
ErrorMethod · 0.45
StackElemMethod · 0.45

Tested by

no test coverage detected