From c8efe8c4ecb76271ae9249733d99b8961b4757b7 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 14 Jan 2020 22:03:33 +0300 Subject: [PATCH] Add tests for equals, hashCode, toString in String and Number --- .../ir/FirBlackBoxCodegenTestGenerated.java | 10 ++++++++++ .../numberEqualsHashCodeToString.kt | 17 +++++++++++++++++ .../stringEqualsHashCodeToString.kt | 13 +++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 10 ++++++++++ .../codegen/LightAnalysisModeTestGenerated.java | 10 ++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 10 ++++++++++ .../semantics/IrJsCodegenBoxTestGenerated.java | 10 ++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 10 ++++++++++ 8 files changed, 90 insertions(+) create mode 100644 compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt create mode 100644 compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 9bae5638f20..794d1eea080 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -17865,11 +17865,21 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/primitiveTypes/number.kt"); } + @TestMetadata("numberEqualsHashCodeToString.kt") + public void testNumberEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt"); + } + @TestMetadata("rangeTo.kt") public void testRangeTo() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt"); } + @TestMetadata("stringEqualsHashCodeToString.kt") + public void testStringEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt"); + } + @TestMetadata("substituteIntForGeneric.kt") public void testSubstituteIntForGeneric() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/substituteIntForGeneric.kt"); diff --git a/compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt b/compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt new file mode 100644 index 00000000000..db815d29dbd --- /dev/null +++ b/compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt @@ -0,0 +1,17 @@ +fun test(n: Number) { + if (!n.equals(n)) throw Error("fail 1 for $n") + if (n.equals(1)) throw Error("fail 2 for $n") + if (n.equals(1L)) throw Error("fail 3 for $n") + if (n != n) throw Error("fail 4 for $n") + if (n == 1) throw Error("fail 5 for $n") + if (n == 1L) throw Error("fail 6 for $n") + if (n.hashCode() != n.toInt()) throw Error("fail 7 for $n") + if (n.toString() != "$n") throw Error("fail 8 for $n") +} + +fun box(): String { + test(234) + test(546L) + + return "OK" +} diff --git a/compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt b/compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt new file mode 100644 index 00000000000..d0180b0874b --- /dev/null +++ b/compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt @@ -0,0 +1,13 @@ +fun test(s: String) { + if (!s.equals(s)) throw Error("fail 1 for $s") + if (s.equals(1)) throw Error("fail 2 for $s") + if (s != s) throw Error("fail 4 for $s") + if (s == "111") throw Error("fail 5 for $s") + if (s.hashCode() != -1268878963) throw Error("fail 7 for $s") + if (s.toString() != "$s") throw Error("fail 8 for $s") +} + +fun box(): String { + test("foobar") + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 90cb06b11e4..3d792a6469f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -19381,11 +19381,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/primitiveTypes/number.kt"); } + @TestMetadata("numberEqualsHashCodeToString.kt") + public void testNumberEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt"); + } + @TestMetadata("rangeTo.kt") public void testRangeTo() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt"); } + @TestMetadata("stringEqualsHashCodeToString.kt") + public void testStringEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt"); + } + @TestMetadata("substituteIntForGeneric.kt") public void testSubstituteIntForGeneric() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/substituteIntForGeneric.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 8e0ed08aaaa..6eaac41ffac 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -19381,11 +19381,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/primitiveTypes/number.kt"); } + @TestMetadata("numberEqualsHashCodeToString.kt") + public void testNumberEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt"); + } + @TestMetadata("rangeTo.kt") public void testRangeTo() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt"); } + @TestMetadata("stringEqualsHashCodeToString.kt") + public void testStringEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt"); + } + @TestMetadata("substituteIntForGeneric.kt") public void testSubstituteIntForGeneric() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/substituteIntForGeneric.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 45954ebe969..eea3e0de026 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -17865,11 +17865,21 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/primitiveTypes/number.kt"); } + @TestMetadata("numberEqualsHashCodeToString.kt") + public void testNumberEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt"); + } + @TestMetadata("rangeTo.kt") public void testRangeTo() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt"); } + @TestMetadata("stringEqualsHashCodeToString.kt") + public void testStringEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt"); + } + @TestMetadata("substituteIntForGeneric.kt") public void testSubstituteIntForGeneric() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/substituteIntForGeneric.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index b589bad8308..41598b6aee7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -14901,11 +14901,21 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/primitiveTypes/nullableCharBoolean.kt"); } + @TestMetadata("numberEqualsHashCodeToString.kt") + public void testNumberEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt"); + } + @TestMetadata("rangeTo.kt") public void testRangeTo() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt"); } + @TestMetadata("stringEqualsHashCodeToString.kt") + public void testStringEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt"); + } + @TestMetadata("substituteIntForGeneric.kt") public void testSubstituteIntForGeneric() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/substituteIntForGeneric.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 62cb31dff3c..473a7080b56 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -15006,11 +15006,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/primitiveTypes/nullableCharBoolean.kt"); } + @TestMetadata("numberEqualsHashCodeToString.kt") + public void testNumberEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/numberEqualsHashCodeToString.kt"); + } + @TestMetadata("rangeTo.kt") public void testRangeTo() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt"); } + @TestMetadata("stringEqualsHashCodeToString.kt") + public void testStringEqualsHashCodeToString() throws Exception { + runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt"); + } + @TestMetadata("substituteIntForGeneric.kt") public void testSubstituteIntForGeneric() throws Exception { runTest("compiler/testData/codegen/box/primitiveTypes/substituteIntForGeneric.kt");