Add simple tests for interop with native code.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
class A(b : Int) {
|
||||
fun g() : Int = js.noImpl
|
||||
fun m() : Int = js.noImpl
|
||||
}
|
||||
|
||||
|
||||
fun box() : Boolean {
|
||||
if (A(2).g() != 4) {
|
||||
return false;
|
||||
}
|
||||
if (A(3).m() != 2) {
|
||||
return false;
|
||||
}
|
||||
val a = A(100)
|
||||
if (a.g() != 200) {
|
||||
return false;
|
||||
}
|
||||
if (a.m() != 99) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
fun returnFalse() : Boolean = js.noImpl
|
||||
|
||||
fun box() = !returnFalse()
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
/*function g should return 0 if a parameter is undefined 1 if parameter is 1 and 3 if parameter is 3*/
|
||||
native
|
||||
fun f(g : (Int?)-> Int) : Boolean = js.noImpl
|
||||
|
||||
|
||||
fun box() : Boolean {
|
||||
val b = {
|
||||
(a : Int?) ->
|
||||
if (a == null) {
|
||||
0
|
||||
} else if (a == 1) {
|
||||
1
|
||||
} else {
|
||||
3
|
||||
}
|
||||
}
|
||||
return f(b)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
import js.*
|
||||
|
||||
native
|
||||
fun paramCount(vararg a : Int) : Int = js.noImpl
|
||||
|
||||
fun count(vararg a : Int) = a.size
|
||||
|
||||
fun box() : Boolean {
|
||||
if (paramCount(1, 2 ,3) != 3) {
|
||||
return false;
|
||||
}
|
||||
if (paramCount() != 0) {
|
||||
return false;
|
||||
}
|
||||
if (count() != 0) {
|
||||
return false;
|
||||
}
|
||||
if (count(1, 1, 1, 1) != 4) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function A(b) {
|
||||
this.g = function() {
|
||||
return 2 * b;
|
||||
}
|
||||
this.m = function() {
|
||||
return b - 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function returnFalse() {
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
function f(g) {
|
||||
if (g() != 0) {
|
||||
return false;
|
||||
}
|
||||
if (g(1) != 1) {
|
||||
return false;
|
||||
}
|
||||
if (g(2) != 3) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function paramCount() {
|
||||
return arguments.length
|
||||
}
|
||||
Reference in New Issue
Block a user