JS: tests for KT-7357: extension functions from external KJS library couldn't be called in some cases

This commit is contained in:
Michael Nedzelsky
2015-04-09 13:06:15 +03:00
parent 66aa15f470
commit 6842c98285
8 changed files with 73 additions and 2 deletions
@@ -0,0 +1,13 @@
OUT:
Buildfile: [TestData]/build.xml
build:
[mkdir] Created dir: [Temp]/lib
[kotlin2js] Compiling [[TestData]/jslib-example] => [[Temp]/lib/jslib-example.js]
[kotlin2js] Compiling [[TestData]/root1] => [[Temp]/out.js]
[copy] Copying 2 files to [Temp]
BUILD SUCCESSFUL
Total time: [time]
Return code: 0
@@ -0,0 +1,22 @@
<project name="Ant Task Test" default="build">
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<property name="library.path" value="${test.data}/jslib-example"/>
<property name="temp.library.path" value="${temp}/lib"/>
<target name="build">
<mkdir dir="${temp.library.path}"/>
<kotlin2js src="${library.path}" output="${temp.library.path}/jslib-example.js" metaInfo="${temp.library.path}/jslib-example.meta.js"/>
<kotlin2js src="${test.data}/root1" output="${temp}/out.js" main="call">
<library>
<pathelement path="${temp.library.path}/jslib-example.meta.js"/>
</library>
</kotlin2js>
<copy todir="${temp}">
<fileset dir="${temp.library.path}">
<include name="**/*.js"/>
<exclude name="META-INF/**"/>
</fileset>
</copy>
</target>
</project>
@@ -0,0 +1,9 @@
package library.sample
import kotlin.js.Date
public class ClassA() {
val value: Int = 100
}
public fun Date.extFun(): Int = 100
@@ -0,0 +1,17 @@
package foo
import library.sample.*
import kotlin.js.Date
var ok = "FAIL"
fun main(args: Array<String>) {
val x = ClassA().value
if (x == 100) {
ok = "OK"
}
val date = Date()
println(date.extFun())
}
fun box(): String = ok
@@ -122,6 +122,11 @@ public class AntTaskJsTest extends AntTaskBaseTest {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithStdlibAndJsFileAsAnotherLib() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithMainFQArgs() throws Exception {
doJsAntTest();
@@ -3,6 +3,7 @@ package sample
import kotlin.Pair
import kotlin.browser.document
import library.sample.*
import kotlin.js.Date
fun myApp() {
val element = document.getElementById("foo")
@@ -11,6 +12,7 @@ fun myApp() {
val x = pairAdd(p)
val y = pairMul(p)
val z = IntHolder(100).value
element.appendChild(document.createTextNode("x=$x y=$y z=$z")!!)
val u = Date().extFun()
element.appendChild(document.createTextNode("x=$x y=$y z=$z u=$u")!!)
}
}
@@ -17,6 +17,6 @@ open class SampleTest {
val foo = driver.findElement(By.id("foo"))!!
val text = foo.getText() ?: ""
println("Found $foo with text '$text'")
assertEquals("x=30 y=200 z=100", text.trim())
assertEquals("x=30 y=200 z=100 u=1000", text.trim())
}
}
@@ -1,8 +1,11 @@
package library.sample
import kotlin.js.Date
public fun pairAdd(p: Pair<Int, Int>): Int = p.first + p.second
public fun pairMul(p: Pair<Int, Int>): Int = p.first * p.second
public data class IntHolder(val value: Int)
public fun Date.extFun(): Int = 1000