Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | const char *TestCases[] = { | ||||
}; | }; | ||||
struct { | struct { | ||||
} $Variable_decl[[S]]; | } $Variable_decl[[S]]; | ||||
void $Function_decl[[foo]](int $Parameter_decl[[A]], $Class[[AS]] $Parameter_decl[[As]]) { | void $Function_decl[[foo]](int $Parameter_decl[[A]], $Class[[AS]] $Parameter_decl[[As]]) { | ||||
$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[VeryLongVariableName]] = 12312; | $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[VeryLongVariableName]] = 12312; | ||||
$Class[[AS]] $LocalVariable_decl[[AA]]; | $Class[[AS]] $LocalVariable_decl[[AA]]; | ||||
$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]]; | $Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_decl[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]]; | ||||
auto $LocalVariable_decl[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_decl[[A]]) -> void {}; | auto $LocalVariable_decl[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_decl[[A]]) -> void {}; | ||||
$LocalVariable[[FN]](12312); | $LocalVariable[[FN]]$Method_readonly[[(]]12312$Method_readonly[[)]]; | ||||
} | } | ||||
)cpp", | )cpp", | ||||
R"cpp( | R"cpp( | ||||
void $Function_decl[[foo]](int); | void $Function_decl[[foo]](int); | ||||
void $Function_decl[[Gah]](); | void $Function_decl[[Gah]](); | ||||
void $Function_decl[[foo]]() { | void $Function_decl[[foo]]() { | ||||
auto $LocalVariable_decl[[Bou]] = $Function[[Gah]]; | auto $LocalVariable_decl[[Bou]] = $Function[[Gah]]; | ||||
} | } | ||||
Show All 12 Lines | )cpp", | ||||
struct $Class_decl[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> { | struct $Class_decl[[C]] : $Namespace[[abc]]::$Class[[A]]<$TemplateParameter[[T]]> { | ||||
typename $TemplateParameter[[T]]::$Type_dependentName[[A]]* $Field_decl[[D]]; | typename $TemplateParameter[[T]]::$Type_dependentName[[A]]* $Field_decl[[D]]; | ||||
}; | }; | ||||
$Namespace[[abc]]::$Class[[A]]<int> $Variable_decl[[AA]]; | $Namespace[[abc]]::$Class[[A]]<int> $Variable_decl[[AA]]; | ||||
typedef $Namespace[[abc]]::$Class[[A]]<int> $Class_decl[[AAA]]; | typedef $Namespace[[abc]]::$Class[[A]]<int> $Class_decl[[AAA]]; | ||||
struct $Class_decl[[B]] { | struct $Class_decl[[B]] { | ||||
$Class_decl[[B]](); | $Class_decl[[B]](); | ||||
~$Class[[B]](); // FIXME: inconsistent with constructor | ~$Class[[B]](); // FIXME: inconsistent with constructor | ||||
void operator<<($Class[[B]]); | void $Method_decl[[operator<<]]($Class[[B]]); | ||||
$Class[[AAA]] $Field_decl[[AA]]; | $Class[[AAA]] $Field_decl[[AA]]; | ||||
}; | }; | ||||
$Class[[B]]::$Class_decl[[B]]() {} | $Class[[B]]::$Class_decl[[B]]() {} | ||||
$Class[[B]]::~$Class[[B]]() {} // FIXME: inconsistent with constructor | $Class[[B]]::~$Class[[B]]() {} // FIXME: inconsistent with constructor | ||||
void $Function_decl[[f]] () { | void $Function_decl[[f]] () { | ||||
$Class[[B]] $LocalVariable_decl[[BB]] = $Class[[B]](); | $Class[[B]] $LocalVariable_decl[[BB]] = $Class[[B]](); | ||||
$LocalVariable[[BB]].~$Class[[B]](); | $LocalVariable[[BB]].~$Class[[B]](); | ||||
$Class[[B]](); | $Class[[B]](); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | )cpp", | ||||
$Class[[Foo]] *$LocalVariable_decl[[FP]] = ($Class[[Foo]]*)$LocalVariable[[B]]; | $Class[[Foo]] *$LocalVariable_decl[[FP]] = ($Class[[Foo]]*)$LocalVariable[[B]]; | ||||
int $LocalVariable_decl[[I]] = (int)$LocalVariable[[B]]; | int $LocalVariable_decl[[I]] = (int)$LocalVariable[[B]]; | ||||
} | } | ||||
)cpp", | )cpp", | ||||
R"cpp( | R"cpp( | ||||
struct $Class_decl[[B]] {}; | struct $Class_decl[[B]] {}; | ||||
struct $Class_decl[[A]] { | struct $Class_decl[[A]] { | ||||
$Class[[B]] $Field_decl[[BB]]; | $Class[[B]] $Field_decl[[BB]]; | ||||
$Class[[A]] &operator=($Class[[A]] &&$Parameter_decl[[O]]); | $Class[[A]] &$Method_decl[[operator=]]($Class[[A]] &&$Parameter_decl[[O]]); | ||||
}; | }; | ||||
$Class[[A]] &$Class[[A]]::operator=($Class[[A]] &&$Parameter_decl[[O]]) = default; | $Class[[A]] &$Class[[A]]::$Method_decl[[operator=]]($Class[[A]] &&$Parameter_decl[[O]]) = default; | ||||
)cpp", | )cpp", | ||||
R"cpp( | R"cpp( | ||||
enum $Enum_decl[[En]] { | enum $Enum_decl[[En]] { | ||||
$EnumConstant_decl_readonly[[EC]], | $EnumConstant_decl_readonly[[EC]], | ||||
}; | }; | ||||
class $Class_decl[[Foo]] {}; | class $Class_decl[[Foo]] {}; | ||||
class $Class_decl[[Bar]] { | class $Class_decl[[Bar]] { | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 468 Lines • ▼ Show 20 Lines | )cpp", | ||||
$Function[[foo]]($Parameter[[x]]); | $Function[[foo]]($Parameter[[x]]); | ||||
} | } | ||||
)cpp", | )cpp", | ||||
// init-captures | // init-captures | ||||
R"cpp( | R"cpp( | ||||
void $Function_decl[[foo]]() { | void $Function_decl[[foo]]() { | ||||
int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]]; | int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]]; | ||||
[ $LocalVariable_decl[[c]] = $LocalVariable[[a]], | [ $LocalVariable_decl[[c]] = $LocalVariable[[a]], | ||||
$LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}(); | $LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}$Method_readonly[[(]]$Method_readonly[[)]]; | ||||
} | } | ||||
)cpp", | )cpp", | ||||
// Enum base specifier | // Enum base specifier | ||||
R"cpp( | R"cpp( | ||||
using $Primitive_decl[[MyTypedef]] = int; | using $Primitive_decl[[MyTypedef]] = int; | ||||
enum $Enum_decl[[MyEnum]] : $Primitive[[MyTypedef]] {}; | enum $Enum_decl[[MyEnum]] : $Primitive[[MyTypedef]] {}; | ||||
)cpp", | )cpp", | ||||
// Enum base specifier | // Enum base specifier | ||||
R"cpp( | R"cpp( | ||||
typedef int $Primitive_decl[[MyTypedef]]; | typedef int $Primitive_decl[[MyTypedef]]; | ||||
enum $Enum_decl[[MyEnum]] : $Primitive[[MyTypedef]] {}; | enum $Enum_decl[[MyEnum]] : $Primitive[[MyTypedef]] {}; | ||||
)cpp", | )cpp", | ||||
// Overloaded operators | |||||
R"cpp( | |||||
struct $Class_decl[[Foo]] { | |||||
bool $Method_decl[[operator()]]() { return true; } | |||||
void $Method_decl[[operator<<]](int $Parameter_decl[[K]]) {} | |||||
operator bool() {} // FIXME: consider how this should be highlighted. | |||||
}; | |||||
namespace $Namespace_decl[[namesp]] { | |||||
void $Function_decl[[operator--]]($Class[[Foo]] $Parameter_decl[[F]]) | |||||
{} | |||||
}; | |||||
auto $Variable_decl[[a]] = | |||||
&$Namespace[[namesp]]::$Function[[operator--]]; | |||||
void $Function_decl[[operator++]]($Class[[Foo]] &$Parameter_decl[[F]]) | |||||
{} | |||||
int $Function_decl[[main]]() { | |||||
$Class[[Foo]] $LocalVariable_decl[[foo]]; | |||||
$LocalVariable[[foo]].$Method[[operator()]](); | |||||
$LocalVariable[[foo]].$Method[[operator<<]](1); | |||||
nridge: I'm going to suggest that we exercise a few more implicit-call cases:
* single-token, e.g. | |||||
$Function[[operator++]]($LocalVariable_usedAsMutableReference[[foo]]); | |||||
$Function[[operator delete[]]]($Function[[operator new[]]](1)); | |||||
} | |||||
)cpp", | |||||
}; | }; | ||||
for (const auto &TestCase : TestCases) | for (const auto &TestCase : TestCases) | ||||
// Mask off scope modifiers to keep the tests manageable. | // Mask off scope modifiers to keep the tests manageable. | ||||
// They're tested separately. | // They're tested separately. | ||||
checkHighlightings(TestCase, {}, ~ScopeModifierMask); | checkHighlightings(TestCase, {}, ~ScopeModifierMask); | ||||
checkHighlightings(R"cpp( | checkHighlightings(R"cpp( | ||||
class $Class_decl[[A]] { | class $Class_decl[[A]] { | ||||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |
I'm going to suggest that we exercise a few more implicit-call cases:
(Very interestingly, in the implicit () and [] cases, the opening one seems to be colored by VisitDeclRefExpr but the closing one by VisitCXXOperatorCallExpr. Not quite sure why that is.)