@@ -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
@@ -1607,7 +1607,7 @@ TEST(TypeHints, CallingConvention) {
16071607 auto AST = TU.build ();
16081608
16091609 EXPECT_THAT (
1610- hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts ),
1610+ hintsOfKind (AST, InlayHintKind::Type, DefaultOptsForTests ),
16111611 ElementsAre (HintMatcher (ExpectedHint{" -> void" , " lambda" }, Source)));
16121612}
16131613
@@ -1690,7 +1690,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
16901690 )cpp" ;
16911691
16921692 assertHintsWithHeader (
1693- InlayHintKind::Type, VectorIntPtr, Header, DefaultInlayHintOpts ,
1693+ InlayHintKind::Type, VectorIntPtr, Header, DefaultOptsForTests ,
16941694 ExpectedHint{" : int *" , " no_modifier" },
16951695 ExpectedHint{" : int **" , " ptr_modifier" },
16961696 ExpectedHint{" : int *&" , " ref_modifier" },
@@ -1714,7 +1714,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17141714 )cpp" ;
17151715
17161716 assertHintsWithHeader (
1717- InlayHintKind::Type, VectorInt, Header, DefaultInlayHintOpts ,
1717+ InlayHintKind::Type, VectorInt, Header, DefaultOptsForTests ,
17181718 ExpectedHint{" : int" , " no_modifier" },
17191719 ExpectedHint{" : int *" , " ptr_modifier" },
17201720 ExpectedHint{" : int &" , " ref_modifier" },
@@ -1741,7 +1741,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
17411741 )cpp" ;
17421742
17431743 assertHintsWithHeader (InlayHintKind::Type, TypeAlias, Header,
1744- DefaultInlayHintOpts ,
1744+ DefaultOptsForTests ,
17451745 ExpectedHint{" : Short" , " short_name" },
17461746 ExpectedHint{" : static_vector<int>" , " vector_name" });
17471747}
@@ -2034,6 +2034,7 @@ TEST(BlockEndHints, If) {
20342034 assertBlockEndHints (
20352035 R"cpp(
20362036 void foo(bool cond) {
2037+ void* ptr;
20372038 if (cond)
20382039 ;
20392040
@@ -2059,13 +2060,17 @@ TEST(BlockEndHints, If) {
20592060
20602061 if (int i = 0; i > 10) {
20612062 $init_cond[[}]]
2063+
2064+ if (ptr != nullptr) {
2065+ $null_check[[}]]
20622066 } // suppress
20632067 )cpp" ,
20642068 ExpectedHint{" // if cond" , " simple" },
20652069 ExpectedHint{" // if cond" , " ifelse" }, ExpectedHint{" // if" , " elseif" },
20662070 ExpectedHint{" // if !cond" , " inner" },
20672071 ExpectedHint{" // if cond" , " outer" }, ExpectedHint{" // if X" , " init" },
2068- ExpectedHint{" // if i > 10" , " init_cond" });
2072+ ExpectedHint{" // if i > 10" , " init_cond" },
2073+ ExpectedHint{" // if ptr != nullptr" , " null_check" });
20692074}
20702075
20712076TEST (BlockEndHints, Loops) {
@@ -2340,6 +2345,10 @@ TEST(BlockEndHints, PointerToMemberFunction) {
23402345}
23412346
23422347TEST (BlockEndHints, MinLineLimit) {
2348+ InlayHintOptions Opts;
2349+ Opts.HintMinLineLimit = 10 ;
2350+
2351+ // namespace ns below is exactly 10 lines
23432352 assertBlockEndHintsWithOpts (
23442353 R"cpp(
23452354 namespace ns {
@@ -2350,30 +2359,30 @@ TEST(BlockEndHints, MinLineLimit) {
23502359 int Field;
23512360 int method1() const;
23522361 int method2(int, int) const;
2353- $struct[[}]] ;
2362+ } ;
23542363 $namespace[[}]]
23552364 void foo() {
23562365 int int_a {};
23572366 while (ns::Var) {
2358- $var[[}]]
2367+ }
23592368
23602369 while (ns::func1()) {
2361- $func1[[}]]
2370+ }
23622371
23632372 while (ns::func2(int_a, int_a)) {
2364- $func2[[}]]
2373+ }
23652374
23662375 while (ns::S{}.Field) {
2367- $field[[}]]
2376+ }
23682377
23692378 while (ns::S{}.method1()) {
2370- $method1[[}]]
2379+ }
23712380
23722381 while (ns::S{}.method2(int_a, int_a)) {
2373- $method2[[}]]
2382+ }
23742383 $foo[[}]]
23752384 )cpp" ,
2376- InlayHintOptions{ 10 } , ExpectedHint{" // namespace ns" , " namespace" },
2385+ Opts , ExpectedHint{" // namespace ns" , " namespace" },
23772386 ExpectedHint{" // foo" , " foo" });
23782387}
23792388
0 commit comments