[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / mlir / unittests / Support / IndentedOstreamTest.cpp
blob08a4de533c1c34d9421f347ba02c32beac94e701
1 //===- IndentedOstreamTest.cpp - Indented raw ostream 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 //===----------------------------------------------------------------------===//
9 #include "mlir/Support/IndentedOstream.h"
10 #include "gmock/gmock.h"
12 using namespace mlir;
13 using ::testing::StrEq;
15 TEST(FormatTest, SingleLine) {
16 std::string str;
17 llvm::raw_string_ostream os(str);
18 raw_indented_ostream ros(os);
19 ros << 10;
20 ros.flush();
21 EXPECT_THAT(os.str(), StrEq("10"));
24 TEST(FormatTest, SimpleMultiLine) {
25 std::string str;
26 llvm::raw_string_ostream os(str);
27 raw_indented_ostream ros(os);
28 ros << "a";
29 ros << "b";
30 ros << "\n";
31 ros << "c";
32 ros << "\n";
33 ros.flush();
34 EXPECT_THAT(os.str(), StrEq("ab\nc\n"));
37 TEST(FormatTest, SimpleMultiLineIndent) {
38 std::string str;
39 llvm::raw_string_ostream os(str);
40 raw_indented_ostream ros(os);
41 ros.indent(2) << "a";
42 ros.indent(4) << "b";
43 ros << "\n";
44 ros << "c";
45 ros << "\n";
46 ros.flush();
47 EXPECT_THAT(os.str(), StrEq(" a b\n c\n"));
50 TEST(FormatTest, SingleRegion) {
51 std::string str;
52 llvm::raw_string_ostream os(str);
53 raw_indented_ostream ros(os);
54 ros << "before\n";
56 raw_indented_ostream::DelimitedScope scope(ros);
57 ros << "inside " << 10;
58 ros << "\n two\n";
60 raw_indented_ostream::DelimitedScope scope(ros, "{\n", "\n}\n");
61 ros << "inner inner";
64 ros << "after";
65 ros.flush();
66 const auto *expected =
67 R"(before
68 inside 10
69 two
71 inner inner
73 after)";
74 EXPECT_THAT(os.str(), StrEq(expected));
76 // Repeat the above with inline form.
77 str.clear();
78 ros << "before\n";
79 ros.scope().os << "inside " << 10 << "\n two\n";
80 ros.scope().os.scope("{\n", "\n}\n").os << "inner inner";
81 ros << "after";
82 ros.flush();
83 EXPECT_THAT(os.str(), StrEq(expected));
86 TEST(FormatTest, Reindent) {
87 std::string str;
88 llvm::raw_string_ostream os(str);
89 raw_indented_ostream ros(os);
91 // String to print with some additional empty lines at the start and lines
92 // with just spaces.
93 const auto *desc = R"(
96 First line
97 second line
101 ros.printReindented(desc);
102 ros.flush();
103 const auto *expected =
104 R"(First line
105 second line
109 EXPECT_THAT(os.str(), StrEq(expected));
112 TEST(FormatTest, ReindentLineEndings) {
113 std::string str;
114 llvm::raw_string_ostream os(str);
115 raw_indented_ostream ros(os);
117 // Similar string as the previous test, but with \r\n (Windows style) line
118 // breaks. Note that C++'s internal string representation uses \n, so just
119 // running the previous test as-is on Windows is not sufficient.
120 const auto *desc =
121 "\r\n\r\n\r\n First line\r\n second line";
122 ros.printReindented(desc);
123 ros.flush();
124 const auto *expected = "First line\r\n second line";
125 EXPECT_THAT(os.str(), StrEq(expected));