Skip to content

Commit

Permalink
[ADT] Follow up to fix bug in "Add makeVisitor to STLExtras.h"
Browse files Browse the repository at this point in the history
Address mistakenly comparing the pointer values of two C-style strings
rather than comparing their contents in the unit tests for makeVisitor,
added in 6d6f35e
  • Loading branch information
slinder1 committed Jul 1, 2021
1 parent c360553 commit 83887df
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions llvm/unittests/ADT/STLExtrasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ TEST(STLExtrasTest, MakeVisitorOneCallable) {

TEST(STLExtrasTest, MakeVisitorTwoCallables) {
auto Visitor =
makeVisitor([](int) { return "int"; }, [](std::string) { return "str"; });
EXPECT_EQ(Visitor(42), "int");
EXPECT_EQ(Visitor("foo"), "str");
makeVisitor([](int) { return 0; }, [](std::string) { return 1; });
EXPECT_EQ(Visitor(42), 0);
EXPECT_EQ(Visitor("foo"), 1);
}

TEST(STLExtrasTest, MakeVisitorCallableMultipleOperands) {
Expand All @@ -793,20 +793,20 @@ TEST(STLExtrasTest, MakeVisitorDefaultCase) {
{
auto Visitor = makeVisitor([](int I) { return I + 100; },
[](float F) { return F * 2; },
[](auto) { return "unhandled type"; });
[](auto) { return -1; });
EXPECT_EQ(Visitor(24), 124);
EXPECT_EQ(Visitor(2.f), 4.f);
EXPECT_EQ(Visitor(2.), "unhandled type");
EXPECT_EQ(Visitor(Visitor), "unhandled type");
EXPECT_EQ(Visitor(2.), -1);
EXPECT_EQ(Visitor(Visitor), -1);
}
{
auto Visitor = makeVisitor([](auto) { return "unhandled type"; },
auto Visitor = makeVisitor([](auto) { return -1; },
[](int I) { return I + 100; },
[](float F) { return F * 2; });
EXPECT_EQ(Visitor(24), 124);
EXPECT_EQ(Visitor(2.f), 4.f);
EXPECT_EQ(Visitor(2.), "unhandled type");
EXPECT_EQ(Visitor(Visitor), "unhandled type");
EXPECT_EQ(Visitor(2.), -1);
EXPECT_EQ(Visitor(Visitor), -1);
}
}

Expand Down

0 comments on commit 83887df

Please sign in to comment.