From 5bf1d731997d2f69007cedfda1872fc7ab7b5380 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Tue, 2 Dec 2014 20:35:52 +0300 Subject: [PATCH] JS backend: tests for translation for extension property --- .../k2js/test/semantics/NameClashesTest.java | 4 ++ .../function/cases/manglingStability.kt | 52 ++++++++++++++++--- .../cases/extensionFunctionAndProperty.kt | 14 +++++ 3 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 js/js.translator/testData/nameClashes/cases/extensionFunctionAndProperty.kt diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/NameClashesTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/NameClashesTest.java index da00cf2926a..5874ea854bb 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/NameClashesTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/semantics/NameClashesTest.java @@ -40,4 +40,8 @@ public final class NameClashesTest extends SingleFileTranslationTest { public void testMethodOverloadInClassWithTwoUpperBounds() throws Exception { checkFooBoxIsOk(); } + + public void testExtensionFunctionAndProperty() throws Exception { + checkFooBoxIsOk(); + } } \ No newline at end of file diff --git a/js/js.translator/testData/expression/function/cases/manglingStability.kt b/js/js.translator/testData/expression/function/cases/manglingStability.kt index 3a368c629cf..f8a8cf15e71 100644 --- a/js/js.translator/testData/expression/function/cases/manglingStability.kt +++ b/js/js.translator/testData/expression/function/cases/manglingStability.kt @@ -1,36 +1,36 @@ package foo fun internal_foo(): Int = 1 -native fun internal_foo(a: Array) = "should be ingnored" +native fun internal_foo(a: Array) = "should be ignored" fun internal_foo(i: Int): Int = 2 fun internal_boo(i: Int): Int = 2 fun internal_boo(s: String): Int = 3 fun internal_boo(): Int = 1 -native fun internal_boo(a: Array) = "should be ingnored" +native fun internal_boo(a: Array) = "should be ignored" val internal_f = { internal_foo() + internal_foo(1) } val internal_b = { internal_boo() + internal_boo(1) } public fun public_foo(): Int = 1 -native public fun public_foo(a: Array): String = "should be ingnored" +native public fun public_foo(a: Array): String = "should be ignored" public fun public_foo(i: Int): Int = 2 public fun public_boo(i: Int): Int = 2 public fun public_boo(s: String): Int = 3 public fun public_boo(): Int = 1 -native public fun public_boo(a: Array): String = "should be ingnored" +native public fun public_boo(a: Array): String = "should be ignored" val public_f = { public_foo() + public_foo(1) } val public_b = { public_boo() + public_boo(1) } -native private fun private_foo(a: Array): String = "should be ingnored" +native private fun private_foo(a: Array): String = "should be ignored" private fun private_foo(): Int = 1 private fun private_foo(i: Int): Int = 2 -native private fun private_boo(a: Array): String = "should be ingnored" +native private fun private_boo(a: Array): String = "should be ignored" private fun private_boo(i: Int): Int = 2 private fun private_boo(s: String): Int = 3 private fun private_boo(): Int = 1 @@ -41,13 +41,13 @@ val private_b = { private_boo() + private_boo(1) } public fun mixed_foo(s: String): Int = 3 fun mixed_foo(): Int = 1 -native fun mixed_foo(a: Array) = "should be ingnored" +native fun mixed_foo(a: Array) = "should be ignored" private fun mixed_foo(s: String, i: Int): Int = 4 fun mixed_foo(i: Int): Int = 2 fun mixed_boo(i: Int): Int = 2 private fun mixed_boo(s: String, i: Int): Int = 4 -native fun mixed_boo(a: Array) = "should be ingnored" +native fun mixed_boo(a: Array) = "should be ignored" public fun mixed_boo(s: String): Int = 3 fun mixed_boo(): Int = 1 @@ -115,6 +115,38 @@ class TestMixed { val mixed_in_class_f = TestMixed().f val mixed_in_class_b = TestMixed().b +class A + +public fun A.foo(): Int = 2 +public val A.foo: Int + get() = 1 +public val A.boo: Int + get() = 1 +public fun A.boo(): Int = 2 + +val public_ext_f = { A.(): Int -> this.foo() + this.foo } +val public_ext_b = { A.(): Int -> this.boo() + this.boo } + +trait TestPublicInTrait { + public fun foo(): Int = 2 + public val foo: Int + public val boo: Int + public fun boo(): Int = 2 +} + +val public_in_trait_f = { (obj: TestPublicInTrait) -> obj.foo() + obj.foo } +val public_in_trait_b = { (obj: TestPublicInTrait) -> obj.boo() + obj.boo } + +trait TestInternalInTrait { + fun foo(): Int = 2 + val foo: Int + val boo: Int + fun boo(): Int = 2 +} + +val internal_in_trait_f = { (obj: TestInternalInTrait) -> obj.foo() + obj.foo } +val internal_in_trait_b = { (obj: TestInternalInTrait) -> obj.boo() + obj.boo } + //Testing fun test(testName: String, ff: Any, fb: Any) { @@ -135,5 +167,9 @@ fun box(): String { test("private_in_class", private_in_class_f, private_in_class_b) test("mixed_in_class", mixed_in_class_f, mixed_in_class_b) + test("public_ext_prop", public_ext_f, public_ext_b) + test("public_in_trait", public_in_trait_f, public_in_trait_b) + test("internal_in_trait", internal_in_trait_f, internal_in_trait_b) + return "OK" } diff --git a/js/js.translator/testData/nameClashes/cases/extensionFunctionAndProperty.kt b/js/js.translator/testData/nameClashes/cases/extensionFunctionAndProperty.kt new file mode 100644 index 00000000000..42fcaa4b366 --- /dev/null +++ b/js/js.translator/testData/nameClashes/cases/extensionFunctionAndProperty.kt @@ -0,0 +1,14 @@ +package foo + +fun box(): String { + + val data = listOf("foo", "bar") + + assertEquals("bar", data.last()) + assertEquals("bar", data.last) + + assertEquals("foo", data.first) + assertEquals("foo", data.first()) + + return "OK" +} \ No newline at end of file