@@ -36,7 +36,7 @@ namespace {
36
36
using ::testing::ElementsAre;
37
37
using ::testing::IsEmpty;
38
38
39
- constexpr InlayHintOptions DefaultInlayHintOpts{ };
39
+ constexpr InlayHintOptions DefaultOptsForTests{ 2 };
40
40
41
41
std::vector<InlayHint> hintsOfKind (ParsedAST &AST, InlayHintKind Kind,
42
42
InlayHintOptions Opts) {
@@ -123,15 +123,15 @@ template <typename... ExpectedHints>
123
123
void assertParameterHints (llvm::StringRef AnnotatedSource,
124
124
ExpectedHints... Expected) {
125
125
ignore (Expected.Side = Left...);
126
- assertHints (InlayHintKind::Parameter, AnnotatedSource, DefaultInlayHintOpts ,
126
+ assertHints (InlayHintKind::Parameter, AnnotatedSource, DefaultOptsForTests ,
127
127
Expected...);
128
128
}
129
129
130
130
template <typename ... ExpectedHints>
131
131
void assertTypeHints (llvm::StringRef AnnotatedSource,
132
132
ExpectedHints... Expected) {
133
133
ignore (Expected.Side = Right...);
134
- assertHints (InlayHintKind::Type, AnnotatedSource, DefaultInlayHintOpts ,
134
+ assertHints (InlayHintKind::Type, AnnotatedSource, DefaultOptsForTests ,
135
135
Expected...);
136
136
}
137
137
@@ -141,7 +141,7 @@ void assertDesignatorHints(llvm::StringRef AnnotatedSource,
141
141
Config Cfg;
142
142
Cfg.InlayHints .Designators = true ;
143
143
WithContextValue WithCfg (Config::Key, std::move (Cfg));
144
- assertHints (InlayHintKind::Designator, AnnotatedSource, DefaultInlayHintOpts ,
144
+ assertHints (InlayHintKind::Designator, AnnotatedSource, DefaultOptsForTests ,
145
145
Expected...);
146
146
}
147
147
@@ -158,7 +158,7 @@ void assertBlockEndHintsWithOpts(llvm::StringRef AnnotatedSource,
158
158
template <typename ... ExpectedHints>
159
159
void assertBlockEndHints (llvm::StringRef AnnotatedSource,
160
160
ExpectedHints... Expected) {
161
- assertBlockEndHintsWithOpts (AnnotatedSource, DefaultInlayHintOpts ,
161
+ assertBlockEndHintsWithOpts (AnnotatedSource, DefaultOptsForTests ,
162
162
Expected...);
163
163
}
164
164
@@ -1241,7 +1241,7 @@ TEST(ParameterHints, IncludeAtNonGlobalScope) {
1241
1241
1242
1242
// Ensure the hint for the call in foo.inc is NOT materialized in foo.cc.
1243
1243
EXPECT_EQ (
1244
- hintsOfKind (*AST, InlayHintKind::Parameter, DefaultInlayHintOpts ).size (),
1244
+ hintsOfKind (*AST, InlayHintKind::Parameter, DefaultOptsForTests ).size (),
1245
1245
0u );
1246
1246
}
1247
1247
@@ -1504,12 +1504,12 @@ TEST(DefaultArguments, Smoke) {
1504
1504
void baz(int = 5) { if (false) baz($unnamed[[)]]; };
1505
1505
)cpp" ;
1506
1506
1507
- assertHints (InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts ,
1507
+ assertHints (InlayHintKind::DefaultArgument, Code, DefaultOptsForTests ,
1508
1508
ExpectedHint{" A: 4" , " default1" , Left},
1509
1509
ExpectedHint{" , B: 1, C: foo()" , " default2" , Left},
1510
1510
ExpectedHint{" 5" , " unnamed" , Left});
1511
1511
1512
- assertHints (InlayHintKind::Parameter, Code, DefaultInlayHintOpts ,
1512
+ assertHints (InlayHintKind::Parameter, Code, DefaultOptsForTests ,
1513
1513
ExpectedHint{" A: " , " explicit" , Left});
1514
1514
}
1515
1515
@@ -1544,14 +1544,14 @@ TEST(DefaultArguments, WithoutParameterNames) {
1544
1544
}
1545
1545
)cpp" ;
1546
1546
1547
- assertHints (InlayHintKind::DefaultArgument, Code, DefaultInlayHintOpts ,
1547
+ assertHints (InlayHintKind::DefaultArgument, Code, DefaultOptsForTests ,
1548
1548
ExpectedHint{" ..." , " abbreviated" , Left},
1549
1549
ExpectedHint{" , Baz{}" , " paren" , Left},
1550
1550
ExpectedHint{" , Baz{}" , " brace1" , Left},
1551
1551
ExpectedHint{" , Baz{}" , " brace2" , Left},
1552
1552
ExpectedHint{" , Baz{}" , " brace3" , Left});
1553
1553
1554
- assertHints (InlayHintKind::Parameter, Code, DefaultInlayHintOpts );
1554
+ assertHints (InlayHintKind::Parameter, Code, DefaultOptsForTests );
1555
1555
}
1556
1556
1557
1557
TEST (TypeHints, Deduplication) {
@@ -1589,7 +1589,7 @@ TEST(TypeHints, Aliased) {
1589
1589
TU.ExtraArgs .push_back (" -xc" );
1590
1590
auto AST = TU.build ();
1591
1591
1592
- EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts ),
1592
+ EXPECT_THAT (hintsOfKind (AST, InlayHintKind::Type, DefaultOptsForTests ),
1593
1593
IsEmpty ());
1594
1594
}
1595
1595
@@ -1607,7 +1607,7 @@ TEST(TypeHints, CallingConvention) {
1607
1607
auto AST = TU.build ();
1608
1608
1609
1609
EXPECT_THAT (
1610
- hintsOfKind (AST, InlayHintKind::Type, DefaultInlayHintOpts ),
1610
+ hintsOfKind (AST, InlayHintKind::Type, DefaultOptsForTests ),
1611
1611
ElementsAre (HintMatcher (ExpectedHint{" -> void" , " lambda" }, Source)));
1612
1612
}
1613
1613
@@ -1690,7 +1690,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
1690
1690
)cpp" ;
1691
1691
1692
1692
assertHintsWithHeader (
1693
- InlayHintKind::Type, VectorIntPtr, Header, DefaultInlayHintOpts ,
1693
+ InlayHintKind::Type, VectorIntPtr, Header, DefaultOptsForTests ,
1694
1694
ExpectedHint{" : int *" , " no_modifier" },
1695
1695
ExpectedHint{" : int **" , " ptr_modifier" },
1696
1696
ExpectedHint{" : int *&" , " ref_modifier" },
@@ -1714,7 +1714,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
1714
1714
)cpp" ;
1715
1715
1716
1716
assertHintsWithHeader (
1717
- InlayHintKind::Type, VectorInt, Header, DefaultInlayHintOpts ,
1717
+ InlayHintKind::Type, VectorInt, Header, DefaultOptsForTests ,
1718
1718
ExpectedHint{" : int" , " no_modifier" },
1719
1719
ExpectedHint{" : int *" , " ptr_modifier" },
1720
1720
ExpectedHint{" : int &" , " ref_modifier" },
@@ -1741,7 +1741,7 @@ TEST(TypeHints, SubstTemplateParameterAliases) {
1741
1741
)cpp" ;
1742
1742
1743
1743
assertHintsWithHeader (InlayHintKind::Type, TypeAlias, Header,
1744
- DefaultInlayHintOpts ,
1744
+ DefaultOptsForTests ,
1745
1745
ExpectedHint{" : Short" , " short_name" },
1746
1746
ExpectedHint{" : static_vector<int>" , " vector_name" });
1747
1747
}
@@ -2034,6 +2034,7 @@ TEST(BlockEndHints, If) {
2034
2034
assertBlockEndHints (
2035
2035
R"cpp(
2036
2036
void foo(bool cond) {
2037
+ void* ptr;
2037
2038
if (cond)
2038
2039
;
2039
2040
@@ -2059,13 +2060,17 @@ TEST(BlockEndHints, If) {
2059
2060
2060
2061
if (int i = 0; i > 10) {
2061
2062
$init_cond[[}]]
2063
+
2064
+ if (ptr != nullptr) {
2065
+ $null_check[[}]]
2062
2066
} // suppress
2063
2067
)cpp" ,
2064
2068
ExpectedHint{" // if cond" , " simple" },
2065
2069
ExpectedHint{" // if cond" , " ifelse" }, ExpectedHint{" // if" , " elseif" },
2066
2070
ExpectedHint{" // if !cond" , " inner" },
2067
2071
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" });
2069
2074
}
2070
2075
2071
2076
TEST (BlockEndHints, Loops) {
@@ -2340,6 +2345,10 @@ TEST(BlockEndHints, PointerToMemberFunction) {
2340
2345
}
2341
2346
2342
2347
TEST (BlockEndHints, MinLineLimit) {
2348
+ InlayHintOptions Opts;
2349
+ Opts.HintMinLineLimit = 10 ;
2350
+
2351
+ // namespace ns below is exactly 10 lines
2343
2352
assertBlockEndHintsWithOpts (
2344
2353
R"cpp(
2345
2354
namespace ns {
@@ -2350,30 +2359,30 @@ TEST(BlockEndHints, MinLineLimit) {
2350
2359
int Field;
2351
2360
int method1() const;
2352
2361
int method2(int, int) const;
2353
- $struct[[}]] ;
2362
+ } ;
2354
2363
$namespace[[}]]
2355
2364
void foo() {
2356
2365
int int_a {};
2357
2366
while (ns::Var) {
2358
- $var[[}]]
2367
+ }
2359
2368
2360
2369
while (ns::func1()) {
2361
- $func1[[}]]
2370
+ }
2362
2371
2363
2372
while (ns::func2(int_a, int_a)) {
2364
- $func2[[}]]
2373
+ }
2365
2374
2366
2375
while (ns::S{}.Field) {
2367
- $field[[}]]
2376
+ }
2368
2377
2369
2378
while (ns::S{}.method1()) {
2370
- $method1[[}]]
2379
+ }
2371
2380
2372
2381
while (ns::S{}.method2(int_a, int_a)) {
2373
- $method2[[}]]
2382
+ }
2374
2383
$foo[[}]]
2375
2384
)cpp" ,
2376
- InlayHintOptions{ 10 } , ExpectedHint{" // namespace ns" , " namespace" },
2385
+ Opts , ExpectedHint{" // namespace ns" , " namespace" },
2377
2386
ExpectedHint{" // foo" , " foo" });
2378
2387
}
2379
2388
0 commit comments