forked from phoedos/pmd
Merge branch 'text-utils-simple' into text-utils-javacc
This commit is contained in:
@@ -23,7 +23,7 @@ infix fun TextAvailableNode.shouldHaveText(str: String) {
|
||||
inline fun <reified T : Node> Node.getDescendantsOfType(): List<T> = descendants(T::class.java).toList()
|
||||
inline fun <reified T : Node> Node.getFirstDescendantOfType(): T = descendants(T::class.java).firstOrThrow()
|
||||
|
||||
fun TextAvailableNode.textOfReportLocation(): String? =
|
||||
fun Node.textOfReportLocation(): String? =
|
||||
reportLocation.regionInFile?.let(textDocument::sliceOriginalText)?.toString()
|
||||
|
||||
|
||||
|
@@ -65,7 +65,7 @@ open class BaseNodeAttributePrinter : TextTreeRenderer(true, -1) {
|
||||
node.xPathAttributesIterator
|
||||
.asSequence()
|
||||
.filterNot { ignoreAttribute(node, it) }
|
||||
.map { AttributeInfo(it.name, it.value?.toString()) }
|
||||
.map { AttributeInfo(it.name, it.value) }
|
||||
.forEach { result += it }
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ open class BaseNodeAttributePrinter : TextTreeRenderer(true, -1) {
|
||||
is Char -> '\''.toString() + value.toString().replace("'".toRegex(), "\\'") + '\''.toString()
|
||||
is Enum<*> -> value.enumDeclaringClass.simpleName + "." + value.name
|
||||
is Class<*> -> value.canonicalName?.let { "$it.class" }
|
||||
is Number, is Boolean, null -> value.toString()
|
||||
is Number, is Boolean -> value.toString()
|
||||
null -> "null"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ast.test
|
||||
|
||||
import io.kotest.assertions.withClue
|
||||
import io.kotest.matchers.Matcher
|
||||
import io.kotest.matchers.equalityMatcher
|
||||
import io.kotest.matchers.should
|
||||
@@ -94,13 +95,21 @@ fun assertSuppressed(report: Report, size: Int): List<Report.SuppressedViolation
|
||||
return report.suppressedViolations
|
||||
}
|
||||
|
||||
/** Checks the coordinates of this node. */
|
||||
/**
|
||||
* Checks the coordinates of this node.
|
||||
* Note that this tests the report location which might not be
|
||||
* the exact boundaries of the node in the text.
|
||||
*
|
||||
* See [Node.getReportLocation].
|
||||
*/
|
||||
fun Node.assertPosition(bline: Int, bcol: Int, eline: Int, ecol: Int) {
|
||||
reportLocation.apply {
|
||||
this::getStartLine shouldBe bline
|
||||
this::getStartColumn shouldBe bcol
|
||||
this::getEndLine shouldBe eline
|
||||
this::getEndColumn shouldBe ecol
|
||||
withClue(this.toRange2d()) {
|
||||
this::getStartLine shouldBe bline
|
||||
this::getStartColumn shouldBe bcol
|
||||
this::getEndLine shouldBe eline
|
||||
this::getEndColumn shouldBe ecol
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user