-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation test for JEP 432: Record Patterns (#1415)
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...test.validation.java20/src/org/jacoco/core/test/validation/java20/RecordPatternsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2023 Mountainminds GmbH & Co. KG and Contributors | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.test.validation.java20; | ||
|
||
import org.jacoco.core.test.validation.ValidationTestBase; | ||
import org.jacoco.core.test.validation.java20.targets.RecordPatternsTarget; | ||
|
||
/** | ||
* Test of code coverage in {@link RecordPatterns}. | ||
*/ | ||
public class RecordPatternsTest extends ValidationTestBase { | ||
|
||
public RecordPatternsTest() { | ||
super(RecordPatternsTarget.class); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ation.java20/src/org/jacoco/core/test/validation/java20/targets/RecordPatternsTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2023 Mountainminds GmbH & Co. KG and Contributors | ||
* This program and the accompanying materials are made available under | ||
* the terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.test.validation.java20.targets; | ||
|
||
import static org.jacoco.core.test.validation.targets.Stubs.nop; | ||
|
||
/** | ||
* This target exercises Record Patterns | ||
* (<a href="https://openjdk.org/jeps/432">JEP 432</a>). | ||
*/ | ||
public class RecordPatternsTarget { | ||
|
||
private record Point(int x, int y) { | ||
} | ||
|
||
private static void instanceofOperator(Object o) { | ||
if (o instanceof Point(int x,int y)) { // assertPartlyCovered(0, 2) | ||
nop(x + y); // assertFullyCovered() | ||
} // assertEmpty() | ||
} | ||
|
||
private static void switchStatement(Object p) { | ||
switch (p) { // assertFullyCovered(0, 2) | ||
case Point(int x, int y) -> nop(x + y); // assertFullyCovered() | ||
default -> nop(); // assertPartlyCovered() | ||
} // assertEmpty() | ||
} | ||
|
||
private static void enhancedForStatement(Point[] p) { | ||
for (Point(int x, int y) : p) { // assertPartlyCovered(2, 3) | ||
nop(x + y); // assertFullyCovered() | ||
} // assertEmpty() | ||
} | ||
|
||
public static void main(String[] args) { | ||
instanceofOperator(new Point(1, 2)); | ||
instanceofOperator(new Object()); | ||
|
||
switchStatement(new Point(1, 2)); | ||
switchStatement(new Object()); | ||
|
||
enhancedForStatement(new Point[] { new Point(1, 2) }); | ||
} | ||
|
||
} |