xref: /aosp_15_r20/external/cronet/base/functional/overloaded_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/functional/overloaded.h"
6 
7 #include <string>
8 
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/abseil-cpp/absl/types/variant.h"
11 
12 namespace base {
13 
TEST(FunctionalTest,Overloaded)14 TEST(FunctionalTest, Overloaded) {
15   struct PackageA {};
16   struct PackageB {};
17 
18   absl::variant<PackageA, PackageB> var = PackageA();
19 
20   const std::string output =
21       absl::visit(Overloaded{[](const PackageA& pack) { return "PackageA"; },
22                              [](const PackageB& pack) { return "PackageB"; }},
23                   var);
24   EXPECT_EQ(output, "PackageA");
25 }
26 
27 }  // namespace base
28