From 6e23cd7e8df15f10a888415e418cd54fbb969669 Mon Sep 17 00:00:00 2001 From: Yogesh Ananda Nikam Date: Fri, 13 Dec 2024 19:26:01 +0530 Subject: [PATCH 1/2] Enable assertion support for other libs depending on specmatic-core --- .../io/specmatic/test/ExamplePreProcessor.kt | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/core/src/main/kotlin/io/specmatic/test/ExamplePreProcessor.kt b/core/src/main/kotlin/io/specmatic/test/ExamplePreProcessor.kt index c7dd8be75..6e6eb9f89 100644 --- a/core/src/main/kotlin/io/specmatic/test/ExamplePreProcessor.kt +++ b/core/src/main/kotlin/io/specmatic/test/ExamplePreProcessor.kt @@ -47,11 +47,11 @@ object ExampleProcessor { runningEntity = emptyMap() } - private fun defaultIfNotExits(lookupKey: String, type: SubstitutionType = SubstitutionType.SIMPLE): Value { + fun defaultIfNotExits(lookupKey: String, type: SubstitutionType = SubstitutionType.SIMPLE): Value { throw ContractException(breadCrumb = lookupKey, errorMessage = "Could not resolve ${lookupKey.quote()}, key does not exist in fact store") } - private fun ifNotExitsToLookupPattern(lookupKey: String, type: SubstitutionType = SubstitutionType.SIMPLE): Value { + fun ifNotExitsToLookupPattern(lookupKey: String, type: SubstitutionType = SubstitutionType.SIMPLE): Value { return when (type) { SubstitutionType.SIMPLE -> StringValue("$($lookupKey)") SubstitutionType.DELAYED_RANDOM -> StringValue("$delayedRandomSubstitutionKey($lookupKey)") @@ -121,15 +121,7 @@ object ExampleProcessor { return value.mapValues { (_, value) -> resolve(value, ifNotExists) } } - private fun resolve(value: String, ifNotExists: (lookupKey: String, type: SubstitutionType) -> Value): String { - return value.ifSubstitutionToken { token, type -> - if (type == SubstitutionType.DELAYED_RANDOM && ifNotExists == ::ifNotExitsToLookupPattern ) { - return@ifSubstitutionToken ifNotExitsToLookupPattern(token, type).toStringLiteral() - } else getValue(token, type)?.toStringLiteral() ?: ifNotExists(token, type).toStringLiteral() - } ?: value - } - - private fun resolve(value: Value, ifNotExists: (lookupKey: String, type: SubstitutionType) -> Value): Value { + fun resolve(value: Value, ifNotExists: (lookupKey: String, type: SubstitutionType) -> Value): Value { return when (value) { is StringValue -> resolve(value, ifNotExists) is JSONObjectValue -> resolve(value, ifNotExists) @@ -138,6 +130,14 @@ object ExampleProcessor { } } + private fun resolve(value: String, ifNotExists: (lookupKey: String, type: SubstitutionType) -> Value): String { + return value.ifSubstitutionToken { token, type -> + if (type == SubstitutionType.DELAYED_RANDOM && ifNotExists == ::ifNotExitsToLookupPattern ) { + return@ifSubstitutionToken ifNotExitsToLookupPattern(token, type).toStringLiteral() + } else getValue(token, type)?.toStringLiteral() ?: ifNotExists(token, type).toStringLiteral() + } ?: value + } + private fun resolve(value: StringValue, ifNotExists: (lookupKey: String, type: SubstitutionType) -> Value): Value { return value.ifSubstitutionToken { token, type -> if (type == SubstitutionType.DELAYED_RANDOM && ifNotExists == ::ifNotExitsToLookupPattern) { @@ -170,6 +170,10 @@ object ExampleProcessor { } } + fun store(exampleValue: Value) { + runningEntity = exampleValue.toFactStore(prefix = "ENTITY") + } + private fun Value.ifContainsStoreToken(block: (storeType: StoreType) -> Unit) { if (this !is JSONObjectValue) return @@ -182,7 +186,7 @@ object ExampleProcessor { } /* PARSER HELPERS */ - private fun Value.toFactStore(prefix: String = ""): Map { + fun Value.toFactStore(prefix: String = ""): Map { return this.traverse( prefix = prefix, onScalar = { scalar, key -> mapOf(key to scalar) }, @@ -221,7 +225,7 @@ object ExampleProcessor { } } -internal fun Value.traverse( +fun Value.traverse( prefix: String = "", onScalar: (Value, String) -> Map, onComposite: ((Value, String) -> Map)? = null, onAssert: ((Value, String) -> Map)? = null ): Map { From db8f3431f8cef0326e2246a566ea8a0f5a550a5a Mon Sep 17 00:00:00 2001 From: Hari Krishnan Date: Wed, 18 Dec 2024 21:33:32 +0530 Subject: [PATCH 2/2] Updating version to 2.0.49 --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index f19e8526e..4edea831b 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -version=2.0.48 +version=2.0.49