Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/ADT/FallibleIteratorTest.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | TEST(FallibleIteratorTest, BasicSuccess) { | ||||
FallibleCollectionWalker begin(C, 0); | FallibleCollectionWalker begin(C, 0); | ||||
FallibleCollectionWalker end(C, 2); | FallibleCollectionWalker end(C, 2); | ||||
Error Err = Error::success(); | Error Err = Error::success(); | ||||
for (auto &Elem : | for (auto &Elem : | ||||
make_fallible_range<FallibleCollectionWalker>(begin, end, Err)) | make_fallible_range<FallibleCollectionWalker>(begin, end, Err)) | ||||
EXPECT_TRUE(Elem.isValid()); | EXPECT_TRUE(Elem.isValid()); | ||||
cantFail(std::move(Err)); | llvm_cantFail(std::move(Err)); | ||||
} | } | ||||
TEST(FallibleIteratorTest, BasicFailure) { | TEST(FallibleIteratorTest, BasicFailure) { | ||||
// Check that a iteration failure (due to the InvalidLink state on element one | // Check that a iteration failure (due to the InvalidLink state on element one | ||||
// of the fallible collection) breaks out of the loop and raises an Error. | // of the fallible collection) breaks out of the loop and raises an Error. | ||||
FallibleCollection C({{ValidItem, ValidLink}, {ValidItem, InvalidLink}}); | FallibleCollection C({{ValidItem, ValidLink}, {ValidItem, InvalidLink}}); | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | FallibleCollection C({{ValidItem, ValidLink}, | ||||
{InvalidItem, InvalidLink}}); | {InvalidItem, InvalidLink}}); | ||||
FallibleCollectionWalkerWithStructDeref begin(C, 0); | FallibleCollectionWalkerWithStructDeref begin(C, 0); | ||||
{ | { | ||||
Error Err = Error::success(); | Error Err = Error::success(); | ||||
auto I = make_fallible_itr(begin, Err); | auto I = make_fallible_itr(begin, Err); | ||||
EXPECT_TRUE(I->isValid()); | EXPECT_TRUE(I->isValid()); | ||||
cantFail(std::move(Err)); | llvm_cantFail(std::move(Err)); | ||||
} | } | ||||
{ | { | ||||
Error Err = Error::success(); | Error Err = Error::success(); | ||||
const auto I = make_fallible_itr(begin, Err); | const auto I = make_fallible_itr(begin, Err); | ||||
EXPECT_TRUE(I->isValid()); | EXPECT_TRUE(I->isValid()); | ||||
cantFail(std::move(Err)); | llvm_cantFail(std::move(Err)); | ||||
} | } | ||||
} | } | ||||
TEST(FallibleIteratorTest, CheckDerefToExpectedSupport) { | TEST(FallibleIteratorTest, CheckDerefToExpectedSupport) { | ||||
// Check that the fallible_iterator wrapper forwards value types, in | // Check that the fallible_iterator wrapper forwards value types, in | ||||
// particular llvm::Expected, correctly. | // particular llvm::Expected, correctly. | ||||
Show All 15 Lines | TEST(FallibleIteratorTest, CheckDerefToExpectedSupport) { | ||||
Expected<Item> V2 = *I; | Expected<Item> V2 = *I; | ||||
EXPECT_THAT_ERROR(V2.takeError(), Failed()); | EXPECT_THAT_ERROR(V2.takeError(), Failed()); | ||||
++I; | ++I; | ||||
EXPECT_NE(I, E); // Implicitly check error. | EXPECT_NE(I, E); // Implicitly check error. | ||||
Expected<Item> V3 = *I; | Expected<Item> V3 = *I; | ||||
EXPECT_THAT_ERROR(V3.takeError(), Succeeded()); | EXPECT_THAT_ERROR(V3.takeError(), Succeeded()); | ||||
++I; | ++I; | ||||
EXPECT_EQ(I, E); | EXPECT_EQ(I, E); | ||||
cantFail(std::move(Err)); | llvm_cantFail(std::move(Err)); | ||||
} | } | ||||
} // namespace | } // namespace |