xref: /llvm-project/llvm/unittests/ADT/SmallVectorExtrasTest.cpp (revision f9dca5bdbb0fccc0c12c7f8f1a190fa05f72f90d)
1 //===- llvm/unittest/ADT/SmallVectorExtrasTest.cpp ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // SmallVectorExtras unit tests.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ADT/SmallVectorExtras.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
16 
17 #include <type_traits>
18 #include <vector>
19 
20 using testing::ElementsAre;
21 
22 namespace llvm {
23 namespace {
24 
25 TEST(SmallVectorExtrasTest, FilterToVector) {
26   std::vector<int> Numbers = {0, 1, 2, 3, 4};
27   auto Odd = filter_to_vector<2>(Numbers, [](int X) { return (X % 2) != 0; });
28   static_assert(std::is_same_v<decltype(Odd), SmallVector<int, 2>>);
29   EXPECT_THAT(Odd, ElementsAre(1, 3));
30 
31   auto Even = filter_to_vector(Numbers, [](int X) { return (X % 2) == 0; });
32   static_assert(std::is_same_v<decltype(Even), SmallVector<int>>);
33   EXPECT_THAT(Even, ElementsAre(0, 2, 4));
34 }
35 
36 } // end namespace
37 } // namespace llvm
38