JS backend: simplify and rename tests for closure in nested functions.
This commit is contained in:
@@ -36,11 +36,11 @@ public final class ClosureTest extends SingleFileTranslationTest {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testLocalParameterInLocalNamedFunction() throws Exception {
|
||||
fooBoxTest();
|
||||
public void testClosureInNestedFunctions() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testObjectAsConstructorParameter() throws Exception {
|
||||
public void testClosureInNestedFunctionsWhichMixedWithObject() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: ()->T) = f()
|
||||
|
||||
fun funfun(): Boolean {
|
||||
val result = true
|
||||
|
||||
fun foo(): Boolean {
|
||||
fun bar() = result
|
||||
return bar()
|
||||
}
|
||||
|
||||
return foo()
|
||||
}
|
||||
|
||||
fun litlit(): Boolean {
|
||||
val result = true
|
||||
|
||||
return run {
|
||||
run { result }
|
||||
}
|
||||
}
|
||||
|
||||
fun funlit(): Boolean {
|
||||
val result = true
|
||||
|
||||
fun foo(): Boolean {
|
||||
return run { result }
|
||||
}
|
||||
|
||||
return foo()
|
||||
}
|
||||
|
||||
fun litfun(): Boolean {
|
||||
val result = true
|
||||
|
||||
return run {
|
||||
fun bar() = result
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!funfun()) "funfun failed"
|
||||
if (!litlit()) "litlit failed"
|
||||
if (!funlit()) "funlit failed"
|
||||
if (!litfun()) "litfun failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
fun run<T>(f: ()->T) = f()
|
||||
|
||||
fun box(): Boolean {
|
||||
val t = run {
|
||||
object {
|
||||
fun boo(param: String): String {
|
||||
return run { param }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t.boo("OK") == "OK"
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun getLastFocused(callback:(window:Any?)->Unit) {
|
||||
callback(null)
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
var result = "no"
|
||||
createTab(true) {
|
||||
result = it
|
||||
}
|
||||
return result == "yes"
|
||||
}
|
||||
|
||||
fun createTab(focusWindow:Boolean, callback:((String)->Unit)?) {
|
||||
getLastFocused {
|
||||
fun createTab() {
|
||||
if (focusWindow && callback != null) {
|
||||
callback("yes")
|
||||
}
|
||||
}
|
||||
|
||||
if (it == null) {
|
||||
createTab()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package foo
|
||||
|
||||
fun getLastFocused(callback: (window: Any?)->Unit) {
|
||||
callback(null)
|
||||
}
|
||||
|
||||
abstract class TabService(val ctorParam: String) {
|
||||
abstract fun query(callback: (tabs: String)->Unit)
|
||||
}
|
||||
|
||||
abstract class PageManager(val tabService: TabService)
|
||||
|
||||
class ChromePageManager(val expected: String) : PageManager(object : TabService(expected) {
|
||||
override fun query(callback: (tabs: String)->Unit) {
|
||||
getLastFocused {
|
||||
callback(expected)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
fun box(): Boolean {
|
||||
var result = ""
|
||||
val tabService = ChromePageManager("result").tabService
|
||||
tabService.query {
|
||||
result = it
|
||||
}
|
||||
return result == "result" && tabService.ctorParam == "result"
|
||||
}
|
||||
Reference in New Issue
Block a user