From 1adf8091b1adde9487897407d5f7a48ca111ebee Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Wed, 23 Jun 2021 15:46:08 +0200 Subject: [PATCH] [Commonizer] HierarchicalClassAndTypeAliasCommonizationTest: Add tests for issues found during okio investigation --- ...hicalClassAndTypeAliasCommonizationTest.kt | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalClassAndTypeAliasCommonizationTest.kt b/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalClassAndTypeAliasCommonizationTest.kt index 2dddb34baa0..7ae7df1133b 100644 --- a/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalClassAndTypeAliasCommonizationTest.kt +++ b/native/commonizer/tests/org/jetbrains/kotlin/commonizer/hierarchical/HierarchicalClassAndTypeAliasCommonizationTest.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.commonizer.hierarchical import org.jetbrains.kotlin.commonizer.AbstractInlineSourcesCommonizationTest import org.jetbrains.kotlin.commonizer.assertCommonized +import org.junit.Test class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesCommonizationTest() { @@ -20,6 +21,17 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm result.assertCommonized("(a, b)", "expect class X") } + fun `test commonization of class and typeAlias`() { + val result = commonize { + outputTarget("(a, b)") + simpleSingleSourceTarget("a", "class X") + simpleSingleSourceTarget("b", "typealias X = Int") + } + + result.assertCommonized("(a, b)", "expect class X") + } + + fun `test commonization of typeAlias and class hierarchically`() { val result = commonize { outputTarget("(a, b)", "(c, d)", "(a, b, c, d)") @@ -268,4 +280,148 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm """.trimIndent() ) } + + fun `test return types`() { + val result = commonize { + outputTarget("(a, b)") + + simpleSingleSourceTarget( + "a", """ + class X + fun createX(): X + """.trimIndent() + ) + + simpleSingleSourceTarget( + "b", """ + class B + typealias X = B + fun createX(): X + """.trimIndent() + ) + } + + result.assertCommonized( + "(a, b)", """ + expect class X expect constructor() + expect fun createX(): X + """.trimIndent() + ) + } + + fun `test parameterized types`() { + val result = commonize { + outputTarget("(a, b)", "(c, d)", "(a, b, c, d)") + registerDependency("a", "b", "c", "d", "(a, b)", "(c, d)", "(a, b, c, d)") { + source("class Box") + } + simpleSingleSourceTarget( + "a", """ + class X + fun createBox(): Box + """.trimIndent() + ) + simpleSingleSourceTarget( + "b", """ + class B + typealias X = B + fun createBox(): Box + """.trimIndent() + ) + simpleSingleSourceTarget( + "c", """ + class CD + typealias X = CD + fun createBox(): Box + """.trimIndent() + ) + simpleSingleSourceTarget( + "d", """ + class CD + typealias X = CD + fun createBox(): Box + """.trimIndent() + ) + } + + result.assertCommonized( + "(a, b)", """ + expect class X expect constructor() + expect fun createBox(): Box + """.trimIndent() + ) + + result.assertCommonized( + "(c, d)", """ + expect class CD expect constructor() + typealias X = CD + expect fun createBox(): Box + """.trimIndent() + ) + + result.assertCommonized( + "(a, b, c, d)", """ + expect class X expect constructor() + expect fun createBox(): Box + """.trimIndent() + ) + } + + @Test + fun `test supertype from dependency`() { + val result = commonize { + outputTarget("(a, b)") + registerDependency("a", "b", "(a, b)") { + source("interface SuperClass") + } + + simpleSingleSourceTarget( + "a", """ + class A: SuperClass + typealias X = A + """.trimIndent() + ) + + simpleSingleSourceTarget( + "b", """ + class X: SuperClass + """.trimIndent() + ) + } + + result.assertCommonized( + "(a, b)", """ + expect class X expect constructor(): SuperClass + """.trimIndent() + ) + } + + @Test + fun `test supertype from sources`() { + val result = commonize { + outputTarget("(a, b)") + + simpleSingleSourceTarget( + "a", """ + interface SuperClass + class A: SuperClass + typealias X = A + """.trimIndent() + ) + + simpleSingleSourceTarget( + "b", """ + interface SuperClass + class X: SuperClass + """.trimIndent() + ) + } + + result.assertCommonized( + "(a, b)", """ + expect interface SuperClass + expect class X expect constructor(): SuperClass + """.trimIndent() + ) + } }