From fa572947a64f0cc111a1835ed6774494b9638b13 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 7 Nov 2019 16:24:13 +0100 Subject: [PATCH] Fixed bug in checking the parameters size of a member function (it always contains an extra one) --- util/test/util.kt | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/test/util.kt b/util/test/util.kt index 8844f4bd..d489efe4 100644 --- a/util/test/util.kt +++ b/util/test/util.kt @@ -119,32 +119,38 @@ fun checkParametersOfConstructor( kClass: KClass<*>, params: List> ) { - checkParameters("constructor of '${kClass.simpleName}'", constructor, params) + checkParameters("constructor of '${kClass.simpleName}'", constructor, params, isTopLevel = true) } fun checkParametersOfTopLevelFunction( function: KFunction<*>, params: List> ) { - checkParameters("function '${function.name}'", function, params) + checkParameters("function '${function.name}'", function, params, isTopLevel = true) } fun checkParametersOfMemberFunction( function: KFunction<*>, params: List> ) { - checkParametersOfTopLevelFunction(function, + checkParameters("function '${function.name}'", function, listOf("" to "") // this parameter refers to a class and ignored while checking - + params) + + params, + isTopLevel = false) } private fun checkParameters( funcOrConstructorName: String, function: KFunction<*>, - params: List> + params: List>, + isTopLevel: Boolean ) { - Assert.assertEquals("${funcOrConstructorName.capitalize()} is expected to have ${params.size} parameter(s)", - params.size, function.parameters.size) + // excluding an extra parameter from checking + fun Int.decIfMember() = if (isTopLevel) this else this - 1 + val expectedSize = params.size.decIfMember() + val actualSize = function.parameters.size.decIfMember() + Assert.assertEquals("${funcOrConstructorName.capitalize()} is expected to have $expectedSize parameter(s)", + expectedSize, actualSize) val expectedParams = params.toList() function.parameters.forEachIndexed { index, kParameter ->