Skip to content

Commit 461ebf3

Browse files
authored
Add validation test for JEP 432: Record Patterns (#1415)
1 parent 5f12145 commit 461ebf3

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2023 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.test.validation.java20;
14+
15+
import org.jacoco.core.test.validation.ValidationTestBase;
16+
import org.jacoco.core.test.validation.java20.targets.RecordPatternsTarget;
17+
18+
/**
19+
* Test of code coverage in {@link RecordPatterns}.
20+
*/
21+
public class RecordPatternsTest extends ValidationTestBase {
22+
23+
public RecordPatternsTest() {
24+
super(RecordPatternsTarget.class);
25+
}
26+
27+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2009, 2023 Mountainminds GmbH & Co. KG and Contributors
3+
* This program and the accompanying materials are made available under
4+
* the terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Evgeny Mandrikov - initial API and implementation
11+
*
12+
*******************************************************************************/
13+
package org.jacoco.core.test.validation.java20.targets;
14+
15+
import static org.jacoco.core.test.validation.targets.Stubs.nop;
16+
17+
/**
18+
* This target exercises Record Patterns
19+
* (<a href="https://openjdk.org/jeps/432">JEP 432</a>).
20+
*/
21+
public class RecordPatternsTarget {
22+
23+
private record Point(int x, int y) {
24+
}
25+
26+
private static void instanceofOperator(Object o) {
27+
if (o instanceof Point(int x,int y)) { // assertPartlyCovered(0, 2)
28+
nop(x + y); // assertFullyCovered()
29+
} // assertEmpty()
30+
}
31+
32+
private static void switchStatement(Object p) {
33+
switch (p) { // assertFullyCovered(0, 2)
34+
case Point(int x, int y) -> nop(x + y); // assertFullyCovered()
35+
default -> nop(); // assertPartlyCovered()
36+
} // assertEmpty()
37+
}
38+
39+
private static void enhancedForStatement(Point[] p) {
40+
for (Point(int x, int y) : p) { // assertPartlyCovered(2, 3)
41+
nop(x + y); // assertFullyCovered()
42+
} // assertEmpty()
43+
}
44+
45+
public static void main(String[] args) {
46+
instanceofOperator(new Point(1, 2));
47+
instanceofOperator(new Object());
48+
49+
switchStatement(new Point(1, 2));
50+
switchStatement(new Object());
51+
52+
enhancedForStatement(new Point[] { new Point(1, 2) });
53+
}
54+
55+
}

0 commit comments

Comments
 (0)