Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java50
1 files changed, 40 insertions, 10 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
index f853c26f9..2f13e97c3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java
@@ -7,6 +7,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -15,6 +19,7 @@ package org.eclipse.jdt.core.tests.compiler.regression;
import java.io.IOException;
import java.util.Map;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.core.util.ClassFormatException;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -27,7 +32,7 @@ public class PatternMatching16Test extends AbstractRegressionTest {
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
-// TESTS_NAMES = new String[] { "test063b" };
+// TESTS_NAMES = new String[] { "testBug575035" };
}
public static Class<?> testClass() {
@@ -42,18 +47,16 @@ public class PatternMatching16Test extends AbstractRegressionTest {
// Enables the tests to run individually
protected Map<String, String> getCompilerOptions(boolean preview) {
Map<String, String> defaultOptions = super.getCompilerOptions();
- defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
- defaultOptions.put(CompilerOptions.OPTION_EnablePreviews,
- preview ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
- defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING);
+ if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel()
+ && preview) {
+ defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED);
+ }
return defaultOptions;
}
@Override
protected void runConformTest(String[] testFiles, String expectedOutput, Map<String, String> customOptions) {
- if(!isJRE15Plus)
+ if(!isJRE16Plus)
return;
runConformTest(testFiles, expectedOutput, customOptions, new String[] {"--enable-preview"}, JAVAC_OPTIONS);
}
@@ -91,7 +94,7 @@ public class PatternMatching16Test extends AbstractRegressionTest {
"1. ERROR in X1.java (at line 3)\n" +
" if (obj instanceof String s) {\n" +
" ^^^^^^^^\n" +
- "The Java feature 'Pattern Matching in instanceof Expressions' is only available with source level "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +" and above\n" +
+ "The Java feature 'Pattern Matching in instanceof Expressions' is only available with source level 16 and above\n" +
"----------\n",
null,
true,
@@ -101,6 +104,8 @@ public class PatternMatching16Test extends AbstractRegressionTest {
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16);
}
public void test000b() {
+ if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel())
+ return;
Map<String, String> options = getCompilerOptions(true);
options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14);
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14);
@@ -119,7 +124,7 @@ public class PatternMatching16Test extends AbstractRegressionTest {
"1. ERROR in X1.java (at line 0)\n" +
" public class X1 {\n" +
" ^\n" +
- "Preview features enabled at an invalid source release level 14, preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" +
+ "Preview features enabled at an invalid source release level 14, preview can be enabled only at source level 17\n" +
"----------\n",
null,
true,
@@ -3861,6 +3866,31 @@ public class PatternMatching16Test extends AbstractRegressionTest {
options);
}
+ public void testBug573880() {
+ if (this.complianceLevel < ClassFileConstants.JDK17)
+ return;
+ Map<String, String> compilerOptions = getCompilerOptions(true);
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"
+ + " public void foo(Object o) {\n"
+ + " if (o instanceof var s) {\n"
+ + " System.out.println(s);\n"
+ + " }\n"
+ + " }\n"
+ + "}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " if (o instanceof var s) {\n" +
+ " ^^^\n" +
+ "\'var\' is not allowed here\n" +
+ "----------\n",
+ null,
+ true,
+ compilerOptions);
+ }
public void testBug574906() {
Map<String, String> options = getCompilerOptions(false);
runConformTest(

Back to the top