| 1 |
//===- StringMapTest.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 |
#include "llvm/Testing/ADT/StringMap.h" |
| 10 |
#include "llvm/ADT/StringMap.h" |
| 11 |
|
| 12 |
#include "gtest/gtest.h" |
| 13 |
#include <sstream> |
| 14 |
|
| 15 |
namespace llvm { |
| 16 |
namespace { |
| 17 |
|
| 18 |
TEST(StringMapTest, StringMapStream) { |
| 19 |
std::ostringstream OS; |
| 20 |
StringMap<int> Map; |
| 21 |
Map["A"] = 42; |
| 22 |
Map["Z"] = 35; |
| 23 |
Map["B"] = 7; |
| 24 |
OS << Map; |
| 25 |
|
| 26 |
EXPECT_EQ(OS.str(), R"({ |
| 27 |
{"A": 42}, |
| 28 |
{"B": 7}, |
| 29 |
{"Z": 35}, |
| 30 |
})"); |
| 31 |
} |
| 32 |
|
| 33 |
TEST(StringMapTest, NestedStringMapStream) { |
| 34 |
std::ostringstream OS; |
| 35 |
StringMap<StringMap<int>> Map; |
| 36 |
Map["Z"]; |
| 37 |
Map["A"]["Apple"] = 5; |
| 38 |
Map["B"]["Bee"] = 3; |
| 39 |
Map["A"]["Axe"] = 3; |
| 40 |
OS << Map; |
| 41 |
|
| 42 |
EXPECT_EQ(OS.str(), R"({ |
| 43 |
{"A": { |
| 44 |
{"Apple": 5}, |
| 45 |
{"Axe": 3}, |
| 46 |
}}, |
| 47 |
{"B": { |
| 48 |
{"Bee": 3}, |
| 49 |
}}, |
| 50 |
{"Z": { }}, |
| 51 |
})"); |
| 52 |
} |
| 53 |
|
| 54 |
} // namespace |
| 55 |
} // namespace llvm |