xref: /llvm-project/llvm/unittests/ADT/Interleave.cpp (revision 52b48a70d3752f9db36ddcfd26d0451c009b19fc)
1e84a7572SJon Roelofs //===- unittests/ADT/Interleave.cpp - Interleave unit tests ---------------===//
2e84a7572SJon Roelofs //
3e84a7572SJon Roelofs // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e84a7572SJon Roelofs // See https://llvm.org/LICENSE.txt for license information.
5e84a7572SJon Roelofs // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e84a7572SJon Roelofs //
7e84a7572SJon Roelofs //===----------------------------------------------------------------------===//
8e84a7572SJon Roelofs 
9e84a7572SJon Roelofs #include "llvm/ADT/STLExtras.h"
10e84a7572SJon Roelofs #include "llvm/ADT/SmallVector.h"
11e84a7572SJon Roelofs #include "llvm/Support/raw_ostream.h"
12e84a7572SJon Roelofs 
13e84a7572SJon Roelofs #include "gtest/gtest.h"
14e84a7572SJon Roelofs 
15e84a7572SJon Roelofs using namespace llvm;
16e84a7572SJon Roelofs 
17e84a7572SJon Roelofs namespace {
18e84a7572SJon Roelofs 
19e84a7572SJon Roelofs TEST(InterleaveTest, Interleave) {
20e84a7572SJon Roelofs   std::string Str;
21e84a7572SJon Roelofs   raw_string_ostream OS(Str);
22e84a7572SJon Roelofs 
23e84a7572SJon Roelofs   // Check that interleave works on a SmallVector.
24e84a7572SJon Roelofs   SmallVector<const char *> Doodles = {"golden", "berna", "labra"};
25e84a7572SJon Roelofs   interleave(
26e84a7572SJon Roelofs       Doodles, OS, [&](const char *Name) { OS << Name << "doodle"; }, ", ");
27e84a7572SJon Roelofs 
28*52b48a70SJOE1994   EXPECT_EQ(Str, "goldendoodle, bernadoodle, labradoodle");
29e84a7572SJon Roelofs }
30e84a7572SJon Roelofs 
31e84a7572SJon Roelofs TEST(InterleaveTest, InterleaveComma) {
32e84a7572SJon Roelofs   std::string Str;
33e84a7572SJon Roelofs   raw_string_ostream OS(Str);
34e84a7572SJon Roelofs 
35e84a7572SJon Roelofs   // Check that interleaveComma uses ADL to find begin/end on an array.
36e84a7572SJon Roelofs   const StringRef LongDogs[] = {"dachshund", "doxie", "dackel", "teckel"};
37e84a7572SJon Roelofs   interleaveComma(LongDogs, OS);
38e84a7572SJon Roelofs 
39*52b48a70SJOE1994   EXPECT_EQ(Str, "dachshund, doxie, dackel, teckel");
40e84a7572SJon Roelofs }
41e84a7572SJon Roelofs 
42e84a7572SJon Roelofs } // anonymous namespace
43