diff --git a/compiler/testData/codegen/box/strings/interpolation.kt b/compiler/testData/codegen/box/strings/interpolation.kt new file mode 100644 index 00000000000..772cb33771a --- /dev/null +++ b/compiler/testData/codegen/box/strings/interpolation.kt @@ -0,0 +1,9 @@ +fun test(p: String?): String { + return "${p ?: "Default"} test" +} +fun box(): String { + if (test(null) != "Default test") return "fail 1: ${test(null)}" + if (test("Good") != "Good test") return "fail 1: ${test("OK")}" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/stringBuilderAppend.kt b/compiler/testData/codegen/bytecodeText/stringOperations/concat.kt similarity index 100% rename from compiler/testData/codegen/bytecodeText/stringBuilderAppend.kt rename to compiler/testData/codegen/bytecodeText/stringOperations/concat.kt diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/infixPlus.kt b/compiler/testData/codegen/bytecodeText/stringOperations/infixPlus.kt new file mode 100644 index 00000000000..03057e0a39a --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/infixPlus.kt @@ -0,0 +1,17 @@ +class A() { + + override fun toString(): String { + return "A" + } +} + + +fun box() : String { + + val s = "1" plus "2" plus 3 plus 4L plus 5.0 plus 6F plus '7' plus A() + + return "OK" +} + +/*TODO: +1 NEW java/lang/StringBuilder*/ diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/interpolation.kt b/compiler/testData/codegen/bytecodeText/stringOperations/interpolation.kt new file mode 100644 index 00000000000..de15a668890 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/interpolation.kt @@ -0,0 +1,16 @@ +class A() { + + override fun toString(): String { + return "A" + } +} + + +fun box() : String { + val p = 1 + val s = "${p}${2}${3}${4L}${5.0}${6F}${7}${A()}" + + return "OK" +} + +// 1 NEW java/lang/StringBuilder \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/stringOperations/plusAssign.kt b/compiler/testData/codegen/bytecodeText/stringOperations/plusAssign.kt new file mode 100644 index 00000000000..9e71eeb9824 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/stringOperations/plusAssign.kt @@ -0,0 +1,16 @@ +class A() { + + override fun toString(): String { + return "A" + } +} + + +fun box() : String { + var s = "1" + s += "2" + 3 + 4L + 5.0 + 6F + '7' + A() + + return "OK" +} + +// 1 NEW java/lang/StringBuilder \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index f02f6b146cd..72a4fda9089 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -42,6 +42,7 @@ import java.util.regex.Pattern; BytecodeTextTestGenerated.Statements.class, BytecodeTextTestGenerated.StaticFields.class, BytecodeTextTestGenerated.StoreStackBeforeInline.class, + BytecodeTextTestGenerated.StringOperations.class, BytecodeTextTestGenerated.When.class, BytecodeTextTestGenerated.WhenEnumOptimization.class, BytecodeTextTestGenerated.WhenStringOptimization.class, @@ -208,12 +209,6 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } - @TestMetadata("stringBuilderAppend.kt") - public void testStringBuilderAppend() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringBuilderAppend.kt"); - doTest(fileName); - } - @TestMetadata("topLevelFunWithDefaultArgs.kt") public void testTopLevelFunWithDefaultArgs() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/topLevelFunWithDefaultArgs.kt"); @@ -661,6 +656,39 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/stringOperations") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class StringOperations extends AbstractBytecodeTextTest { + public void testAllFilesPresentInStringOperations() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/stringOperations"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("concat.kt") + public void testConcat() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/concat.kt"); + doTest(fileName); + } + + @TestMetadata("infixPlus.kt") + public void testInfixPlus() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/infixPlus.kt"); + doTest(fileName); + } + + @TestMetadata("interpolation.kt") + public void testInterpolation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/interpolation.kt"); + doTest(fileName); + } + + @TestMetadata("plusAssign.kt") + public void testPlusAssign() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/stringOperations/plusAssign.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/when") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 9ac83449a76..9a0f13ef367 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -6525,6 +6525,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("interpolation.kt") + public void testInterpolation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/strings/interpolation.kt"); + doTest(fileName); + } + @TestMetadata("kt2592.kt") public void testKt2592() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/strings/kt2592.kt");