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
15using namespace llvm;
16
17namespace {
18
19TEST(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 c: Doodles, os&: OS, each_fn: [&](const char *Name) { OS << Name << "doodle"; }, separator: ", ");
27
28 EXPECT_EQ(OS.str(), "goldendoodle, bernadoodle, labradoodle");
29}
30
31TEST(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(c: LongDogs, os&: OS);
38
39 EXPECT_EQ(OS.str(), "dachshund, doxie, dackel, teckel");
40}
41
42} // anonymous namespace
43

source code of llvm/unittests/ADT/Interleave.cpp