[java] Simplify ASTPatternTest

Backported from pmd/7.0.x
This commit is contained in:
Andreas Dangel
2022-03-10 16:42:43 +01:00
parent 690e5a66e3
commit 19cba367f9
2 changed files with 10 additions and 4 deletions

View File

@ -11,11 +11,10 @@ import net.sourceforge.pmd.lang.java.ast.JavaVersion.*
import java.io.IOException
class ASTPatternTest : ParserTestSpec({
val typePatternsVersions = JavaVersion.since(J16)
parserTest("Test patterns only available on JDK16 or higher (including preview)",
javaVersions = JavaVersion.values().asList().minus(J16)
.minus(J17).minus(J17__PREVIEW)
.minus(J18).minus(J18__PREVIEW)) {
javaVersions = JavaVersion.except(typePatternsVersions)) {
expectParseException("Pattern Matching for instanceof is only supported with JDK >= 16") {
parseAstExpression("obj instanceof Class c")
@ -23,7 +22,7 @@ class ASTPatternTest : ParserTestSpec({
}
parserTest("Test simple patterns", javaVersions = listOf(J16, J17, J18)) {
parserTest("Test simple patterns", javaVersions = typePatternsVersions) {
importedTypes += IOException::class.java

View File

@ -47,6 +47,13 @@ enum class JavaVersion : Comparable<JavaVersion> {
companion object {
val Latest = values().last()
val Earliest = values().first()
fun since(v: JavaVersion) = v.rangeTo(Latest)
fun except(v1: JavaVersion, vararg versions: JavaVersion) =
values().toList() - v1 - versions
fun except(versions: List<JavaVersion>) = values().toList() - versions
}
}