xref: /llvm-project/llvm/unittests/ADT/Interleave.cpp (revision 52b48a70d3752f9db36ddcfd26d0451c009b19fc)
1 //===- unittests/ADT/Interleave.cpp - Interleave unit tests ---------------===//
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 #include "llvm/ADT/STLExtras.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/Support/raw_ostream.h"
12 
13 #include "gtest/gtest.h"
14 
15 using namespace llvm;
16 
17 namespace {
18 
19 TEST(InterleaveTest, Interleave) {
20   std::string Str;
21   raw_string_ostream OS(Str);
22 
23   // Check that interleave works on a SmallVector.
24   SmallVector<const char *> Doodles = {"golden", "berna", "labra"};
25   interleave(
26       Doodles, OS, [&](const char *Name) { OS << Name << "doodle"; }, ", ");
27 
28   EXPECT_EQ(Str, "goldendoodle, bernadoodle, labradoodle");
29 }
30 
31 TEST(InterleaveTest, InterleaveComma) {
32   std::string Str;
33   raw_string_ostream OS(Str);
34 
35   // Check that interleaveComma uses ADL to find begin/end on an array.
36   const StringRef LongDogs[] = {"dachshund", "doxie", "dackel", "teckel"};
37   interleaveComma(LongDogs, OS);
38 
39   EXPECT_EQ(Str, "dachshund, doxie, dackel, teckel");
40 }
41 
42 } // anonymous namespace
43