Skip to content

Commit

Permalink
Added lambda test suite from Android's Jack
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Jul 15, 2015
1 parent e63c761 commit 4855cac
Show file tree
Hide file tree
Showing 51 changed files with 1,550 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/src/main/java/org/robovm/compiler/config/Config.java
Expand Up @@ -225,8 +225,8 @@ protected Config() throws IOException {
new ObjCMemberPlugin(),
new ObjCBlockPlugin(),
new AnnotationImplPlugin(),
// new LambdaPlugin()
new org.robovm.compiler.plugin.lambda2.LambdaPlugin()
new LambdaPlugin()
//new org.robovm.compiler.plugin.lambda2.LambdaPlugin()
));
this.loadPluginsFromClassPath();
}
Expand Down
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.robovm.rt;
package org.robovm.rt.lambdas;

import static org.junit.Assert.*;

Expand Down
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test001;

interface I {
int getValue();
}

/**
* Lambda expression test without parameters.
*/
public class Lambda {

public static int testGet10() {
I i = () -> 10;
return i.getValue();
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test001;

import org.junit.Assert;
import org.junit.Test;

/**
* Lambda expression test without parameters.
*/
public class Tests {

@Test
public void test001() {
Assert.assertEquals(10, Lambda.testGet10());
}
}
21 changes: 21 additions & 0 deletions tests/robovm/src/test/java/org/robovm/rt/lambdas/test002/I.java
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test002;

interface I {
int add(int a, int b);
}
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test002;

/**
* Lambda expression test with parameters.
*/
public class Lambda {

public static int testAdd(int a, int b) {
I i = (x, y) -> x + y;
return i.add(a, b);
}
}
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test002;

import org.junit.Assert;
import org.junit.Test;

/**
* Lambda expression test with parameters.
*/
public class Tests {

@Test
public void test001() {
Assert.assertEquals(10, Lambda.testAdd(5, 5));
Assert.assertEquals(8, Lambda.testAdd(5, 3));
}
}
21 changes: 21 additions & 0 deletions tests/robovm/src/test/java/org/robovm/rt/lambdas/test003/I.java
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test003;

interface I {
int addOutsideValue();
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test003;

/**
* Test with lambda expression accessing field and local variable from enclosing class.
*/
public class Lambda {

private int field;

public Lambda(int value) {
this.field = value;
}

public int testAdd(int a) {
I i = () -> a + field;
return i.addOutsideValue();
}
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test003;

import org.junit.Assert;
import org.junit.Test;

/**
* Test with lambda expression accessing field and local variable from enclosing class.
*/
public class Tests {

@Test
public void test001() {
Lambda lambda = new Lambda(5);
Assert.assertEquals(10, lambda.testAdd(5));
Assert.assertEquals(8, lambda.testAdd(3));
}
}
21 changes: 21 additions & 0 deletions tests/robovm/src/test/java/org/robovm/rt/lambdas/test004/I.java
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test004;

interface I {
int addOutsideValue();
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test004;


/**
* Test casting lambda expression.
*/
public class Lambda {

private int field;

public Lambda(int value) {
this.field = value;
}

public int testAdd(int a) {
return ((I)() -> a + field).addOutsideValue();
}
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test004;

import org.junit.Assert;
import org.junit.Test;

/**
* Test casting lambda expression.
*/
public class Tests {

@Test
public void test001() {
Lambda lambda = new Lambda(5);
Assert.assertEquals(10, lambda.testAdd(5));
Assert.assertEquals(8, lambda.testAdd(3));
}
}
21 changes: 21 additions & 0 deletions tests/robovm/src/test/java/org/robovm/rt/lambdas/test005/I.java
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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.robovm.rt.lambdas.test005;

interface I<V> {
int add(V val1, V val2);
}

0 comments on commit 4855cac

Please sign in to comment.