[clang] [clang][ASTMatcher] Add `matchesString` for `StringLiteral` which matches literals on given `RegExp` (PR #102152)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 23:53:32 PDT 2024
================
@@ -2503,6 +2503,25 @@ TEST_P(ASTMatchersTest, IsDelegatingConstructor) {
cxxConstructorDecl(isDelegatingConstructor(), parameterCountIs(1))));
}
+TEST_P(ASTMatchersTest, MatchesString) {
+ StatementMatcher Literal = stringLiteral(matchesString("foo.*"));
+ EXPECT_TRUE(matches("const char* a = \"foo\";", Literal));
+ EXPECT_TRUE(matches("const char* b = \"foobar\";", Literal));
+ EXPECT_TRUE(matches("const char* b = \"fo\"\"obar\";", Literal));
+ EXPECT_TRUE(notMatches("const char* c = \"bar\";", Literal));
+ // test embedded nulls
+ StatementMatcher Literal2 = stringLiteral(matchesString("bar"));
+ EXPECT_TRUE(matches("const char* b = \"foo\\0bar\";", Literal2));
+ EXPECT_TRUE(notMatches("const char* b = \"foo\\0b\\0ar\";", Literal2));
+ // test prefix
+ if (!GetParam().isCXX20OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(matches("const wchar_t* a = L\"foo\";", Literal));
+ EXPECT_TRUE(matches("const char16_t* a = u\"foo\";", Literal));
+ EXPECT_TRUE(matches("const char32_t* a = U\"foo\";", Literal));
----------------
Gitspike wrote:
https://buildkite.com/llvm-project/github-pull-requests/builds/90047#01913521-cb7d-4fd8-a286-694680dc2631 Looks like this check is necessary, but earlier I mixed up the C/C++ standards that are supported. I've now split the test cases based on the examples above :)
https://github.com/llvm/llvm-project/pull/102152
More information about the cfe-commits
mailing list