[Commonizer] Check errors in code of commonization tests
This commit is contained in:
committed by
Space
parent
57ce178bb3
commit
5e874bc3c5
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.commonizer
|
||||
|
||||
import kotlin.test.assertFails
|
||||
|
||||
class InlineSourceCommonizationHealthCheckTest : AbstractInlineSourcesCommonizationTest() {
|
||||
fun `test reference module with error diagnostics breaks tests`() {
|
||||
val result = commonize {
|
||||
outputTarget("(a, b)")
|
||||
"a" withSource "class X"
|
||||
"b" withSource "class X"
|
||||
}
|
||||
|
||||
assertFails("Test should fail when source code of reference module contains errors") {
|
||||
result.assertCommonized("(a, b)", "expect class X() : kotlin.MissingSupertype")
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -43,7 +43,7 @@ class SimpleCirSupertypesResolverTest : KtInlineSourceCommonizerTestCase() {
|
||||
"""
|
||||
class Outer {
|
||||
open inner class Inner
|
||||
class X: Inner()
|
||||
inner class X: Inner()
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
+12
-12
@@ -22,9 +22,9 @@ class BackwardsTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommoniz
|
||||
typealias Y = X
|
||||
typealias Z = Y
|
||||
|
||||
fun x(x: A)
|
||||
fun x1(x: A1)
|
||||
fun x2(x: X)
|
||||
fun x(x: A) {}
|
||||
fun x1(x: A1) {}
|
||||
fun x2(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -37,9 +37,9 @@ class BackwardsTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommoniz
|
||||
typealias Y = X
|
||||
typealias Z = Y
|
||||
|
||||
fun x(x: B)
|
||||
fun x1(x: B1)
|
||||
fun x2(x: X)
|
||||
fun x(x: B) {}
|
||||
fun x1(x: B1) {}
|
||||
fun x2(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -69,9 +69,9 @@ class BackwardsTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommoniz
|
||||
typealias Y = X
|
||||
typealias Z = Y
|
||||
|
||||
fun x(x: A)
|
||||
fun x1(x: A1)
|
||||
fun x2(x: X)
|
||||
fun x(x: A) {}
|
||||
fun x1(x: A1) {}
|
||||
fun x2(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -84,9 +84,9 @@ class BackwardsTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommoniz
|
||||
typealias Y = X
|
||||
typealias Z = Y
|
||||
|
||||
fun x(x: Z)
|
||||
fun x1(x: Z)
|
||||
fun x2(x: Z)
|
||||
fun x(x: Z) {}
|
||||
fun x1(x: Z) {}
|
||||
fun x2(x: Z) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+5
-5
@@ -18,7 +18,7 @@ class FunctionReturnTypeCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
class A { // NOTE: Class
|
||||
class B
|
||||
}
|
||||
fun x(): A.B = TODO()
|
||||
fun x(): A.B = null!!
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ class FunctionReturnTypeCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
interface A { // NOTE: Interface
|
||||
class B
|
||||
}
|
||||
fun x(): A.B = TODO()
|
||||
fun x(): A.B = null!!
|
||||
"""
|
||||
)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class FunctionReturnTypeCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
interface A {
|
||||
class B
|
||||
}
|
||||
fun x(): A.B = TODO()
|
||||
fun x(): A.B = null!!
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -61,7 +61,7 @@ class FunctionReturnTypeCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
interface A {
|
||||
class B
|
||||
}
|
||||
fun x(): A.B = TODO()
|
||||
fun x(): A.B = null!!
|
||||
"""
|
||||
)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class FunctionReturnTypeCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
result.assertCommonized(
|
||||
"(a,b)", """
|
||||
expect interface A {
|
||||
expect class B expect constructor()
|
||||
class B()
|
||||
}
|
||||
expect fun x(): A.B
|
||||
"""
|
||||
|
||||
+15
-15
@@ -22,7 +22,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"a", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCMethod(0)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"b", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCMethod(1)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"c", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCMethod(2)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -46,7 +46,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"d", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCMethod(2)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"a", """
|
||||
import kotlin.commonizer.*
|
||||
@ObjCCallable
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -95,7 +95,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"b", """
|
||||
import kotlin.commonizer.*
|
||||
@ObjCCallable
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"a", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCMethod(0)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -128,7 +128,7 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"b", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCConstructor(1)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -136,15 +136,15 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
"c", """
|
||||
import kotlinx.cinterop.*
|
||||
@ObjCFactory(2)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
import kotlin.commonizer.*
|
||||
@ObjCCallable(2)
|
||||
fun x()
|
||||
@ObjCCallable
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -184,13 +184,13 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
@ObjCMethod(0)
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -199,13 +199,13 @@ class HierarchicalCInteropCallableAnnotationCommonizationTest : AbstractInlineSo
|
||||
import kotlin.commonizer.*
|
||||
|
||||
@ObjCCallable
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
fun x()
|
||||
fun x() {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+46
-45
@@ -60,7 +60,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"a", """
|
||||
typealias X = NotX
|
||||
|
||||
class NotX(val constructorProperty: Int) {
|
||||
class NotX(constructorParameter: Int) {
|
||||
val property: Int = 42
|
||||
fun function() = 42
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class X(val constructorProperty: Int) {
|
||||
class X(constructorParameter: Int) {
|
||||
val property: Int = 42
|
||||
fun function() = 42
|
||||
}
|
||||
@@ -79,9 +79,9 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor(expect val constructorProperty: Int) {
|
||||
expect val property: Int
|
||||
expect fun function(): Int
|
||||
expect class X(constructorParameter: Int) {
|
||||
val property: Int
|
||||
fun function(): Int
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -94,7 +94,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"a", """
|
||||
typealias X = NotX
|
||||
typealias NotX = ReallyNotX
|
||||
class ReallyNotX(val constructorProperty: Int) {
|
||||
class ReallyNotX(constructorParameter: Int) {
|
||||
val property: Int = 42
|
||||
fun function() = 42
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class X(val constructorProperty: Int) {
|
||||
class X(constructorParameter: Int) {
|
||||
val property: Int = 42
|
||||
fun function() = 42
|
||||
}
|
||||
@@ -111,11 +111,12 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: [EXPECTED_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER]
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor(expect val constructorProperty: Int) {
|
||||
expect val property: Int
|
||||
expect fun function(): Int
|
||||
expect class X(constructorParameter: Int) {
|
||||
val property: Int
|
||||
fun function(): Int
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -145,8 +146,8 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor() {
|
||||
expect val x: Int
|
||||
expect class X() {
|
||||
val x: Int
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -176,8 +177,8 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor() {
|
||||
expect val x: Int
|
||||
expect class AB() {
|
||||
val x: Int
|
||||
}
|
||||
typealias X = AB
|
||||
""".trimIndent()
|
||||
@@ -205,7 +206,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", """expect class X expect constructor()""")
|
||||
result.assertCommonized("(a, b)", """expect class X()""")
|
||||
}
|
||||
|
||||
fun `test typeAlias with nullability`() {
|
||||
@@ -251,7 +252,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
expect class V
|
||||
expect class Y
|
||||
""".trimIndent()
|
||||
@@ -280,8 +281,8 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect typealias V = AB
|
||||
expect class AB()
|
||||
typealias V = AB
|
||||
expect class Y
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -294,7 +295,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
class X
|
||||
fun createX(): X
|
||||
fun createX(): X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -302,14 +303,14 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"b", """
|
||||
class B
|
||||
typealias X = B
|
||||
fun createX(): X
|
||||
fun createX(): X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor()
|
||||
expect class X()
|
||||
expect fun createX(): X
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -337,7 +338,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor()
|
||||
expect class X()
|
||||
expect fun useX(x: X)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -352,42 +353,42 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
class X
|
||||
fun createBox(): Box<X>
|
||||
fun createBox(): Box<X> = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class B
|
||||
typealias X = B
|
||||
fun createBox(): Box<X>
|
||||
fun createBox(): Box<X> = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"c", """
|
||||
class CD
|
||||
typealias X = CD
|
||||
fun createBox(): Box<X>
|
||||
fun createBox(): Box<X> = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
class CD
|
||||
typealias X = CD
|
||||
fun createBox(): Box<X>
|
||||
fun createBox(): Box<X> = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor()
|
||||
expect class X()
|
||||
expect fun createBox(): Box<X>
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c, d)", """
|
||||
expect class CD expect constructor()
|
||||
expect class CD()
|
||||
typealias X = CD
|
||||
expect fun createBox(): Box<X>
|
||||
""".trimIndent()
|
||||
@@ -395,7 +396,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b, c, d)", """
|
||||
expect class X expect constructor()
|
||||
expect class X()
|
||||
expect fun createBox(): Box<X>
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -409,7 +410,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"a", """
|
||||
class Box<T>
|
||||
class X
|
||||
fun useBox(x: Box<X>)
|
||||
fun useBox(x: Box<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -418,15 +419,15 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
class Box<T>
|
||||
class B
|
||||
typealias X = B
|
||||
fun useBox(x: Box<X>)
|
||||
fun useBox(x: Box<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class Box<T> expect constructor()
|
||||
expect class X expect constructor()
|
||||
expect class Box<T>()
|
||||
expect class X()
|
||||
expect fun useBox(x: Box<X>)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -441,7 +442,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
class Box<T>
|
||||
class A
|
||||
typealias X = A
|
||||
fun useBox(x: Box<X>)
|
||||
fun useBox(x: Box<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -450,15 +451,15 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
class Box<T>
|
||||
class B
|
||||
typealias X = B
|
||||
fun useBox(x: Box<X>)
|
||||
fun useBox(x: Box<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class Box<T> expect constructor()
|
||||
expect class X expect constructor()
|
||||
expect class Box<T>()
|
||||
expect class X()
|
||||
expect fun useBox(x: Box<X>)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -487,7 +488,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor(): SuperClass
|
||||
expect class X(): SuperClass
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -515,7 +516,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect interface SuperClass
|
||||
expect class X expect constructor(): SuperClass
|
||||
expect class X(): SuperClass
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -654,8 +655,8 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
typealias A = X
|
||||
typealias B = Y
|
||||
|
||||
fun x(x: A)
|
||||
fun x(x: B)
|
||||
fun x(x: A) {}
|
||||
fun x(x: B) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -667,8 +668,8 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
typealias A = Y // NOTE: Y & X are swapped
|
||||
typealias B = X // NOTE: Y & X are swapped
|
||||
|
||||
fun x(x: A)
|
||||
fun x(x: B)
|
||||
fun x(x: A) {}
|
||||
fun x(x: B) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -696,7 +697,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
typealias A = X
|
||||
typealias B = Y
|
||||
|
||||
fun x(x: A)
|
||||
fun x(x: A) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -708,7 +709,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
typealias A = Y // NOTE: Y & X are swapped
|
||||
typealias B = X // NOTE: Y & X are swapped
|
||||
|
||||
fun x(x: A)
|
||||
fun x(x: A) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+12
-12
@@ -20,10 +20,10 @@ class HierarchicalClassCommonizationTest : AbstractInlineSourcesCommonizationTes
|
||||
simpleSingleSourceTarget("e", "class X")
|
||||
}
|
||||
|
||||
result.assertCommonized("(a,b)", "expect class X expect constructor()")
|
||||
result.assertCommonized("(c,d)", "expect class X expect constructor()")
|
||||
result.assertCommonized("(a,b)", "expect class X expect constructor()")
|
||||
result.assertCommonized("((a,b), (c,d), e)", "expect class X expect constructor()")
|
||||
result.assertCommonized("(a,b)", "expect class X()")
|
||||
result.assertCommonized("(c,d)", "expect class X()")
|
||||
result.assertCommonized("(a,b)", "expect class X()")
|
||||
result.assertCommonized("((a,b), (c,d), e)", "expect class X()")
|
||||
}
|
||||
|
||||
fun `test sample class`() {
|
||||
@@ -72,26 +72,26 @@ class HierarchicalClassCommonizationTest : AbstractInlineSourcesCommonizationTes
|
||||
|
||||
result.assertCommonized(
|
||||
"(a,b)", """
|
||||
expect class X expect constructor() {
|
||||
expect val ab: Int
|
||||
expect val abcd: Int
|
||||
expect class X() {
|
||||
val ab: Int
|
||||
val abcd: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c,d)", """
|
||||
expect class X expect constructor() {
|
||||
expect val cd: Int
|
||||
expect val abcd: Int
|
||||
expect class X() {
|
||||
val cd: Int
|
||||
val abcd: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"((a,b), (c,d))", """
|
||||
expect class X expect constructor() {
|
||||
expect val abcd: Int
|
||||
expect class X() {
|
||||
val abcd: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
+15
-15
@@ -42,26 +42,26 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
fun x(): ABCD = null!!
|
||||
"""
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
fun x(): ABCD = null!!
|
||||
"""
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"c", """
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
fun x(): ABCD = null!!
|
||||
"""
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
fun x(): ABCD = null!!
|
||||
"""
|
||||
)
|
||||
}
|
||||
@@ -92,10 +92,10 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
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("interface ABCD") }
|
||||
simpleSingleSourceTarget("a", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("b", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("d", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("a", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("b", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("d", "fun x(): ABCD = null!!")
|
||||
}
|
||||
|
||||
result.assertCommonized("(c, d)", "expect fun x(): ABCD")
|
||||
@@ -109,10 +109,10 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
registerDependency("a", "b", "c", "d") { source("interface ABCD") }
|
||||
registerDependency("(a, b)") { source("interface ABCD") }
|
||||
registerDependency("(c,d)") { source("interface ABCD") }
|
||||
simpleSingleSourceTarget("a", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("b", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("d", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("a", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("b", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("d", "fun x(): ABCD = null!!")
|
||||
}
|
||||
|
||||
result.assertCommonized("(c, d)", "expect fun x(): ABCD")
|
||||
@@ -127,9 +127,9 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
outputTarget("(a, b)", "(a, b, c)")
|
||||
registerDependency("(a, b, c)") { source("interface ABCD") }
|
||||
registerDependency("a", "b", "c", "(a, b)") { source("interface ABCD") }
|
||||
simpleSingleSourceTarget("a", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("b", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = TODO()")
|
||||
simpleSingleSourceTarget("a", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("b", "fun x(): ABCD = null!!")
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = null!!")
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", "expect fun x(): ABCD")
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@ class HierarchicalModuleCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
|
||||
result.assertCommonized("(a, b)") {
|
||||
name = "shared"
|
||||
source("expect class Shared expect constructor()")
|
||||
source("expect class Shared()")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -626,8 +626,8 @@ class HierarchicalOptimisticNumbersTypeCommonizerTest : AbstractInlineSourcesCom
|
||||
fun `test function with pure number types parameter`() {
|
||||
val result = commonize {
|
||||
outputTarget("(a, b)")
|
||||
simpleSingleSourceTarget("a", "fun x(p: Int)")
|
||||
simpleSingleSourceTarget("b", "fun x(p: Long)")
|
||||
simpleSingleSourceTarget("a", "fun x(p: Int) {}")
|
||||
simpleSingleSourceTarget("b", "fun x(p: Long) {}")
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -649,14 +649,14 @@ class HierarchicalOptimisticNumbersTypeCommonizerTest : AbstractInlineSourcesCom
|
||||
"a", """
|
||||
typealias A = Int
|
||||
typealias X = A
|
||||
fun x(p: X)
|
||||
fun x(p: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
typealias B = Long
|
||||
typealias X = B
|
||||
fun x(p: X)
|
||||
fun x(p: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -674,8 +674,8 @@ class HierarchicalOptimisticNumbersTypeCommonizerTest : AbstractInlineSourcesCom
|
||||
val result = commonize {
|
||||
outputTarget("(a, b)")
|
||||
registerDependency("a", "b", "(a, b)") { unsignedIntegers() }
|
||||
simpleSingleSourceTarget("a", "val x: UInt = TODO()")
|
||||
simpleSingleSourceTarget("b", "val x: ULong = TODO()")
|
||||
simpleSingleSourceTarget("a", "val x: UInt = null!!")
|
||||
simpleSingleSourceTarget("b", "val x: ULong = null!!")
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -693,13 +693,13 @@ class HierarchicalOptimisticNumbersTypeCommonizerTest : AbstractInlineSourcesCom
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
typealias X = UShort
|
||||
val x: X = TODO()
|
||||
val x: X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
typealias X = ULong
|
||||
val x: X = TODO()
|
||||
val x: X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+6
-6
@@ -97,7 +97,7 @@ class HierarchicalPropertyCommonizationTest : AbstractInlineSourcesCommonization
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
expect val x: AB
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -124,7 +124,7 @@ class HierarchicalPropertyCommonizationTest : AbstractInlineSourcesCommonization
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
expect val x: AB
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -144,14 +144,14 @@ class HierarchicalPropertyCommonizationTest : AbstractInlineSourcesCommonization
|
||||
"b", """
|
||||
class AB
|
||||
typealias TA = AB
|
||||
val x: TA = TA
|
||||
val x: TA = TA()
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
expect val x: AB
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -181,7 +181,7 @@ class HierarchicalPropertyCommonizationTest : AbstractInlineSourcesCommonization
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
typealias TA_AB = AB
|
||||
expect val x: TA_AB
|
||||
""".trimIndent()
|
||||
@@ -211,7 +211,7 @@ class HierarchicalPropertyCommonizationTest : AbstractInlineSourcesCommonization
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
typealias TA_AB = AB
|
||||
expect val x: TA_AB
|
||||
""".trimIndent()
|
||||
|
||||
+7
-7
@@ -39,7 +39,7 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized("(a,b)", "expect class X expect constructor()")
|
||||
result.assertCommonized("(a,b)", "expect class X()")
|
||||
}
|
||||
|
||||
fun `test typealias to different classes`() {
|
||||
@@ -75,31 +75,31 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
|
||||
result.assertCommonized(
|
||||
"(a,b)", """
|
||||
expect class AB expect constructor()
|
||||
expect class AB()
|
||||
typealias x = AB
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c,d)", """
|
||||
expect class CD expect constructor()
|
||||
expect class CD()
|
||||
typealias x = CD
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c,d)", """
|
||||
expect class CD expect constructor()
|
||||
expect class CD()
|
||||
typealias x = CD
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(e,f)", """expect class x expect constructor()"""
|
||||
"(e,f)", """expect class x()"""
|
||||
)
|
||||
|
||||
result.assertCommonized("(a, b, c, d)", """expect class x expect constructor()""")
|
||||
result.assertCommonized("(a, b, c, d, e, f)", """expect class x expect constructor()""")
|
||||
result.assertCommonized("(a, b, c, d)", """expect class x()""")
|
||||
result.assertCommonized("(a, b, c, d, e, f)", """expect class x()""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-12
@@ -19,7 +19,7 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
class Box<T>
|
||||
class A
|
||||
typealias X = A
|
||||
fun x(x: Box<X>)
|
||||
fun x(x: Box<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -28,15 +28,15 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
class Box<T>
|
||||
class B
|
||||
typealias X = B
|
||||
fun x(x: Box<B>)
|
||||
fun x(x: Box<B>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class Box<T> expect constructor()
|
||||
expect class X expect constructor()
|
||||
expect class Box<T>()
|
||||
expect class X()
|
||||
expect fun x(x: Box<X>)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -55,7 +55,7 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
"a", """
|
||||
class A
|
||||
typealias X = A
|
||||
fun x(x: Box<X>)
|
||||
fun x(x: Box<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -63,14 +63,14 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
"b", """
|
||||
class B
|
||||
typealias X = B
|
||||
fun x(x: Box<B>)
|
||||
fun x(x: Box<B>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor()
|
||||
expect class X()
|
||||
expect fun x(x: Box<X>)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -98,7 +98,7 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class X expect constructor()
|
||||
expect class X()
|
||||
expect fun useX(x: X)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -113,7 +113,7 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
class Box<T>
|
||||
class A
|
||||
typealias X = A
|
||||
val x: Box<X>
|
||||
val x: Box<X> = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -122,15 +122,15 @@ class HierarchicalTypeSubstitutionCommonizationTest : AbstractInlineSourcesCommo
|
||||
class Box<T>
|
||||
class B
|
||||
typealias X = B
|
||||
val x: Box<B>
|
||||
val x: Box<B> = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class Box<T> expect constructor()
|
||||
expect class X expect constructor()
|
||||
expect class Box<T>()
|
||||
expect class X()
|
||||
expect val x: Box<X>
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
+35
-35
@@ -17,18 +17,18 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
class X<T, R>
|
||||
fun<T, R> x1(x: X<T, R>)
|
||||
fun <M> x2(x: X<M, String>)
|
||||
fun x3(x: X<Int, String>)
|
||||
fun<T, R> x1(x: X<T, R>) {}
|
||||
fun <M> x2(x: X<M, String>) {}
|
||||
fun x3(x: X<Int, String>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class X<T, R>
|
||||
fun<T, R> x1(x: X<T, R>)
|
||||
fun <M> x2(x: X<M, String>)
|
||||
fun x3(x: X<Int, String>)
|
||||
fun<T, R> x1(x: X<T, R>) {}
|
||||
fun <M> x2(x: X<M, String>) {}
|
||||
fun x3(x: X<Int, String>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias TA2<R> = TA1<String, R>
|
||||
typealias TA3 = TA2<Int>
|
||||
|
||||
fun x1(x: TA3)
|
||||
fun x1(x: TA3) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias TA2<R> = TA1<String, R>
|
||||
typealias TA3 = TA2<Int>
|
||||
|
||||
fun x1(x: TA3)
|
||||
fun x1(x: TA3) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias TA2<R> = TA1<String, R>
|
||||
typealias TA3 = TA2<Int>
|
||||
|
||||
fun x1(x: TA3)
|
||||
fun x1(x: TA3) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -99,7 +99,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias TA2<R> = TA1<String, R>
|
||||
typealias TA3 = TA2<Int>
|
||||
|
||||
fun x1(x: TA1<String, Int>)
|
||||
fun x1(x: TA1<String, Int>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -125,8 +125,8 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias A<T, M> = Triple<T, String, M>
|
||||
typealias B<T, M> = Triple<T, String, M>
|
||||
|
||||
fun x1(x: B<Int, Long>)
|
||||
fun x2(x: A<Int, Long>)
|
||||
fun x1(x: B<Int, Long>) {}
|
||||
fun x2(x: A<Int, Long>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -136,8 +136,8 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias A<T, M> = Triple<T, String, M>
|
||||
typealias B<T, M> = Triple<T, String, M>
|
||||
|
||||
fun x1(x: A<Int, Long>) // NOTE: A & B flipped
|
||||
fun x2(x: B<Int, Long>) // NOTE: A & B flipped
|
||||
fun x1(x: A<Int, Long>) {} // NOTE: A & B flipped
|
||||
fun x2(x: B<Int, Long>) {} // NOTE: A & B flipped
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -166,8 +166,8 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias T3<T, M> = Triple<T, String, M>
|
||||
typealias T4<T, M> = Triple<T, String, M>
|
||||
|
||||
fun x1(x: T4<Int, Long>)
|
||||
fun x2(x: T3<Int, Long>)
|
||||
fun x1(x: T4<Int, Long>) {}
|
||||
fun x2(x: T3<Int, Long>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -179,8 +179,8 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias T3<T, M> = Triple<T, String, M>
|
||||
typealias T4<T, M> = T3<T, M>
|
||||
|
||||
fun x1(x: T3<Int, Long>) // NOTE: T3 & T4 flipped
|
||||
fun x2(x: T4<Int, Long>) // NOTE: T3 & T4 flipped
|
||||
fun x1(x: T3<Int, Long>) {} // NOTE: T3 & T4 flipped
|
||||
fun x2(x: T4<Int, Long>) {} // NOTE: T3 & T4 flipped
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -210,7 +210,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias A2 = Long
|
||||
typealias A3<T, R> = Triple<T, String, R>
|
||||
|
||||
fun x(x: A3<A1, A2>)
|
||||
fun x(x: A3<A1, A2>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -220,7 +220,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
typealias B1 = String
|
||||
typealias B2 = Long
|
||||
|
||||
fun x(x: Triple<B1, String, B2>)
|
||||
fun x(x: Triple<B1, String, B2>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -252,9 +252,9 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
class MyClass
|
||||
typealias X = TA<MyClass>
|
||||
|
||||
fun x(x: X)
|
||||
fun x2(x: TA<MyClass>)
|
||||
fun x3(x: TA<X>)
|
||||
fun x(x: X) {}
|
||||
fun x2(x: TA<MyClass>) {}
|
||||
fun x3(x: TA<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -263,9 +263,9 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
class MyClass
|
||||
typealias X = TA<MyClass>
|
||||
|
||||
fun x(x: X)
|
||||
fun x2(x: TA<MyClass>)
|
||||
fun x3(x: TA<X>)
|
||||
fun x(x: X) {}
|
||||
fun x2(x: TA<MyClass>) {}
|
||||
fun x3(x: TA<X>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -288,13 +288,13 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
typealias X<T> = Map<Int, T>
|
||||
fun <T: Any> x(x: X<T>)
|
||||
fun <T: Any> x(x: X<T>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
fun <T: Any> x(x: Map<Int, T>)
|
||||
fun <T: Any> x(x: Map<Int, T>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -313,13 +313,13 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
typealias X<T> = Map<Int, T>
|
||||
fun <T: X<T>> x(x: X<T>)
|
||||
fun <T: X<T>> x(x: X<T>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
fun <T: Map<Int, T>> x(x: Map<Int, T>)
|
||||
fun <T: Map<Int, T>> x(x: Map<Int, T>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -338,7 +338,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
typealias X<T> = Map<Int, T>
|
||||
fun <T: X<T>> x(x: X<T>)
|
||||
fun <T: X<T>> x(x: X<T>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -346,14 +346,14 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
"b", """
|
||||
typealias X<T> = Map<Int, T>
|
||||
typealias Y<T> = X<T>
|
||||
fun <T: Y<T>> x(x: Y<T>)
|
||||
fun <T: Y<T>> x(x: Y<T>) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect typealias X<T> = Map<Int, T>
|
||||
typealias X<T> = Map<Int, T>
|
||||
expect fun <T: X<T>> x(x: X<T>)
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -417,7 +417,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class Foo<T1, T2, T3>() {
|
||||
expect fun t(x: Foo<Int, String, T3>)
|
||||
fun t(x: Foo<Int, String, T3>)
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -454,7 +454,7 @@ class ParameterizedTypesCommonizationTest : AbstractInlineSourcesCommonizationTe
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
expect class Foo<T1, T2, T3>() {
|
||||
expect fun t(x: Y<T3, Int>)
|
||||
fun t(x: Y<T3, Int>)
|
||||
}
|
||||
|
||||
typealias X<T1, T2, T3> = Foo<T1, T2, T3>
|
||||
|
||||
+21
-21
@@ -13,8 +13,8 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
fun `test two nullable functions`() {
|
||||
val result = commonize {
|
||||
outputTarget("(a, b)")
|
||||
simpleSingleSourceTarget("a", "fun x(): Any?")
|
||||
simpleSingleSourceTarget("b", "fun x(): Any?")
|
||||
simpleSingleSourceTarget("a", "fun x(): Any? = Unit")
|
||||
simpleSingleSourceTarget("b", "fun x(): Any? = Unit")
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", "expect fun x(): Any?")
|
||||
@@ -23,8 +23,8 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
fun `test two non-nullable functions`() {
|
||||
val result = commonize {
|
||||
outputTarget("(a, b)")
|
||||
simpleSingleSourceTarget("a", "fun x(): Any")
|
||||
simpleSingleSourceTarget("b", "fun x(): Any")
|
||||
simpleSingleSourceTarget("a", "fun x(): Any = Unit")
|
||||
simpleSingleSourceTarget("b", "fun x(): Any = Unit")
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", "expect fun x(): Any")
|
||||
@@ -33,8 +33,8 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
fun `test nullable and non-nullable function`() {
|
||||
val result = commonize {
|
||||
outputTarget("(a, b)")
|
||||
simpleSingleSourceTarget("a", "fun x(): Any?")
|
||||
simpleSingleSourceTarget("b", "fun x(): Any")
|
||||
simpleSingleSourceTarget("a", "fun x(): Any? = null")
|
||||
simpleSingleSourceTarget("b", "fun x(): Any = null!!")
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", "expect fun x(): Any?")
|
||||
@@ -96,14 +96,14 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
typealias X = Any?
|
||||
fun x(): X
|
||||
fun x(): X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
typealias X = Any
|
||||
fun x(): X
|
||||
fun x(): X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
typealias Z = Any
|
||||
typealias Y = Z?
|
||||
typealias X = Y
|
||||
fun x(): X
|
||||
fun x(): X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -133,7 +133,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
typealias Z = Any
|
||||
typealias Y = Z
|
||||
typealias X = Y
|
||||
fun x(): X
|
||||
fun x(): X = null!!
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -167,7 +167,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
typealias Z = Any
|
||||
typealias Y = Z
|
||||
typealias X = Y
|
||||
val x: X = Any
|
||||
val x: X = Unit
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -211,7 +211,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
class X {
|
||||
val x: Any?
|
||||
val x: Any? = Unit
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -219,7 +219,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class X {
|
||||
val x: Any
|
||||
val x: Any = Unit
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -227,7 +227,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"c", """
|
||||
class X {
|
||||
val x: Any
|
||||
val x: Any = Unit
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -235,14 +235,14 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
class X {
|
||||
val x: Any
|
||||
val x: Any = Unit
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", """expect class X()""")
|
||||
result.assertCommonized("(c, d)", """expect class X() { expect val x: Any }""")
|
||||
result.assertCommonized("(c, d)", """expect class X() { val x: Any }""")
|
||||
result.assertCommonized("(a, b, c, d)", """expect class X()""")
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"a", """
|
||||
class X {
|
||||
fun x(): Any?
|
||||
fun x(): Any? = null!!
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -261,7 +261,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
class X {
|
||||
fun x(): Any
|
||||
fun x(): Any = null!!
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -269,7 +269,7 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"c", """
|
||||
class X {
|
||||
fun x(): Any
|
||||
fun x(): Any = null!!
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -277,14 +277,14 @@ class ReturnTypeNullabilityCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
simpleSingleSourceTarget(
|
||||
"d", """
|
||||
class X {
|
||||
fun x(): Any
|
||||
fun x(): Any = null!!
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
result.assertCommonized("(a, b)", """expect class X()""")
|
||||
result.assertCommonized("(c, d)", """expect class X() { expect fun x(): Any }""")
|
||||
result.assertCommonized("(c, d)", """expect class X() { fun x(): Any }""")
|
||||
result.assertCommonized("(a, b, c, d)", """expect class X()""")
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -25,7 +25,7 @@ class SingleTargetPropagationTest : AbstractInlineSourcesCommonizationTest() {
|
||||
simpleSingleSourceTarget("a", """class A""")
|
||||
}
|
||||
|
||||
result.assertCommonized("(a,b)", "expect class A expect constructor()")
|
||||
result.assertCommonized("((a, b), (c, d))", "expect class A expect constructor()")
|
||||
result.assertCommonized("(a,b)", "expect class A()")
|
||||
result.assertCommonized("((a, b), (c, d))", "expect class A()")
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -17,14 +17,14 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"a", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: __X)
|
||||
fun x(x: __X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
simpleSingleSourceTarget(
|
||||
"b", """
|
||||
typealias X = Int
|
||||
fun x(x: X)
|
||||
fun x(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"a", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: __X)
|
||||
fun x(x: __X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"b", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: X)
|
||||
fun x(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"a", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: X)
|
||||
fun x(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"b", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: X)
|
||||
fun x(x: X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -104,7 +104,7 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"a", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: __X)
|
||||
fun x(x: __X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -112,7 +112,7 @@ class UnderscoredTypeAliasTypeSubstitutonTest : AbstractInlineSourcesCommonizati
|
||||
"b", """
|
||||
typealias X = Int
|
||||
typealias __X = X
|
||||
fun x(x: __X)
|
||||
fun x(x: __X) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ class InlineTypeAliasCirNodeTransformerTest : KtInlineSourceCommonizerTestCase()
|
||||
source(
|
||||
"""
|
||||
package dep
|
||||
class ClassA
|
||||
open class ClassA
|
||||
class ClassB: ClassA()
|
||||
""".trimIndent()
|
||||
)
|
||||
@@ -112,7 +112,7 @@ class InlineTypeAliasCirNodeTransformerTest : KtInlineSourceCommonizerTestCase()
|
||||
source(
|
||||
"""
|
||||
package dep
|
||||
class ClassA
|
||||
open class ClassA
|
||||
class ClassB: ClassA()
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
+11
-3
@@ -40,7 +40,7 @@ class CirTreePropertyDeserializerTest : AbstractCirTreeDeserializerTest() {
|
||||
}
|
||||
|
||||
fun `test lateinit var property`() {
|
||||
val module = createCirTreeFromSourceCode("lateinit var x: Int")
|
||||
val module = createCirTreeFromSourceCode("lateinit var x: Unit")
|
||||
val property = module.assertSingleProperty()
|
||||
|
||||
assertNotNull(property.getter, "Expected property has getter")
|
||||
@@ -50,7 +50,13 @@ class CirTreePropertyDeserializerTest : AbstractCirTreeDeserializerTest() {
|
||||
}
|
||||
|
||||
fun `test generic var property`() {
|
||||
val module = createCirTreeFromSourceCode("var <T> T.x: T get() = this")
|
||||
val module = createCirTreeFromSourceCode(
|
||||
"""
|
||||
var <T> T.x: T
|
||||
get() = this
|
||||
set(value) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
val property = module.assertSingleProperty()
|
||||
|
||||
assertNotNull(property.extensionReceiver, "Expected property has extension receiver")
|
||||
@@ -66,7 +72,9 @@ class CirTreePropertyDeserializerTest : AbstractCirTreeDeserializerTest() {
|
||||
val x: Int = 42
|
||||
val y: Float = 42f
|
||||
var z: String = "42"
|
||||
var Any?.answer get() = if(this != null) 42 else null
|
||||
var Any?.answer
|
||||
get() = if(this != null) 42 else null
|
||||
set(value) {}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
|
||||
+39
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.commonizer.utils
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonDependenciesContainer
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonPlatformAnalyzerServices
|
||||
@@ -24,11 +25,14 @@ import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.diagnostics.Severity
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.CommonPlatforms
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
@@ -79,7 +83,7 @@ class InlineSourceBuilderImpl(private val disposable: Disposable) : InlineSource
|
||||
.map { psiFactory.createFile(it.name, KtTestUtil.doLoadFile(it)) }
|
||||
.toList()
|
||||
|
||||
return CommonResolverForModuleFactory.analyzeFiles(
|
||||
val analysisResult = CommonResolverForModuleFactory.analyzeFiles(
|
||||
files = psiFiles,
|
||||
moduleName = Name.special("<${module.name}>"),
|
||||
dependOnBuiltIns = true,
|
||||
@@ -89,7 +93,40 @@ class InlineSourceBuilderImpl(private val disposable: Disposable) : InlineSource
|
||||
dependenciesContainer = DependenciesContainerImpl(module.dependencies),
|
||||
) { content ->
|
||||
environment.createPackagePartProvider(content.moduleContentScope)
|
||||
}.moduleDescriptor
|
||||
}
|
||||
|
||||
val errorDiagnostics = analysisResult.bindingContext.diagnostics.noSuppression().filter { it.severity == Severity.ERROR }
|
||||
check(errorDiagnostics.isEmpty()) {
|
||||
val diagnosticInfos = errorDiagnostics.map { diagnostic ->
|
||||
DiagnosticInfo(diagnostic.psiElement, diagnostic.factoryName)
|
||||
}
|
||||
val diagnosticDescriptions = diagnosticInfos.joinToString(System.lineSeparator()) { info ->
|
||||
"[${info.diagnosticFactoryName}] reported on '${info.psiElementText}' " +
|
||||
"in file ${info.fileName} [${info.psiElementStartOffset}, ${info.psiElementEndOffset}]"
|
||||
}
|
||||
"""No errors expected in test sources, but found:
|
||||
|${diagnosticDescriptions}
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
return analysisResult.moduleDescriptor
|
||||
}
|
||||
|
||||
private class DiagnosticInfo(
|
||||
val element: PsiElement,
|
||||
val diagnosticFactoryName: String,
|
||||
) {
|
||||
val psiElementText: String
|
||||
get() = element.text
|
||||
|
||||
val psiElementStartOffset: Int
|
||||
get() = element.startOffset
|
||||
|
||||
val psiElementEndOffset: Int
|
||||
get() = element.endOffset
|
||||
|
||||
val fileName: String
|
||||
get() = element.containingFile.name
|
||||
}
|
||||
|
||||
private inner class DependenciesContainerImpl(
|
||||
|
||||
Reference in New Issue
Block a user