"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt" between
pmd-src-6.37.0.zip and pmd-src-6.38.0.zip

About: PMD is a source code analyzer for Java, JavaScript, XML and others. It finds unused variables, empty catch blocks, unnecessary object creation, and so forth. Sources (Java).

TestUtils.kt  (pmd-src-6.37.0):TestUtils.kt  (pmd-src-6.38.0)
/* /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/ */
package net.sourceforge.pmd.lang.ast.test package net.sourceforge.pmd.lang.ast.test
import io.kotest.matchers.Matcher
import io.kotest.matchers.equalityMatcher
import io.kotest.matchers.should import io.kotest.matchers.should
import net.sourceforge.pmd.Report
import net.sourceforge.pmd.RuleViolation
import net.sourceforge.pmd.lang.ast.Node
import kotlin.reflect.KCallable import kotlin.reflect.KCallable
import kotlin.reflect.jvm.isAccessible import kotlin.reflect.jvm.isAccessible
import io.kotest.matchers.shouldBe as ktShouldBe import kotlin.test.assertEquals
/** /**
* Extension to add the name of a property to error messages. * Extension to add the name of a property to error messages.
* *
* @see [shouldBe]. * @see [shouldBe].
*/ */
infix fun <N, V : N> KCallable<N>.shouldEqual(expected: V?) = infix fun <N, V : N> KCallable<N>.shouldEqual(expected: V?) =
assertWrapper(this, expected) { n, v -> n ktShouldBe v } assertWrapper(this, expected) { n, v ->
// using shouldBe would perform numeric conversion
// eg (3.0 shouldBe 3L) passes, even though (3.0 != 3L)
// equalityMatcher doesn't do this conversion
n.should(equalityMatcher(v) as Matcher<N>)
}
private fun <N, V> assertWrapper(callable: KCallable<N>, right: V, asserter: (N, V) -> Unit) { private fun <N, V> assertWrapper(callable: KCallable<N>, right: V, asserter: (N, V) -> Unit) {
fun formatName() = "::" + callable.name.removePrefix("get").decapitalize() fun formatName() = "::" + callable.name.removePrefix("get").decapitalize()
val value: N = try { val value: N = try {
callable.isAccessible = true callable.isAccessible = true
callable.call() callable.call()
} catch (e: Exception) { } catch (e: Exception) {
throw RuntimeException("Couldn't fetch value for property ${formatName() }", e) throw RuntimeException("Couldn't fetch value for property ${formatName() }", e)
skipping to change at line 57 skipping to change at line 67
* For properties synthesized from Java getters starting with "get", you * For properties synthesized from Java getters starting with "get", you
* have to use the name of the getter instead of that of the generated * have to use the name of the getter instead of that of the generated
* property (with the get prefix). * property (with the get prefix).
* *
* If this conflicts with [io.kotest.matchers.shouldBe], use the equivalent [sho uldEqual] * If this conflicts with [io.kotest.matchers.shouldBe], use the equivalent [sho uldEqual]
* *
*/ */
infix fun <N, V : N> KCallable<N>.shouldBe(expected: V?) = this.shouldEqual(expe cted) infix fun <N, V : N> KCallable<N>.shouldBe(expected: V?) = this.shouldEqual(expe cted)
infix fun <T> KCallable<T>.shouldMatch(expected: T.() -> Unit) = assertWrapper(t his, expected) { n, v -> n should v } infix fun <T> KCallable<T>.shouldMatch(expected: T.() -> Unit) = assertWrapper(t his, expected) { n, v -> n should v }
inline fun <reified T> Any?.shouldBeA(f: (T) -> Unit = {}): T {
if (this is T) {
f(this)
return this
} else throw AssertionError("Expected an instance of ${T::class.java}, got $
this")
}
operator fun <T> List<T>.component6() = get(5)
operator fun <T> List<T>.component7() = get(6)
operator fun <T> List<T>.component8() = get(7)
operator fun <T> List<T>.component9() = get(8)
operator fun <T> List<T>.component10() = get(9)
operator fun <T> List<T>.component11() = get(10)
/** Assert number of violations. */
fun assertSize(report: Report, size: Int): List<RuleViolation> {
assertEquals(size, report.violations.size, message = "Wrong number of violat
ions!")
return report.violations
}
/** Assert number of suppressed violations. */
fun assertSuppressed(report: Report, size: Int): List<Report.SuppressedViolation
> {
assertEquals(size, report.suppressedViolations.size, message = "Wrong number
of suppressed violations!")
return report.suppressedViolations
}
/** Checks the coordinates of this node. */
fun Node.assertPosition(bline: Int, bcol: Int, eline: Int, ecol: Int) {
this::getBeginLine shouldBe bline
this::getBeginColumn shouldBe bcol
this::getEndLine shouldBe eline
this::getEndColumn shouldBe ecol
}
 End of changes. 5 change blocks. 
2 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)