mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add tests for JSFunctor
This commit is contained in:
parent
5fca860b70
commit
53d784ee7b
|
@ -56,6 +56,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
|
|||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<configuration>
|
||||
<configLocation>../checkstyle.xml</configLocation>
|
||||
<includeTestSourceDirectory>true</includeTestSourceDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
52
teavm-jso/src/test/java/org/teavm/jso/test/FunctorTest.java
Normal file
52
teavm-jso/src/test/java/org/teavm/jso/test/FunctorTest.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2015 Alexey Andreev.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.teavm.jso.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSFunctor;
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public class FunctorTest {
|
||||
@Test
|
||||
public void functorPassed() {
|
||||
assertEquals("(5)", testMethod((a, b) -> a + b, 2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functorIdentityPreserved() {
|
||||
JSBiFunction javaFunction = (a, b) -> a + b;
|
||||
JSObject firstRef = getFunction(javaFunction);
|
||||
JSObject secondRef = getFunction(javaFunction);
|
||||
assertSame(firstRef, secondRef);
|
||||
}
|
||||
|
||||
@JSBody(params = { "f", "a", "b" }, script = "return '(' + f(a, b) + ')';")
|
||||
private static native String testMethod(JSBiFunction f, int a, int b);
|
||||
|
||||
@JSBody(params = "f", script = "return f;")
|
||||
private static native JSObject getFunction(JSBiFunction f);
|
||||
|
||||
@JSFunctor
|
||||
interface JSBiFunction extends JSObject {
|
||||
int apply(int a, int b);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user