From 69c8b3868171c271452cfe0d666fab7868c6b234 Mon Sep 17 00:00:00 2001 From: Takahiro Menju Date: Wed, 18 Oct 2023 11:34:26 +0900 Subject: Switching to Kotlin Multiplatform for JVM use (#1654) * Transition to Kotlin Multiplatform for JVM use * Use jvmTest task instead of test task * Apply KMP plugin only to the kotlinpoet module * Fix setup check task * Fix targetExclude folder as the source set name change * Move Java code to jvmMain directory * Apply dokka workaround * Use js(IR) as phantom target * Update kotlinpoet/build.gradle.kts * Update kotlinpoet/build.gradle.kts * Update kotlinpoet/build.gradle.kts * Update gradle/libs.versions.toml * Update kotlinpoet/build.gradle.kts --------- Co-authored-by: Jake Wharton --- .../com/squareup/kotlinpoet/TypeNameKotlinTest.kt | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt (limited to 'kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt') diff --git a/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt b/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt new file mode 100644 index 00000000..3c16242a --- /dev/null +++ b/kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2021 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.kotlinpoet + +import com.google.common.truth.Truth.assertThat +import org.junit.Test + +class TypeNameKotlinTest { + + @Test + fun typeNameOf_simple() { + val type = typeNameOf() + assertThat(type.toString()).isEqualTo("com.squareup.kotlinpoet.TypeNameKotlinTest") + } + + @Test + fun typeNameOf_simple_intrinsic() { + val type = typeNameOf() + assertThat(type.toString()).isEqualTo("kotlin.String") + } + + @Test + fun typeNameOf_array_primitive() { + val type = typeNameOf() + assertThat(type.toString()).isEqualTo("kotlin.IntArray") + } + + @Test + fun typeNameOf_array_parameterized() { + val type = typeNameOf>() + assertThat(type.toString()).isEqualTo("kotlin.Array") + } + + @Test + fun typeNameOf_nullable() { + val type = typeNameOf() + assertThat(type.toString()).isEqualTo("kotlin.String?") + } + + @Test + fun typeNameOf_generic() { + val type = typeNameOf>() + assertThat(type.toString()).isEqualTo("kotlin.collections.List") + } + + @Test + fun typeNameOf_generic_wildcard_out() { + val type = typeNameOf>() + assertThat(type.toString()).isEqualTo("com.squareup.kotlinpoet.TypeNameKotlinTest.GenericType") + } + + @Test + fun typeNameOf_generic_wildcard_in() { + val type = typeNameOf>() + assertThat(type.toString()).isEqualTo("com.squareup.kotlinpoet.TypeNameKotlinTest.GenericType") + } + + @Test + fun typeNameOf_complex() { + val type = typeNameOf?>>>>>>>() + assertThat(type.toString()).isEqualTo("kotlin.collections.Map?>>>>>>") + } + + @Suppress("unused") + class GenericType + + @Test + fun tag() { + val type = typeNameOf().copy(tags = mapOf(String::class to "Test")) + assertThat(type.tag()).isEqualTo("Test") + } + + @Test + fun existingTagsShouldBePreserved() { + val type = typeNameOf().copy(tags = mapOf(String::class to "Test")) + val copied = type.copy(nullable = true) + assertThat(copied.tag()).isEqualTo("Test") + } +} -- cgit v1.2.3