1 //===-- RemoveUsingNamespaceTest.cpp ----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "TweakTesting.h"
10 #include "gmock/gmock-matchers.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
18 TWEAK_TEST(RemoveUsingNamespace
);
20 TEST_F(RemoveUsingNamespaceTest
, All
) {
21 std::pair
<llvm::StringRef
/*Input*/, llvm::StringRef
/*Expected*/> Cases
[] = {
22 {// Remove all occurrences of ns. Qualify only unqualified.
24 namespace ns1 { struct vector {}; }
25 namespace ns2 { struct map {}; }
36 namespace ns1 { struct vector {}; }
37 namespace ns2 { struct map {}; }
47 {// Ident to be qualified is a macro arg.
49 #define DECLARE(x, y) x y
50 namespace ns { struct vector {}; }
53 DECLARE(ns::vector, v1);
58 #define DECLARE(x, y) x y
59 namespace ns { struct vector {}; }
62 DECLARE(ns::vector, v1);
63 DECLARE(ns::vector, v2);
66 {// Nested namespace: Fully qualify ident from inner ns.
68 namespace aa { namespace bb { struct map {}; }}
69 using namespace aa::b^b;
75 namespace aa { namespace bb { struct map {}; }}
81 {// Nested namespace: Fully qualify ident from inner ns.
83 namespace aa { namespace bb { struct map {}; }}
90 namespace aa { namespace bb { struct map {}; }}
98 namespace aa { namespace bb { struct map {}; }}
101 int main() { map M; }
104 namespace aa { namespace bb { struct map {}; }}
106 typedef aa::bb::map map;
107 int main() { map M; }
109 {// FIXME: Nested namespaces: Not aware of using ns decl of outer ns.
111 namespace aa { namespace bb { struct map {}; }}
112 using name[[space aa::b]]b;
119 namespace aa { namespace bb { struct map {}; }}
126 {// Does not qualify ident from inner namespace.
128 namespace aa { namespace bb { struct map {}; }}
129 using namespace aa::bb;
136 namespace aa { namespace bb { struct map {}; }}
137 using namespace aa::bb;
143 {// Available only for top level namespace decl.
146 namespace bb { struct map {}; }
149 int main() { aa::map m; }
152 {// FIXME: Unavailable for namespaces containing using-namespace decl.
155 namespace bb { struct map {}; }
165 namespace a::b { struct Foo {}; }
167 using namespace a::[[b]];
172 namespace a::b { struct Foo {}; }
176 int main() { a::b::Foo F;}
179 namespace a::b { struct Foo {}; }
181 using namespace a::b;
182 using namespace [[b]];
186 namespace a::b { struct Foo {}; }
190 int main() { b::Foo F;}
196 comma, identifier, numeric
199 using namespace tok^ens;
207 comma, identifier, numeric
212 auto x = tokens::comma;
215 {// inline namespaces.
217 namespace std { inline namespace ns1 { inline namespace ns2 { struct vector {}; }}}
218 using namespace st^d;
224 namespace std { inline namespace ns1 { inline namespace ns2 { struct vector {}; }}}
230 {// Does not qualify operators declared in a non-class context
234 void operator+(const Foo &, int) {}
245 void operator+(const Foo &, int) {}
253 {// Does not qualify user-defined literals
256 long double operator "" _w(long double);
259 int main() { 1.5_w; }
263 long double operator "" _w(long double);
266 int main() { 1.5_w; }
270 namespace a { inline namespace b { void foobar(); } }
271 using namespace a::[[b]];
272 int main() { foobar(); }
275 namespace a { inline namespace b { void foobar(); } }
277 int main() { a::b::foobar(); }
280 EXPECT_EQ(C
.second
, apply(C
.first
)) << C
.first
;
284 } // namespace clangd