#include "Config.h"
#include "TweakTesting.h"
+#include "support/Context.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
-#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
+#include <utility>
namespace clang {
namespace clangd {
struct {
llvm::StringRef TestSource;
llvm::StringRef ExpectedSource;
- } Cases[]{{
- // Function, no other using, namespace.
- R"cpp(
+ } Cases[]{
+ {
+ // Function, no other using, namespace.
+ R"cpp(
#include "test.hpp"
namespace {
void fun() {
^one::two::ff();
}
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
namespace {using one::two::ff;
ff();
}
})cpp",
- },
- // Type, no other using, namespace.
- {
- R"cpp(
+ },
+ // Type, no other using, namespace.
+ {
+ R"cpp(
#include "test.hpp"
namespace {
void fun() {
::one::t^wo::cc inst;
}
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
namespace {using ::one::two::cc;
cc inst;
}
})cpp",
- },
- // Type, no other using, no namespace.
- {
- R"cpp(
+ },
+ // Type, no other using, no namespace.
+ {
+ R"cpp(
#include "test.hpp"
void fun() {
one::two::e^e inst;
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::two::ee;
void fun() {
ee inst;
})cpp"},
- // Function, other usings.
- {
- R"cpp(
+ // Function, other usings.
+ {
+ R"cpp(
#include "test.hpp"
using one::two::cc;
one::two::f^f();
}
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::two::cc;
ff();
}
})cpp",
- },
- // Function, other usings inside namespace.
- {
- R"cpp(
+ },
+ // Function, other usings inside namespace.
+ {
+ R"cpp(
#include "test.hpp"
using one::two::cc;
o^ne::oo();
}
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::two::cc;
oo();
}
})cpp"},
- // Using comes after cursor.
- {
- R"cpp(
+ // Using comes after cursor.
+ {
+ R"cpp(
#include "test.hpp"
namespace {
using one::two::cc;
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
namespace {using one::two::ff;
using one::two::cc;
})cpp"},
- // Pointer type.
- {R"cpp(
+ // Pointer type.
+ {R"cpp(
#include "test.hpp"
void fun() {
one::two::c^c *p;
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::two::cc;
void fun() {
cc *p;
})cpp"},
- // Namespace declared via macro.
- {R"cpp(
+ // Namespace declared via macro.
+ {R"cpp(
#include "test.hpp"
#define NS_BEGIN(name) namespace name {
one::two::f^f();
}
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
#define NS_BEGIN(name) namespace name {
ff();
}
})cpp"},
- // Inside macro argument.
- {R"cpp(
+ // Inside macro argument.
+ {R"cpp(
#include "test.hpp"
#define CALL(name) name()
void fun() {
CALL(one::t^wo::ff);
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
#define CALL(name) name()
void fun() {
CALL(ff);
})cpp"},
- // Parent namespace != lexical parent namespace
- {R"cpp(
+ // Parent namespace != lexical parent namespace
+ {R"cpp(
#include "test.hpp"
namespace foo { void fun(); }
void foo::fun() {
one::two::f^f();
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::two::ff;
void foo::fun() {
ff();
})cpp"},
- // If all other using are fully qualified, add ::
- {R"cpp(
+ // If all other using are fully qualified, add ::
+ {R"cpp(
#include "test.hpp"
using ::one::two::cc;
void fun() {
one::two::f^f();
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using ::one::two::cc;
void fun() {
ff();
})cpp"},
- // Make sure we don't add :: if it's already there
- {R"cpp(
+ // Make sure we don't add :: if it's already there
+ {R"cpp(
#include "test.hpp"
using ::one::two::cc;
void fun() {
::one::two::f^f();
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using ::one::two::cc;
void fun() {
ff();
})cpp"},
- // If even one using doesn't start with ::, do not add it
- {R"cpp(
+ // If even one using doesn't start with ::, do not add it
+ {R"cpp(
#include "test.hpp"
using ::one::two::cc;
void fun() {
one::two::f^f();
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using ::one::two::cc;
void fun() {
ff();
})cpp"},
- // using alias; insert using for the spelled name.
- {R"cpp(
+ // using alias; insert using for the spelled name.
+ {R"cpp(
#include "test.hpp"
void fun() {
one::u^u u;
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::uu;
void fun() {
uu u;
})cpp"},
- // using namespace.
- {R"cpp(
+ // using namespace.
+ {R"cpp(
#include "test.hpp"
using namespace one;
namespace {
two::c^c C;
})cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using namespace one;
namespace {using two::cc;
cc C;
})cpp"},
- // Type defined in main file, make sure using is after that.
- {R"cpp(
+ // Type defined in main file, make sure using is after that.
+ {R"cpp(
namespace xx {
struct yy {};
}
x^x::yy X;
)cpp",
- R"cpp(
+ R"cpp(
namespace xx {
struct yy {};
}
yy X;
)cpp"},
- // Type defined in main file via "using", insert after that.
- {R"cpp(
+ // Type defined in main file via "using", insert after that.
+ {R"cpp(
#include "test.hpp"
namespace xx {
x^x::yy X;
)cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
namespace xx {
yy X;
)cpp"},
- // Using must come after function definition.
- {R"cpp(
+ // Using must come after function definition.
+ {R"cpp(
namespace xx {
void yy();
}
x^x::yy();
}
)cpp",
- R"cpp(
+ R"cpp(
namespace xx {
void yy();
}
yy();
}
)cpp"},
- // Existing using with non-namespace part.
- {R"cpp(
+ // Existing using with non-namespace part.
+ {R"cpp(
#include "test.hpp"
using one::two::ee::ee_one;
one::t^wo::cc c;
)cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::two::cc;using one::two::ee::ee_one;
cc c;
)cpp"},
- // Template (like std::vector).
- {R"cpp(
+ // Template (like std::vector).
+ {R"cpp(
#include "test.hpp"
one::v^ec<int> foo;
)cpp",
- R"cpp(
+ R"cpp(
#include "test.hpp"
using one::vec;