diff options
author | Sadaf Ebrahimi <sadafebrahimi@google.com> | 2024-02-20 16:39:45 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-02-20 16:39:45 +0000 |
commit | 8f0503c359a4d94cf537a29a4dc9df7885be9cc5 (patch) | |
tree | ef6bae21f79804e20e6449e174536d7dca972376 /kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt | |
parent | 42861d32915d16a42f84d4758782d2fff26e6c17 (diff) | |
parent | af7bd99cda5997a81e801e1220bc78a696ec147d (diff) | |
download | kotlinpoet-8f0503c359a4d94cf537a29a4dc9df7885be9cc5.tar.gz |
Upgrade kotlinpoet to 1.16.0 am: af7bd99cda
Original change: https://android-review.googlesource.com/c/platform/external/kotlinpoet/+/2967683
Change-Id: I5922082e30e41d299676b15095b223a761ca1b40
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt')
-rw-r--r-- | kotlinpoet/src/commonTest/kotlin/com/squareup/kotlinpoet/TypeNameKotlinTest.kt | 92 |
1 files changed, 92 insertions, 0 deletions
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<TypeNameKotlinTest>() + assertThat(type.toString()).isEqualTo("com.squareup.kotlinpoet.TypeNameKotlinTest") + } + + @Test + fun typeNameOf_simple_intrinsic() { + val type = typeNameOf<String>() + assertThat(type.toString()).isEqualTo("kotlin.String") + } + + @Test + fun typeNameOf_array_primitive() { + val type = typeNameOf<IntArray>() + assertThat(type.toString()).isEqualTo("kotlin.IntArray") + } + + @Test + fun typeNameOf_array_parameterized() { + val type = typeNameOf<Array<String>>() + assertThat(type.toString()).isEqualTo("kotlin.Array<kotlin.String>") + } + + @Test + fun typeNameOf_nullable() { + val type = typeNameOf<String?>() + assertThat(type.toString()).isEqualTo("kotlin.String?") + } + + @Test + fun typeNameOf_generic() { + val type = typeNameOf<List<String>>() + assertThat(type.toString()).isEqualTo("kotlin.collections.List<kotlin.String>") + } + + @Test + fun typeNameOf_generic_wildcard_out() { + val type = typeNameOf<GenericType<out String>>() + assertThat(type.toString()).isEqualTo("com.squareup.kotlinpoet.TypeNameKotlinTest.GenericType<out kotlin.String>") + } + + @Test + fun typeNameOf_generic_wildcard_in() { + val type = typeNameOf<GenericType<in String>>() + assertThat(type.toString()).isEqualTo("com.squareup.kotlinpoet.TypeNameKotlinTest.GenericType<in kotlin.String>") + } + + @Test + fun typeNameOf_complex() { + val type = typeNameOf<Map<String, List<Map<*, GenericType<in Set<Array<GenericType<out String>?>>>>>>>() + assertThat(type.toString()).isEqualTo("kotlin.collections.Map<kotlin.String, kotlin.collections.List<kotlin.collections.Map<*, com.squareup.kotlinpoet.TypeNameKotlinTest.GenericType<in kotlin.collections.Set<kotlin.Array<com.squareup.kotlinpoet.TypeNameKotlinTest.GenericType<out kotlin.String>?>>>>>>") + } + + @Suppress("unused") + class GenericType<T> + + @Test + fun tag() { + val type = typeNameOf<String>().copy(tags = mapOf(String::class to "Test")) + assertThat(type.tag<String>()).isEqualTo("Test") + } + + @Test + fun existingTagsShouldBePreserved() { + val type = typeNameOf<String>().copy(tags = mapOf(String::class to "Test")) + val copied = type.copy(nullable = true) + assertThat(copied.tag<String>()).isEqualTo("Test") + } +} |