[kpm] kgp-idea-proto: Implement simple serialization tests

^KT-52568 In Progress
This commit is contained in:
sebastian.sellmair
2022-06-13 14:14:10 +02:00
committed by Space
parent d78fb1d4d2
commit 2a5457f59d
17 changed files with 696 additions and 0 deletions
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmSerializationContext
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmExtrasSerializationExtension
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmSerializationLogger
import kotlin.test.assertEquals
abstract class AbstractSerializationTest<T : Any> : IdeaKpmSerializationContext {
final override val logger = TestIdeaKpmSerializationLogger()
final override val extrasSerializationExtension = TestIdeaKpmExtrasSerializationExtension
abstract fun serialize(value: T): ByteArray
abstract fun deserialize(data: ByteArray): T
open fun normalize(value: T): T = value
fun testSerialization(value: T) {
testSerializeAndDeserializeEquals(value)
}
private fun testSerializeAndDeserializeEquals(value: T) {
assertEquals(
normalize(value), deserialize(serialize(value))
)
}
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmBinaryCoordinates
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmBinaryCoordinatesImpl
import org.junit.Test
class BinaryCoordinatesTest : AbstractSerializationTest<IdeaKpmBinaryCoordinates>() {
override fun serialize(value: IdeaKpmBinaryCoordinates): ByteArray = value.toByteArray()
override fun deserialize(data: ByteArray): IdeaKpmBinaryCoordinates = IdeaKpmBinaryCoordinates(data)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmBinaryCoordinatesImpl(
group = "myGroup",
module = "myModule",
version = "myVersion",
kotlinModuleName = null,
kotlinFragmentName = null
)
)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmBinaryCoordinatesImpl(
group = "myGroup",
module = "myModule",
version = "myVersion",
kotlinModuleName = "myModuleName",
kotlinFragmentName = null
)
)
@Test
fun `serialize - deserialize - sample 2`() = testSerialization(
IdeaKpmBinaryCoordinatesImpl(
group = "myGroup",
module = "myModule",
version = "myVersion",
kotlinModuleName = null,
kotlinFragmentName = "myFragmentName"
)
)
}
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmCompilationOutput
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmCompilationOutputImpl
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import kotlin.test.Test
class CompilationOutputTest : AbstractSerializationTest<IdeaKpmCompilationOutput>() {
override fun serialize(value: IdeaKpmCompilationOutput): ByteArray = value.toByteArray()
override fun deserialize(data: ByteArray): IdeaKpmCompilationOutput = IdeaKpmCompilationOutput(data)
@Test
fun `serialize - deserialize - sample 0`() {
testSerialization(TestIdeaKpmInstances.simpleCompilationOutput)
}
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmCompilationOutputImpl(
classesDirs = emptySet(),
resourcesDir = null
)
)
}
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmSerializationContext
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmExtrasSerializationExtension
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmSerializationLogger
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
class ContainerTest : IdeaKpmSerializationContext {
override val logger = TestIdeaKpmSerializationLogger()
override val extrasSerializationExtension = TestIdeaKpmExtrasSerializationExtension
@Test
fun `deserialize - with too high major version - returns null`() {
val data = ideaKpmContainerProto {
schemaVersionMajor = IdeaKpmProtoSchema.versionMajor + 1
schemaVersionMinor = IdeaKpmProtoSchema.versionMinor
schemaVersionPatch = IdeaKpmProtoSchema.versionPatch
}.toByteArray()
assertTrue(logger.reports.isEmpty(), "Expected no reports in logger")
assertNull(IdeaKpmProject(data))
assertTrue(logger.reports.isNotEmpty(), "Expected at least one report in logger")
}
@Test
fun `deserialize - with lower major version - returns object`() {
val data = ideaKpmContainerProto {
schemaVersionMajor = IdeaKpmProtoSchema.versionMajor - 1
schemaVersionMinor = IdeaKpmProtoSchema.versionMinor
schemaVersionPatch = IdeaKpmProtoSchema.versionPatch
project = IdeaKpmProjectProto(TestIdeaKpmInstances.simpleProject)
}.toByteArray()
assertEquals(TestIdeaKpmInstances.simpleProject, IdeaKpmProject(data))
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.tooling.core.*
import kotlin.test.Test
class ExtrasTest : AbstractSerializationTest<Extras>() {
override fun serialize(value: Extras): ByteArray = IdeaKpmExtrasProto(value).toByteArray()
override fun deserialize(data: ByteArray): Extras = Extras(IdeaKpmExtrasProto.parseFrom(data))
override fun normalize(value: Extras): Extras = value.filter { (_, value) -> value !is Ignored }.toExtras()
class Ignored
@Test
fun `serialize - deserialize - sample 0`() {
val extras = mutableExtrasOf(
extrasKeyOf<String>() withValue "myValue",
extrasKeyOf<String>("a") withValue "myValueA",
extrasKeyOf<Int>() withValue 2411,
extrasKeyOf<Ignored>() withValue Ignored()
)
testSerialization(extras)
}
}
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmFragmentCoordinates
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmFragmentCoordinatesImpl
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmModuleCoordinatesImpl
import org.junit.Test
class FragmentCoordinatesTest : AbstractSerializationTest<IdeaKpmFragmentCoordinates>() {
override fun serialize(value: IdeaKpmFragmentCoordinates) = value.toByteArray()
override fun deserialize(data: ByteArray) = IdeaKpmFragmentCoordinates(data)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmFragmentCoordinatesImpl(
module = IdeaKpmModuleCoordinatesImpl(
buildId = "buildId",
projectPath = "projectPath",
projectName = "projectName",
moduleName = "moduleName",
moduleClassifier = null
),
fragmentName = "myFragmentName"
)
)
}
@@ -0,0 +1,69 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmFragmentCoordinatesImpl
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmFragmentDependency
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmFragmentDependencyImpl
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmModuleCoordinatesImpl
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmSerializationContext
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.extrasOf
import org.jetbrains.kotlin.tooling.core.withValue
import kotlin.test.Test
import kotlin.test.assertEquals
class FragmentDependencyTest : AbstractSerializationTest<IdeaKpmFragmentDependency>() {
override fun serialize(value: IdeaKpmFragmentDependency) = value.toByteArray(this)
override fun deserialize(data: ByteArray) = IdeaKpmFragmentDependency(data)
private val coordinates = IdeaKpmFragmentCoordinatesImpl(
module = IdeaKpmModuleCoordinatesImpl(
buildId = "buildId",
projectPath = "projectPath",
projectName = "projectName",
moduleName = "moduleName",
moduleClassifier = "moduleClassifier"
),
fragmentName = "fragmentName"
)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmFragmentDependencyImpl(
type = IdeaKpmFragmentDependency.Type.Regular,
coordinates = coordinates
)
)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmFragmentDependencyImpl(
type = IdeaKpmFragmentDependency.Type.Refines,
coordinates = coordinates
)
)
@Test
fun `serialize - deserialize - sample 2`() = testSerialization(
IdeaKpmFragmentDependencyImpl(
type = IdeaKpmFragmentDependency.Type.Friend,
coordinates = coordinates
)
)
@Test
fun `serialize - deserialize - sample 3`() = testSerialization(
IdeaKpmFragmentDependencyImpl(
type = IdeaKpmFragmentDependency.Type.Regular,
coordinates = coordinates,
extras = extrasOf(extrasKeyOf<String>() withValue "myStringExtras")
)
)
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.*
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import kotlin.test.Test
import kotlin.test.assertEquals
class FragmentTest : AbstractSerializationTest<IdeaKpmFragment>() {
override fun serialize(value: IdeaKpmFragment) = value.toByteArray(this)
override fun deserialize(data: ByteArray) = IdeaKpmFragment(data)
@Test
fun `serialize - deserialize - sample 0`() {
testDeserializedEquals(TestIdeaKpmInstances.simpleFragment)
}
@Test
fun `serialize - deserialize - sample 1`() {
testDeserializedEquals(TestIdeaKpmInstances.fragmentWithExtras)
}
private fun testDeserializedEquals(value: IdeaKpmFragmentImpl) {
val deserialized = IdeaKpmFragment(value.toByteArray(this))
val normalized = value.copy(
dependencies = value.dependencies.map {
if (it !is IdeaKpmResolvedBinaryDependency) return@map it
IdeaKpmResolvedBinaryDependencyImpl(
coordinates = it.coordinates,
binaryType = it.binaryType,
binaryFile = it.binaryFile.absoluteFile,
extras = it.extras
)
},
languageSettings = (value.languageSettings as IdeaKpmLanguageSettingsImpl).copy(
compilerPluginClasspath = value.languageSettings.compilerPluginClasspath.map { it.absoluteFile }
),
sourceDirectories = value.sourceDirectories
.map { it as IdeaKpmSourceDirectoryImpl }
.map { it.copy(file = it.file.absoluteFile) }
)
assertEquals(normalized, deserialized)
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmLanguageSettings
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmLanguageSettingsImpl
import java.io.File
import kotlin.test.Test
class LanguageSettingsTest : AbstractSerializationTest<IdeaKpmLanguageSettings>() {
override fun serialize(value: IdeaKpmLanguageSettings): ByteArray {
return value.toByteArray()
}
override fun deserialize(data: ByteArray): IdeaKpmLanguageSettings {
return IdeaKpmLanguageSettings(data)
}
override fun normalize(value: IdeaKpmLanguageSettings): IdeaKpmLanguageSettings {
value as IdeaKpmLanguageSettingsImpl
return value.copy(
compilerPluginClasspath = value.compilerPluginClasspath.map { it.absoluteFile }
)
}
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmLanguageSettingsImpl(
languageVersion = "1.3",
apiVersion = "1.4",
isProgressiveMode = false,
enabledLanguageFeatures = setOf("some.feature.1"),
optInAnnotationsInUse = setOf("some.opt.in", "some.other.opt.in"),
compilerPluginArguments = listOf("my.argument"),
compilerPluginClasspath = listOf(File("classpath")),
freeCompilerArgs = listOf("free.compiler.arg.1", "free.compiler.arg.2")
)
)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmLanguageSettingsImpl(
languageVersion = null,
apiVersion = "1.7",
isProgressiveMode = true,
enabledLanguageFeatures = emptySet(),
optInAnnotationsInUse = emptySet(),
compilerPluginArguments = emptyList(),
compilerPluginClasspath = emptyList(),
freeCompilerArgs = emptyList()
)
)
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmModuleCoordinates
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmModuleCoordinatesImpl
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import kotlin.test.Test
class ModuleCoordinatesTest : AbstractSerializationTest<IdeaKpmModuleCoordinates>() {
override fun serialize(value: IdeaKpmModuleCoordinates) = value.toByteArray()
override fun deserialize(data: ByteArray) = IdeaKpmModuleCoordinates(data)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(TestIdeaKpmInstances.simpleModuleCoordinates)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmModuleCoordinatesImpl(
buildId = "myBuildId",
projectPath = "myProjectPath",
projectName = "myProjectName",
moduleName = "myModuleName",
moduleClassifier = null
)
)
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmModule
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import kotlin.test.Test
class ModuleTest : AbstractSerializationTest<IdeaKpmModule>() {
override fun serialize(value: IdeaKpmModule): ByteArray {
return value.toByteArray(this)
}
override fun deserialize(data: ByteArray): IdeaKpmModule {
return IdeaKpmModule(data)
}
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(TestIdeaKpmInstances.simpleModule)
}
@@ -0,0 +1,61 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.*
import kotlin.test.Test
import kotlin.test.assertEquals
class PlatformTest : AbstractSerializationTest<IdeaKpmPlatform>() {
override fun serialize(value: IdeaKpmPlatform): ByteArray {
return IdeaKpmPlatformProto(value).toByteArray()
}
override fun deserialize(data: ByteArray): IdeaKpmPlatform {
return IdeaKpmPlatform(IdeaKpmPlatformProto.parseFrom(data))
}
@Test
fun `serialize - deserialize - jvm`() {
val value = IdeaKpmJvmPlatformImpl("jvmTarget")
assertEquals(value, IdeaKpmJvmPlatform(value.toByteArray(this)))
assertEquals(value, IdeaKpmPlatform(IdeaKpmPlatformProto(value)))
testSerialization(value)
}
@Test
fun `serialize - deserialize - native`() {
val value = IdeaKpmNativePlatformImpl("konanTarget")
assertEquals(value, IdeaKpmNativePlatform(value.toByteArray(this)))
assertEquals(value, IdeaKpmPlatform(IdeaKpmPlatformProto(value)))
testSerialization(value)
}
@Test
fun `serialize - deserialize - js`() {
val value = IdeaKpmJsPlatformImpl(true)
assertEquals(value, IdeaKpmJsPlatform(value.toByteArray(this)))
assertEquals(value, IdeaKpmPlatform(IdeaKpmPlatformProto(value)))
testSerialization(value)
}
@Test
fun `serialize - deserialize - wasm`() {
val value = IdeaKpmWasmPlatformImpl()
assertEquals(value, IdeaKpmWasmPlatform(value.toByteArray(this)))
assertEquals(value, IdeaKpmPlatform(IdeaKpmPlatformProto(value)))
testSerialization(value)
}
@Test
fun `serialize - deserialize - unknown`() {
val value = IdeaKpmUnknownPlatformImpl()
assertEquals(value, IdeaKpmUnknownPlatform(value.toByteArray(this)))
assertEquals(value, IdeaKpmPlatform(IdeaKpmPlatformProto(value)))
testSerialization(value)
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmProject
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import kotlin.test.Test
class ProjectTest : AbstractSerializationTest<IdeaKpmProject>() {
override fun serialize(value: IdeaKpmProject): ByteArray {
return value.toByteArray(this)
}
override fun deserialize(data: ByteArray): IdeaKpmProject {
return IdeaKpmProject(data) ?: error("Failed to deserialize kpm project: ${logger.reports}")
}
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(TestIdeaKpmInstances.simpleProject)
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmBinaryCoordinatesImpl
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmResolvedBinaryDependency
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmResolvedBinaryDependencyImpl
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmSerializationContext
import org.jetbrains.kotlin.tooling.core.emptyExtras
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.extrasOf
import org.jetbrains.kotlin.tooling.core.withValue
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals
class ResolvedBinaryDependencyTest : AbstractSerializationTest<IdeaKpmResolvedBinaryDependency>() {
override fun serialize(value: IdeaKpmResolvedBinaryDependency) = value.toByteArray(this)
override fun deserialize(data: ByteArray) = IdeaKpmResolvedBinaryDependency(data)
override fun normalize(value: IdeaKpmResolvedBinaryDependency) =
value.run { this as IdeaKpmResolvedBinaryDependencyImpl }.copy(binaryFile = value.binaryFile.absoluteFile)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmResolvedBinaryDependencyImpl(
null, binaryType = "binaryType", binaryFile = File("bin"), emptyExtras()
)
)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmResolvedBinaryDependencyImpl(
coordinates = IdeaKpmBinaryCoordinatesImpl(
group = "group",
module = "module",
version = "version",
kotlinModuleName = null,
kotlinFragmentName = null
),
binaryType = "binaryType",
binaryFile = File("bin"),
extras = extrasOf(extrasKeyOf<Int>() withValue 2411)
)
)
}
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmSourceDirectory
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmSourceDirectoryImpl
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmSerializationContext
import org.jetbrains.kotlin.tooling.core.emptyExtras
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.extrasOf
import org.jetbrains.kotlin.tooling.core.withValue
import org.junit.Test
import java.io.File
import kotlin.test.assertEquals
class SourceDirectoryTest : AbstractSerializationTest<IdeaKpmSourceDirectory>() {
override fun serialize(value: IdeaKpmSourceDirectory) = value.toByteArray(this)
override fun deserialize(data: ByteArray) = IdeaKpmSourceDirectory(data)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmSourceDirectoryImpl(
File("myFile").absoluteFile, type = "myType", extras = emptyExtras()
)
)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmSourceDirectoryImpl(
File("myFile").absoluteFile, type = "myType", extras = extrasOf(extrasKeyOf<Int>() withValue 1)
)
)
}
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmBinaryCoordinatesImpl
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmUnresolvedBinaryDependency
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmUnresolvedBinaryDependencyImpl
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmSerializationContext
import org.jetbrains.kotlin.tooling.core.emptyExtras
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.extrasOf
import org.jetbrains.kotlin.tooling.core.withValue
import kotlin.test.Test
import kotlin.test.assertEquals
class UnresolvedBinaryTest : AbstractSerializationTest<IdeaKpmUnresolvedBinaryDependency>() {
override fun serialize(value: IdeaKpmUnresolvedBinaryDependency) = value.toByteArray(this)
override fun deserialize(data: ByteArray) = IdeaKpmUnresolvedBinaryDependency(data)
@Test
fun `serialize - deserialize - sample 0`() = testSerialization(
IdeaKpmUnresolvedBinaryDependencyImpl(
null, null, emptyExtras()
)
)
@Test
fun `serialize - deserialize - sample 1`() = testSerialization(
IdeaKpmUnresolvedBinaryDependencyImpl(
"1", IdeaKpmBinaryCoordinatesImpl(
group = "group",
module = "module",
version = "version",
kotlinModuleName = null,
kotlinFragmentName = null
), emptyExtras()
)
)
@Test
fun `serialize - deserialize - sample 2`() = testSerialization(
IdeaKpmUnresolvedBinaryDependencyImpl(
null, null, extrasOf(extrasKeyOf<String>() withValue "myExtraValue")
)
)
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.kpm.idea.proto
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKpmVariant
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.TestIdeaKpmInstances
import kotlin.test.Test
class VariantTest : AbstractSerializationTest<IdeaKpmVariant>() {
override fun serialize(value: IdeaKpmVariant) = value.toByteArray(this)
override fun deserialize(data: ByteArray) = IdeaKpmVariant(data)
@Test
fun `serialize - deserialize - sample 0`() {
testSerialization(TestIdeaKpmInstances.simpleVariant)
}
@Test
fun `serialize - deserialize - sample 1`() {
testSerialization(TestIdeaKpmInstances.variantWithExtras)
}
}