Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiLiteralExpression
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.nextLeafs
import org.domaframework.doma.intellij.common.isInjectionSqlFile
Expand Down Expand Up @@ -102,13 +101,16 @@ class SqlTestDataAfterBlockCommentVisitor(
* These values can be separated by commas, and the entire list must be enclosed in parentheses.
*/
private fun isMatchListTestData(element: PsiElement): Boolean {
// Ensure the list starts with an opening parenthesis, as this is required
// for the structure to match the expected "list type test data" pattern.
if (element.nextSibling?.elementType != SqlTypes.LEFT_PAREN) return false
val parenthesesListPattern =
Regex(
"""^\(\s*(?:(?:"[^"]*"|'[^']*'|\d+|true|false|null)\s*(?:,\s*(?:"[^"]*"|'[^']*'|\d+|true|false|null)\s*)*)?\)$""",
)
val testDataText =
element.nextLeafs
.takeWhile { it !is PsiWhiteSpace }
.takeWhile { it.prevSibling is PsiElement && it.prevSibling?.elementType != SqlTypes.RIGHT_PAREN }
.toList()
.joinToString("") { it.text }
return testDataText.matches(parenthesesListPattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ SELECT e.employee_id AS employeeId
/*%! This comment will be removed */
WHERE e.employee_id = <error descr="Bind variables must be followed by test data">/*^ id */</error>
AND e.age >= /*^ literalAge */99
AND e.sub_id IN /* subIds */(1,2,3)
AND e.sub_id IN /* subIds */(1, 2, 3)