Add more tests for inline classes

#KT-27416
 #KT-27513
This commit is contained in:
Dmitry Petrov
2018-10-15 09:51:35 +03:00
parent 0fd68d29f4
commit b6be72bb11
9 changed files with 156 additions and 28 deletions
@@ -0,0 +1,10 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
// IGNORE_BACKEND: JVM_IR
inline class A(val b: String) {
override fun toString(): String =
buildString { append(b) }
}
fun box() = A("OK").toString()
@@ -0,0 +1,35 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val int: Int)
inline class L(val long: Long)
inline class Str(val string: String)
inline class Obj(val obj: Any)
inline class Host(val xx: Int) {
inline fun <R> withDefaultZ(fn: (Z) -> R, x: Z = Z(xx)) = fn(x)
inline fun <R> withDefaultL(fn: (L) -> R, x: L = L(xx.toLong())) = fn(x)
inline fun <R> withDefaultL2(x: L = L(xx.toLong()), fn: (L) -> R) = fn(x)
inline fun <R> withDefaultStr(fn: (Str) -> R, x: Str = Str(xx.toString())) = fn(x)
inline fun <R> withDefaultObj(fn: (Obj) -> R, x: Obj = Obj(xx.toString())) = fn(x)
inline fun <R> withDefaultObj2(x: Obj = Obj(xx.toString()), fn: (Obj) -> R) = fn(x)
fun testWithDefaultZ() = withDefaultZ({ Z(it.int + 1) })
fun testWithDefaultL() = withDefaultL({ L(it.long + 1L) })
fun testWithDefaultL2() = withDefaultL2(fn = { L(it.long + 1L) })
fun testWithDefaultStr() = withDefaultStr({ Str(it.string + "1") })
fun testWithDefaultObj() = withDefaultObj({ Obj(it.obj.toString() + "1") })
fun testWithDefaultObj2() = withDefaultObj2(fn = { Obj(it.obj.toString() + "1") })
}
fun box(): String {
val h = Host(42)
if (h.testWithDefaultZ().int != 43) throw AssertionError()
if (h.testWithDefaultL().long != 43L) throw AssertionError()
if (h.testWithDefaultL2().long != 43L) throw AssertionError()
if (h.testWithDefaultStr().string != "421") throw AssertionError()
if (h.testWithDefaultObj().obj != "421") throw AssertionError()
if (h.testWithDefaultObj2().obj != "421") throw AssertionError()
return "OK"
}
@@ -0,0 +1,8 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class A(val i: Int) {
fun foo(s: String = "OK") = s
}
fun box() = A(42).foo()
@@ -12111,6 +12111,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt26858.kt");
}
@TestMetadata("kt27513.kt")
public void testKt27513() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt27513.kt");
}
@TestMetadata("lambdaInInlineClassFun.kt")
public void testLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt");
@@ -12169,6 +12174,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFun.kt");
}
@TestMetadata("defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt")
public void testDefaultValueOfInlineClassTypeInInlineFunInInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt");
}
@TestMetadata("inlineClassFun.kt")
public void testInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/inlineClassFun.kt");
@@ -12188,6 +12198,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testKt26554() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt26554.kt");
}
@TestMetadata("kt27416.kt")
public void testKt27416() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt27416.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@@ -12111,6 +12111,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt26858.kt");
}
@TestMetadata("kt27513.kt")
public void testKt27513() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt27513.kt");
}
@TestMetadata("lambdaInInlineClassFun.kt")
public void testLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt");
@@ -12169,6 +12174,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFun.kt");
}
@TestMetadata("defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt")
public void testDefaultValueOfInlineClassTypeInInlineFunInInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt");
}
@TestMetadata("inlineClassFun.kt")
public void testInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/inlineClassFun.kt");
@@ -12188,6 +12198,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testKt26554() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt26554.kt");
}
@TestMetadata("kt27416.kt")
public void testKt27416() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt27416.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@@ -12116,6 +12116,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt26858.kt");
}
@TestMetadata("kt27513.kt")
public void testKt27513() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt27513.kt");
}
@TestMetadata("lambdaInInlineClassFun.kt")
public void testLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt");
@@ -12174,6 +12179,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFun.kt");
}
@TestMetadata("defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt")
public void testDefaultValueOfInlineClassTypeInInlineFunInInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt");
}
@TestMetadata("inlineClassFun.kt")
public void testInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/inlineClassFun.kt");
@@ -12193,6 +12203,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testKt26554() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt26554.kt");
}
@TestMetadata("kt27416.kt")
public void testKt27416() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt27416.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@@ -5064,6 +5064,34 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ReplaceArraysCopyOfWithCopyOf extends AbstractLocalInspectionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInReplaceArraysCopyOfWithCopyOf() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("nonArraysCopyOf.kt")
public void testNonArraysCopyOf() throws Exception {
runTest("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf/nonArraysCopyOf.kt");
}
@TestMetadata("qualified.kt")
public void testQualified() throws Exception {
runTest("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf/qualified.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf/simple.kt");
}
}
@TestMetadata("idea/testData/inspectionsLocal/replaceAssertBooleanWithAssertEquality")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -5117,34 +5145,6 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ReplaceArraysCopyOfWithCopyOf extends AbstractLocalInspectionTest {
public void testAllFilesPresentInReplaceArraysCopyOfWithCopyOf() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("nonArraysCopyOf.kt")
public void testNonArraysCopyOf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf/nonArraysCopyOf.kt");
doTest(fileName);
}
@TestMetadata("qualified.kt")
public void testQualified() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf/qualified.kt");
doTest(fileName);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArraysCopyOfWithCopyOf/simple.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspectionsLocal/replacePutWithAssignment")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -10646,6 +10646,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt26858.kt");
}
@TestMetadata("kt27513.kt")
public void testKt27513() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt27513.kt");
}
@TestMetadata("lambdaInInlineClassFun.kt")
public void testLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt");
@@ -10704,6 +10709,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFun.kt");
}
@TestMetadata("defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt")
public void testDefaultValueOfInlineClassTypeInInlineFunInInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt");
}
@TestMetadata("inlineClassFun.kt")
public void testInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/inlineClassFun.kt");
@@ -10723,6 +10733,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testKt26554() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt26554.kt");
}
@TestMetadata("kt27416.kt")
public void testKt27416() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt27416.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")
@@ -11691,6 +11691,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt26858.kt");
}
@TestMetadata("kt27513.kt")
public void testKt27513() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/kt27513.kt");
}
@TestMetadata("lambdaInInlineClassFun.kt")
public void testLambdaInInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt");
@@ -11749,6 +11754,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFun.kt");
}
@TestMetadata("defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt")
public void testDefaultValueOfInlineClassTypeInInlineFunInInlineClass() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/defaultValueOfInlineClassTypeInInlineFunInInlineClass.kt");
}
@TestMetadata("inlineClassFun.kt")
public void testInlineClassFun() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/inlineClassFun.kt");
@@ -11768,6 +11778,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testKt26554() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt26554.kt");
}
@TestMetadata("kt27416.kt")
public void testKt27416() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/defaultParameterValues/kt27416.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/inlineClasses/functionNameMangling")