@@ -4767,6 +4767,48 @@ constexpr u64 pow_with_mod(u64 a, u64 b, u64 p) {
47674767 EXPECT_TRUE (H->Type );
47684768}
47694769
4770+ TEST (Hover, HoverMacroContentsLimit) {
4771+ const char *const Code =
4772+ R"cpp(
4773+ #define C(A) A##A // Concatenate
4774+ #define E(A) C(A) // Expand
4775+ #define Z0032 00000000000000000000000000000000
4776+ #define Z0064 E(Z0032)
4777+ #define Z0128 E(Z0064)
4778+ #define Z0256 E(Z0128)
4779+ #define Z0512 E(Z0256)
4780+ #define Z1024 E(Z0512)
4781+ #define Z2048 E(Z1024)
4782+ #define Z4096 E(Z2048) // 4096 zeroes
4783+ int main() { return [[^Z4096]]; }
4784+ )cpp" ;
4785+
4786+ struct {
4787+ uint32_t MacroContentsLimit;
4788+ const std::string ExpectedDefinition;
4789+ } Cases[] = {
4790+ // With a limit of 2048, the macro expansion should get dropped.
4791+ {2048 , " #define Z4096 E(Z2048)" },
4792+ // With a limit of 8192, the macro expansion should be fully expanded.
4793+ {8192 , std::string (" #define Z4096 E(Z2048)\n\n " ) +
4794+ std::string (" // Expands to\n " ) + std::string (4096 , ' 0' )},
4795+ };
4796+ for (const auto &Case : Cases) {
4797+ SCOPED_TRACE (Code);
4798+
4799+ Annotations T (Code);
4800+ TestTU TU = TestTU::withCode (T.code ());
4801+ auto AST = TU.build ();
4802+ Config Cfg;
4803+ Cfg.Hover .MacroContentsLimit = Case.MacroContentsLimit ;
4804+ WithContextValue WithCfg (Config::Key, std::move (Cfg));
4805+ auto H = getHover (AST, T.point (), format::getLLVMStyle (), nullptr );
4806+ ASSERT_TRUE (H);
4807+
4808+ EXPECT_EQ (H->Definition , Case.ExpectedDefinition );
4809+ }
4810+ };
4811+
47704812TEST (Hover, FunctionParameters) {
47714813 struct {
47724814 const char *const Code;
0 commit comments