From 040a646174cc4c2807f63ed5fe0cb12f3aff4313 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 15 Feb 2016 14:27:25 +0300 Subject: [PATCH] [KT-4124] Add test case for nested native class --- .../js/test/semantics/NestedTypesTest.java | 25 +++++++++++++++++++ .../nestedTypes/cases/nestedNative.kt | 16 ++++++++++++ .../nestedTypes/native/nestedNative.js | 7 ++++++ 3 files changed, 48 insertions(+) create mode 100644 js/js.translator/testData/nestedTypes/cases/nestedNative.kt create mode 100644 js/js.translator/testData/nestedTypes/native/nestedNative.js diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NestedTypesTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NestedTypesTest.java index 2b8460a0fd6..0af939d993a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NestedTypesTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/NestedTypesTest.java @@ -16,8 +16,15 @@ package org.jetbrains.kotlin.js.test.semantics; +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.js.JavaScript; +import org.jetbrains.kotlin.js.config.EcmaVersion; import org.jetbrains.kotlin.js.test.SingleFileTranslationTest; +import java.io.File; +import java.util.List; + public class NestedTypesTest extends SingleFileTranslationTest { public NestedTypesTest() { super("nestedTypes/"); @@ -42,4 +49,22 @@ public class NestedTypesTest extends SingleFileTranslationTest { public void testOuterObject() throws Exception { checkFooBoxIsOk(); } + + public void testNestedNative() throws Exception { + checkFooBoxIsOk(); + } + + @NotNull + @Override + protected List additionalJsFiles(@NotNull EcmaVersion ecmaVersion) { + List result = Lists.newArrayList(super.additionalJsFiles(ecmaVersion)); + + String jsFilePath = pathToTestDir() + "native/" + getTestName(true) + JavaScript.DOT_EXTENSION; + File jsFile = new File(jsFilePath); + if (jsFile.exists() && jsFile.isFile()) { + result.add(jsFilePath); + } + + return result; + } } diff --git a/js/js.translator/testData/nestedTypes/cases/nestedNative.kt b/js/js.translator/testData/nestedTypes/cases/nestedNative.kt new file mode 100644 index 00000000000..26093d66c5e --- /dev/null +++ b/js/js.translator/testData/nestedTypes/cases/nestedNative.kt @@ -0,0 +1,16 @@ +package foo + +open class A { + @native class B(value: Int = 0) { + val foo: Int + get() = noImpl + fun bar(): Int = noImpl + } +} + +fun box(): String { + var b = A.B(23) + if (b.foo != 123) return "failed1: ${b.foo}" + if (b.bar() != 1123) return "failed2: ${b.bar()}" + return "OK" +} diff --git a/js/js.translator/testData/nestedTypes/native/nestedNative.js b/js/js.translator/testData/nestedTypes/native/nestedNative.js new file mode 100644 index 00000000000..8220cb5025d --- /dev/null +++ b/js/js.translator/testData/nestedTypes/native/nestedNative.js @@ -0,0 +1,7 @@ +function B(value) { + this.foo = 100 + value; +} +B.prototype = {}; +B.prototype.bar = function() { + return this.foo + 1000; +}; \ No newline at end of file