Commit to FunSpec style

* Move everything inside ParsingCtx. It's extensible and can accommodate more
configuration options without breaking clients/ dealing with many optional parameters.
* Create tests for CatchStatement.
* Child calls now return the matched node.
* Change behaviour of ignoreChildren: it throws an exception if 'child' is called.
This is to be consistent with the previous item.
This commit is contained in:
Clément Fournier
2018-09-04 12:30:30 +02:00
parent 84ac91b373
commit 1eb5b7a7c9
4 changed files with 252 additions and 170 deletions
@@ -0,0 +1,64 @@
package net.sourceforge.pmd.lang.java.ast
import io.kotlintest.matchers.collections.shouldContainExactly
import io.kotlintest.should
import io.kotlintest.shouldBe
import io.kotlintest.specs.FunSpec
import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest
import net.sourceforge.pmd.lang.java.ast.JavaVersion.J1_5
import net.sourceforge.pmd.lang.java.ast.JavaVersion.J1_7
import java.io.IOException
class ASTCatchStatementTest : FunSpec({
parserTest("Test single type", javaVersions = J1_5..Latest) {
importedTypes += IOException::class.java
"try { } catch (IOException ioe) { }" should matchStmt<ASTTryStatement> {
child<ASTBlock> { }
child<ASTCatchStatement> {
it.isMulticatchStatement shouldBe false
unspecifiedChildren(2)
}
}
}
parserTest("Test multicatch", javaVersions = J1_7..Latest) {
importedTypes += IOException::class.java
"try { } catch (IOException | AssertionError e) { }" should matchStmt<ASTTryStatement> {
child<ASTBlock> { }
child<ASTCatchStatement> {
it.isMulticatchStatement shouldBe true
val catchNode = it
child<ASTFormalParameter> {
val ioe = child<ASTType>(ignoreChildren = true) {
it.type shouldBe IOException::class.java
}
val aerr = child<ASTType>(ignoreChildren = true) {
it.type shouldBe java.lang.AssertionError::class.java
}
catchNode.caughtExceptionTypeNodes.shouldContainExactly(ioe, aerr)
catchNode.caughtExceptionTypes.shouldContainExactly(catchNode.caughtExceptionTypeNodes.map { it.type })
child<ASTVariableDeclaratorId> { }
}
child<ASTBlock> { }
}
}
}
})
@@ -9,7 +9,7 @@ import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest
class Java11Test : FunSpec({
parserTest("Test lambda parameter with var keyword", javaVersionRange = J1_8..J10) {
parserTest("Test lambda parameter with var keyword", javaVersions = J1_8..J10) {
"(var x) -> String.valueOf(x)" should matchExpr<ASTLambdaExpression> {
child<ASTFormalParameters> {
@@ -75,7 +75,7 @@ class Java11Test : FunSpec({
}
}
parserTest("Test lambda parameter with var keyword", javaVersionRange = J11..Latest) {
parserTest("Test lambda parameter with var keyword", javaVersions = J11..Latest) {
"(var x) -> String.valueOf(x)" should matchExpr<ASTLambdaExpression> {
child<ASTFormalParameters> {
File diff suppressed because it is too large Load Diff