From 9648a6c9c660e745e11cd6f92ffb236b00393a11 Mon Sep 17 00:00:00 2001 From: Federico Tomassetti Date: Wed, 27 Sep 2023 15:48:53 +0200 Subject: [PATCH] update tests because of changes in LionWeb --- .../kolasu/kcp/FieldObservableExtension.kt | 3 +-- .../kolasu/kcp/SettingParentExtension.kt | 4 +++- lionweb/build.gradle.kts | 3 +++ .../kolasu/lionweb/LionWebModelConverter.kt | 2 +- .../lionweb/LionWebLanguageConverterTest.kt | 2 +- .../lionweb/LionWebModelConverterTest.kt | 19 ++++++++++++++----- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/FieldObservableExtension.kt b/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/FieldObservableExtension.kt index 8f23b4a5b..9789bfae2 100644 --- a/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/FieldObservableExtension.kt +++ b/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/FieldObservableExtension.kt @@ -4,7 +4,6 @@ package com.strumenta.kolasu.kcp import com.strumenta.kolasu.model.Node import com.strumenta.kolasu.model.ReferenceByName -import org.jetbrains.kotlin.GeneratedDeclarationKey import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext @@ -56,7 +55,7 @@ class FieldObservableExtension(val pluginContext: IrPluginContext) : IrElementTr val anonymousInitializerSymbolImpl = IrFactoryImpl.createAnonymousInitializer( declaration.startOffset, declaration.endOffset, - IrDeclarationOrigin.GeneratedByPlugin(object : GeneratedDeclarationKey() {}), + IrDeclarationOrigin.GeneratedByPlugin(StarLasuGeneratedDeclarationKey), IrAnonymousInitializerSymbolImpl(), false ) diff --git a/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/SettingParentExtension.kt b/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/SettingParentExtension.kt index e1ea95737..951f63144 100644 --- a/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/SettingParentExtension.kt +++ b/kotlin-ir-plugin/src/main/kotlin/com/strumenta/kolasu/kcp/SettingParentExtension.kt @@ -35,6 +35,8 @@ import org.jetbrains.kotlin.ir.util.statements import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull +object StarLasuGeneratedDeclarationKey : GeneratedDeclarationKey() + /** * Set the parent appropriately when modifying a containment value. */ @@ -88,7 +90,7 @@ class SettingParentExtension(val pluginContext: IrPluginContext, val messageColl val anonymousInitializerSymbolImpl = IrFactoryImpl.createAnonymousInitializer( -1, -1, - IrDeclarationOrigin.GeneratedByPlugin(object : GeneratedDeclarationKey() {}), + IrDeclarationOrigin.GeneratedByPlugin(StarLasuGeneratedDeclarationKey), IrAnonymousInitializerSymbolImpl(), false ) diff --git a/lionweb/build.gradle.kts b/lionweb/build.gradle.kts index f0ce42391..2bb976e9f 100644 --- a/lionweb/build.gradle.kts +++ b/lionweb/build.gradle.kts @@ -9,10 +9,13 @@ plugins { val lionwebVersion = extra["lionwebVersion"] val kotlinVersion = extra["kotlinVersion"] val clikt_version = extra["clikt_version"] +val gson_version = extra["gson_version"] dependencies { implementation("com.github.ajalt.clikt:clikt:$clikt_version") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion") + testImplementation("com.google.code.gson:gson:$gson_version") + testImplementation("io.github.mkfl3x:json-delta:1.3") implementation("io.lionweb.lioncore-java:lioncore-java-core:$lionwebVersion") api(project(":core")) } diff --git a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt index f67f0ced9..353d986fb 100644 --- a/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt +++ b/lionweb/src/main/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverter.kt @@ -120,7 +120,7 @@ class LionWebModelConverter { fun unserializeToNodes(json: String, useDynamicNodesIfNeeded: Boolean = true): List { val js = JsonSerialization.getStandardSerialization() languageConverter.knownLWLanguages().forEach { - js.conceptResolver.registerLanguage(it) + js.classifierResolver.registerLanguage(it) } if (useDynamicNodesIfNeeded) { js.enableDynamicNodes() diff --git a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt index 69996fc34..eaf334517 100644 --- a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt +++ b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebLanguageConverterTest.kt @@ -110,7 +110,7 @@ class LionWebLanguageConverterTest { assertEquals(false, simpleNodeBValue.isOptional) assertEquals(LionCoreBuiltins.getString(), simpleNodeBValue.type) - val validationResult = LanguageValidator().validateLanguage(lwLanguage) + val validationResult = LanguageValidator().validate(lwLanguage) assertEquals(true, validationResult.isSuccessful, validationResult.issues.toString()) } } diff --git a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt index 4cbd1b860..66c39e6e6 100644 --- a/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt +++ b/lionweb/src/test/kotlin/com/strumenta/kolasu/lionweb/LionWebModelConverterTest.kt @@ -5,9 +5,11 @@ import com.strumenta.kolasu.model.ReferenceByName import com.strumenta.kolasu.model.assignParents import com.strumenta.kolasu.testing.assertASTsAreEqual import io.lionweb.lioncore.java.serialization.JsonSerialization +import org.mkfl3x.jsondelta.JsonDelta import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertSame +import kotlin.test.assertTrue class LionWebModelConverterTest { @@ -52,6 +54,7 @@ class LionWebModelConverterTest { } ], "references": [], + "annotations":[], "parent": null }, { @@ -64,9 +67,9 @@ class LionWebModelConverterTest { "properties": [ { "property": { - "language": "LIonCore-builtins", + "language": "LionCore-builtins", "version": "1", - "key": "LIonCore-builtins-INamed-name" + "key": "LionCore-builtins-INamed-name" }, "value": "A1" } @@ -96,6 +99,7 @@ class LionWebModelConverterTest { ] } ], + "annotations":[], "parent": "UNKNOWN_SOURCE_root" }, { @@ -117,6 +121,7 @@ class LionWebModelConverterTest { ], "children": [], "references": [], + "annotations":[], "parent": "UNKNOWN_SOURCE_root" }, { @@ -129,9 +134,9 @@ class LionWebModelConverterTest { "properties": [ { "property": { - "language": "LIonCore-builtins", + "language": "LionCore-builtins", "version": "1", - "key": "LIonCore-builtins-INamed-name" + "key": "LionCore-builtins-INamed-name" }, "value": "A3" } @@ -163,6 +168,7 @@ class LionWebModelConverterTest { ] } ], + "annotations":[], "parent": "UNKNOWN_SOURCE_root" }, { @@ -184,6 +190,7 @@ class LionWebModelConverterTest { ], "children": [], "references": [], + "annotations":[], "parent": "UNKNOWN_SOURCE_root_childrez_2" } ] @@ -244,7 +251,9 @@ class LionWebModelConverterTest { assertSame(child1, refValue3[0].referred) val js = JsonSerialization.getStandardSerialization() - assertEquals(serialized, js.serializeTreeToJsonString(lwAST)) + + val report = JsonDelta().compare(serialized, js.serializeTreeToJsonString(lwAST)) + assertTrue(report.success, message = "Mismatches: ${report.mismatches}") } @Test