Skip to content

Commit

Permalink
Add validation test for JEP 432: Record Patterns (#1415)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored Mar 27, 2023
1 parent 5f12145 commit 461ebf3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
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);
}

}
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) });
}

}

0 comments on commit 461ebf3

Please sign in to comment.