@@ -36,7 +36,7 @@ namespace {
3636using ::testing::ElementsAre;
3737using ::testing::IsEmpty;
3838
39- constexpr InlayHintOptions DefaultInlayHintOpts{ };
39+ constexpr InlayHintOptions DefaultOptsForTests{ 2 };
4040
4141std::vector<InlayHint> hintsOfKind (ParsedAST &AST, InlayHintKind Kind,
4242 InlayHintOptions Opts) {
@@ -123,15 +123,15 @@ template <typename... ExpectedHints>
123123void assertParameterHints (llvm::StringRef AnnotatedSource,
124124 ExpectedHints... Expected) {
125125 ignore (Expected.Side = Left...);
126- assertHints (InlayHintKind::Parameter, AnnotatedSource, DefaultInlayHintOpts ,
126+ assertHints (InlayHintKind::Parameter, AnnotatedSource, DefaultOptsForTests ,
127127 Expected...);
128128}
129129
130130template <typename ... ExpectedHints>
131131void assertTypeHints (llvm::StringRef AnnotatedSource,
132132 ExpectedHints... Expected) {
133133 ignore (Expected.Side = Right...);
134- assertHints (InlayHintKind::Type, AnnotatedSource, DefaultInlayHintOpts ,
134+ assertHints (InlayHintKind::Type, AnnotatedSource, DefaultOptsForTests ,
135135 Expected...);
136136}
137137
@@ -141,7 +141,7 @@ void assertDesignatorHints(llvm::StringRef AnnotatedSource,
141141 Config Cfg;
142142 Cfg.InlayHints .Designators = true ;
143143 WithContextValue WithCfg (Config::Key, std::move (Cfg));
144- assertHints (InlayHintKind::Designator, AnnotatedSource, DefaultInlayHintOpts ,
144+ assertHints (InlayHintKind::Designator, AnnotatedSource, DefaultOptsForTests ,
145145 Expected...);
146146}
147147
@@ -158,7 +158,7 @@ void assertBlockEndHintsWithOpts(llvm::StringRef AnnotatedSource,
158158template <typename ... ExpectedHints>
159159void assertBlockEndHints (llvm::StringRef AnnotatedSource,
160160 ExpectedHints... Expected) {
161- assertBlockEndHintsWithOpts (AnnotatedSource, DefaultInlayHintOpts ,
161+ assertBlockEndHintsWithOpts (AnnotatedSource, DefaultOptsForTests ,
162162 Expected...);
163163}
164164
@@ -1241,7 +1241,7 @@ TEST(ParameterHints, IncludeAtNonGlobalScope) {
12411241
12421242 // Ensure the hint for the call in foo.inc is NOT materialized in foo.cc.
12431243 EXPECT_EQ (
1244- hintsOfKind (*AST, InlayHintKind::Parameter, DefaultInlayHintOpts ).size (),
1244+ hintsOfKind (*AST, InlayHintKind::Parameter, DefaultOptsForTests ).size (),
12451245 0u );
12461246}
12471247
@@ -1504,12 +1504,12 @@ TEST(DefaultArguments, Smoke) {
15041504 void baz(int = 5) { if (false) baz($unnamed[[)]]; };
15051505 )cpp" ;
15061506
1507- assertHints (InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts ,
1507+ assertHints (InlayHintKind::DefaultArgument, Code, DefaultOptsForTests ,
15081508 ExpectedHint{" A: 4" , " default1" , Left},
15091509 ExpectedHint{" , B: 1, C: foo()" , " default2" , Left},
15101510 ExpectedHint{" 5" , " unnamed" , Left});
15111511
1512- assertHints (InlayHintKind::Parameter, Code, DefaultInlayHintOpts ,
1512+ assertHints (InlayHintKind::Parameter, Code, DefaultOptsForTests ,
15131513 ExpectedHint{" A: " , " explicit" , Left});
15141514}
15151515
@@ -1544,14 +1544,14 @@ TEST(DefaultArguments, WithoutParameterNames) {
15441544 }
15451545 )cpp" ;
15461546
1547- assertHints (InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts ,
1547+ assertHints (InlayHintKind::DefaultArgument, Code, DefaultOptsForTests ,
15481548 ExpectedHint{" ..." , " abbreviated" , Left},
15491549 ExpectedHint{" , Baz{}" , " paren" , Left},
15501550 ExpectedHint{" , Baz{}" , " brace1" , Left},
15511551 ExpectedHint{" , Baz{}" , " brace2" , Left},
15521552 ExpectedHint{" , Baz{}" , " brace3" , Left});
15531553
1554- assertHints (InlayHintKind::Parameter, Code, DefaultInlayHintOpts );
1554+ assertHints (InlayHintKind::Parameter, Code, DefaultOptsForTests );
15551555}
15561556
15571557TEST (TypeHints, Deduplication) {
@@ -1589,7 +1589,7 @@ TEST(TypeHints, Aliased) {
15891589 TU.ExtraArgs .push_back (" -xc" );
15901590 auto AST = TU.build ();
15911591
1592- EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts ),
1592+ EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultOptsForTests ),
15931593 IsEmpty ());
15941594}
15951595
@@ -1606,7 +1606,7 @@ TEST(TypeHints, CallingConvention) {
16061606 TU.PredefineMacros = true ; // for the __cdecl
16071607 auto AST = TU.build ();
16081608
1609- EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts ),
1609+ EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultOptsForTests ),
16101610 IsEmpty ());
16111611}
16121612
@@ -1689,7 +1689,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16891689 )cpp" ;
16901690
16911691 assertHintsWithHeader (
1692- InlayHintKind::Type, VectorIntPtr, Header, DefaultInlayHintOpts ,
1692+ InlayHintKind::Type, VectorIntPtr, Header, DefaultOptsForTests ,
16931693 ExpectedHint{" : int *" , " no_modifier" },
16941694 ExpectedHint{" : int **" , " ptr_modifier" },
16951695 ExpectedHint{" : int *&" , " ref_modifier" },
@@ -1713,7 +1713,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17131713 )cpp" ;
17141714
17151715 assertHintsWithHeader (
1716- InlayHintKind::Type, VectorInt, Header, DefaultInlayHintOpts ,
1716+ InlayHintKind::Type, VectorInt, Header, DefaultOptsForTests ,
17171717 ExpectedHint{" : int" , " no_modifier" },
17181718 ExpectedHint{" : int *" , " ptr_modifier" },
17191719 ExpectedHint{" : int &" , " ref_modifier" },
@@ -1740,7 +1740,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17401740 )cpp" ;
17411741
17421742 assertHintsWithHeader (InlayHintKind::Type, TypeAlias, Header,
1743- DefaultInlayHintOpts ,
1743+ DefaultOptsForTests ,
17441744 ExpectedHint{" : Short" , " short_name" },
17451745 ExpectedHint{" : static_vector<int>" , " vector_name" });
17461746}
@@ -2033,6 +2033,7 @@ TEST(BlockEndHints, If) {
20332033 assertBlockEndHints (
20342034 R"cpp(
20352035 void foo(bool cond) {
2036+ void* ptr;
20362037 if (cond)
20372038 ;
20382039
@@ -2058,13 +2059,17 @@ TEST(BlockEndHints, If) {
20582059
20592060 if (int i = 0; i > 10) {
20602061 $init_cond[[}]]
2062+
2063+ if (ptr != nullptr) {
2064+ $null_check[[}]]
20612065 } // suppress
20622066 )cpp" ,
20632067 ExpectedHint{" // if cond" , " simple" },
20642068 ExpectedHint{" // if cond" , " ifelse" }, ExpectedHint{" // if" , " elseif" },
20652069 ExpectedHint{" // if !cond" , " inner" },
20662070 ExpectedHint{" // if cond" , " outer" }, ExpectedHint{" // if X" , " init" },
2067- ExpectedHint{" // if i > 10" , " init_cond" });
2071+ ExpectedHint{" // if i > 10" , " init_cond" },
2072+ ExpectedHint{" // if ptr != nullptr" , " null_check" });
20682073}
20692074
20702075TEST (BlockEndHints, Loops) {
@@ -2339,6 +2344,10 @@ TEST(BlockEndHints, PointerToMemberFunction) {
23392344}
23402345
23412346TEST (BlockEndHints, MinLineLimit) {
2347+ InlayHintOptions Opts;
2348+ Opts.HintMinLineLimit = 10 ;
2349+
2350+ // namespace ns below is exactly 10 lines
23422351 assertBlockEndHintsWithOpts (
23432352 R"cpp(
23442353 namespace ns {
@@ -2349,30 +2358,30 @@ TEST(BlockEndHints, MinLineLimit) {
23492358 int Field;
23502359 int method1() const;
23512360 int method2(int, int) const;
2352- $struct[[}]] ;
2361+ } ;
23532362 $namespace[[}]]
23542363 void foo() {
23552364 int int_a {};
23562365 while (ns::Var) {
2357- $var[[}]]
2366+ }
23582367
23592368 while (ns::func1()) {
2360- $func1[[}]]
2369+ }
23612370
23622371 while (ns::func2(int_a, int_a)) {
2363- $func2[[}]]
2372+ }
23642373
23652374 while (ns::S{}.Field) {
2366- $field[[}]]
2375+ }
23672376
23682377 while (ns::S{}.method1()) {
2369- $method1[[}]]
2378+ }
23702379
23712380 while (ns::S{}.method2(int_a, int_a)) {
2372- $method2[[}]]
2381+ }
23732382 $foo[[}]]
23742383 )cpp" ,
2375- InlayHintOptions{ 10 } , ExpectedHint{" // namespace ns" , " namespace" },
2384+ Opts , ExpectedHint{" // namespace ns" , " namespace" },
23762385 ExpectedHint{" // foo" , " foo" });
23772386}
23782387
0 commit comments