[java] Fix unit tests for new version 18

This commit is contained in:
Andreas Dangel
2022-03-10 12:22:24 +01:00
parent b3ab5f0c40
commit 1e042ce4d0
3 changed files with 13 additions and 11 deletions

View File

@ -529,30 +529,30 @@ public class JavaParser {
}
private boolean isJEP406Supported() {
return jdkVersion == 17 && preview;
return (jdkVersion == 17 || jdkVersion == 18) && preview;
}
private void checkForPatternMatchingInSwitch() {
if (!isJEP406Supported()) {
throwParseException("Pattern Matching in Switch is only supported with JDK 17 Preview.");
throwParseException("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview.");
}
}
private void checkForNullCaseLabel() {
if (!isJEP406Supported()) {
throwParseException("Null case labels in switch are only supported with JDK 17 Preview.");
throwParseException("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview.");
}
}
private void checkForDefaultCaseLabel() {
if (!isJEP406Supported()) {
throwParseException("Default case labels in switch are only supported with JDK 17 Preview.");
throwParseException("Default case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview.");
}
}
private void checkForGuardedPatterns() {
if (!isJEP406Supported()) {
throwParseException("Guarded patterns are only supported with JDK 17 Preview.");
throwParseException("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview.");
}
}

View File

@ -38,7 +38,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview."));
thrown.getMessage().contains("Pattern Matching in Switch is only supported with JDK 17 Preview or JDK 18 Preview."));
}
@Test
@ -65,7 +65,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview."));
thrown.getMessage().contains("Null case labels in switch are only supported with JDK 17 Preview or JDK 18 Preview."));
}
@Test
@ -82,7 +82,7 @@ public class Java17PreviewTreeDumpTest extends BaseTreeDumpTest {
}
});
Assert.assertTrue("Unexpected message: " + thrown.getMessage(),
thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview."));
thrown.getMessage().contains("Guarded patterns are only supported with JDK 17 Preview or JDK 18 Preview."));
}
@Test

View File

@ -12,8 +12,10 @@ import java.io.IOException
class ASTPatternTest : ParserTestSpec({
parserTest("Test patterns only available on JDK16 and JDK16 (preview) and JDK17 and JDK 17 (preview)",
javaVersions = JavaVersion.values().asList().minus(J16).minus(J16__PREVIEW).minus(J17).minus(J17__PREVIEW)) {
parserTest("Test patterns only available on JDK16 or higher (including preview)",
javaVersions = JavaVersion.values().asList().minus(J16).minus(J16__PREVIEW)
.minus(J17).minus(J17__PREVIEW)
.minus(J18).minus(J18__PREVIEW)) {
expectParseException("Pattern Matching for instanceof is only supported with JDK >= 16") {
parseAstExpression("obj instanceof Class c")
@ -21,7 +23,7 @@ class ASTPatternTest : ParserTestSpec({
}
parserTest("Test simple patterns", javaVersions = listOf(J16, J17)) {
parserTest("Test simple patterns", javaVersions = listOf(J16, J17, J18)) {
importedTypes += IOException::class.java