Added and sorted tests from jet repository. Fixed a bug with custom setter.

This commit is contained in:
Pavel Talanov
2011-11-26 00:38:17 +04:00
parent e36eaa08a4
commit 97fbcb4775
51 changed files with 1399 additions and 376 deletions
+1
View File
@@ -6,6 +6,7 @@
<module fileurl="file://$PROJECT_DIR$/../Kotlin/jet/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/../Kotlin/jet/compiler/frontend/frontend.iml" />
<module fileurl="file://$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/../../Kotlin/jet/compiler/frontend.java/frontend.java.iml" />
<module fileurl="file://$PROJECT_DIR$/../Kotlin/jet/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/../Kotlin/jet/compiler/frontend.java/frontend.java.iml" />
<module fileurl="file://$PROJECT_DIR$/examples/jetTests.iml" filepath="$PROJECT_DIR$/examples/jetTests.iml" />
<module fileurl="file://$PROJECT_DIR$/js/js.iml" filepath="$PROJECT_DIR$/js/js.iml" />
<module fileurl="file://$PROJECT_DIR$/translator/translator.iml" filepath="$PROJECT_DIR$/translator/translator.iml" />
</modules>
+553 -350
View File
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="IDEA IC-110.408" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="translator" />
</component>
</module>
+34
View File
@@ -0,0 +1,34 @@
import com.intellij.testFramework.UsefulTestCase;
import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.k2js.test.ExampleTest;
public final class ExampleTestSuite extends UsefulTestCase {
private String name;
private ExampleTest tester = new ExampleTest();
public ExampleTestSuite(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
public void runTest() throws Exception {
tester.runBoxTest(getName());
}
public static Test suite() {
return JetTestCaseBuilder.suiteForDirectory("translator",
"/testFiles/examples/cases/", true, new JetTestCaseBuilder.NamedTestFactory() {
@NotNull
@Override
public Test createTest(@NotNull String dataPath, @NotNull String name) {
return (new ExampleTestSuite(name));
}
});
}
}
+86
View File
@@ -0,0 +1,86 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author abreslav
*/
public abstract class JetTestCaseBuilder {
public static FilenameFilter emptyFilter = new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return true;
}
};
public interface NamedTestFactory {
@NotNull
Test createTest(@NotNull String dataPath, @NotNull String name);
}
@NotNull
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, @NotNull NamedTestFactory factory) {
return suiteForDirectory(baseDataDir, dataPath, recursive, emptyFilter, factory);
}
@NotNull
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, final FilenameFilter filter, @NotNull NamedTestFactory factory) {
TestSuite suite = new TestSuite(dataPath);
appendTestsInDirectory(baseDataDir, dataPath, recursive, filter, factory, suite);
return suite;
}
public static void appendTestsInDirectory(String baseDataDir, String dataPath, boolean recursive,
final FilenameFilter filter, NamedTestFactory factory, TestSuite suite) {
final String extensionJet = ".jet";
final String extensionKt = ".kt";
final FilenameFilter extensionFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(extensionJet) || name.endsWith(extensionKt);
}
};
FilenameFilter resultFilter;
if (filter != emptyFilter) {
resultFilter = new FilenameFilter() {
@Override
public boolean accept(File file, String s) {
return extensionFilter.accept(file, s) && filter.accept(file, s);
}
};
} else {
resultFilter = extensionFilter;
}
File dir = new File(baseDataDir + dataPath);
FileFilter dirFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
};
if (recursive) {
File[] files = dir.listFiles(dirFilter);
assert files != null : dir;
List<File> subdirs = Arrays.asList(files);
Collections.sort(subdirs);
for (File subdir : subdirs) {
suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory));
}
}
List<File> files = Arrays.asList(dir.listFiles(resultFilter));
Collections.sort(files);
for (File file : files) {
String fileName = file.getName();
assert fileName != null;
String extension = fileName.endsWith(extensionJet) ? extensionJet : extensionKt;
suite.addTest(factory.createTest(dataPath, fileName));
}
}
}
+33
View File
@@ -0,0 +1,33 @@
import junit.framework.Test;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetLiteFixture;
public final class ExampleTestSuite extends JetLiteFixture {
private String name;
public ExampleTestSuite(@NonNls String dataPath, String name) {
this.name = name;
}
public String getName() {
return "test" + name;
}
public void runTest() throws Exception {
}
public static Test suite() {
return JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(),
"/checkerWithErrorTypes/quick", true, new JetTestCaseBuilder.NamedTestFactory() {
@NotNull
@Override
public Test createTest(@NotNull String dataPath, @NotNull String name) {
return (new ExampleTestSuite(dataPath, name));
}
});
}
}
Binary file not shown.
@@ -7,7 +7,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
import org.jetbrains.k2js.translate.general.AbstractTranslator;
@@ -139,20 +138,6 @@ public final class PropertyTranslator extends AbstractTranslator {
@NotNull
private JsPropertyInitializer translateCustomAccessor(@NotNull JetPropertyAccessor expression) {
JsFunction methodBody = translateCustomAccessorBody(expression);
// we know that custom getters and setters always have their descriptors
return AstUtil.newNamedMethod(context().getNameForElement(expression), methodBody);
return Translation.functionTranslator(expression, context()).translateAsMethod();
}
@NotNull
private JsFunction translateCustomAccessorBody(@NotNull JetPropertyAccessor expression) {
JsFunction methodBody = JsFunction.getAnonymousFunctionWithScope(context().getScopeForElement(expression));
JetExpression bodyExpression = expression.getBodyExpression();
assert bodyExpression != null : "Custom accessor should have a body.";
JsBlock methodBodyBlock = AstUtil.convertToBlock(
Translation.translateExpression(bodyExpression, context().newPropertyAccess(expression)));
methodBody.setBody(methodBodyBlock);
return methodBody;
}
}
@@ -17,16 +17,18 @@ import java.util.List;
public final class FunctionTranslator extends AbstractTranslator {
@NotNull
private final JetFunction functionDeclaration;
private final JetDeclarationWithBody functionDeclaration;
@NotNull
private final JsFunction functionObject;
@NotNull
public static FunctionTranslator newInstance(@NotNull JetFunction function, @NotNull TranslationContext context) {
public static FunctionTranslator newInstance(@NotNull JetDeclarationWithBody function,
@NotNull TranslationContext context) {
return new FunctionTranslator(function, context);
}
private FunctionTranslator(@NotNull JetFunction functionDeclaration, @NotNull TranslationContext context) {
private FunctionTranslator(@NotNull JetDeclarationWithBody functionDeclaration,
@NotNull TranslationContext context) {
super(context);
this.functionDeclaration = functionDeclaration;
this.functionObject = createFunctionObject();
@@ -34,7 +36,8 @@ public final class FunctionTranslator extends AbstractTranslator {
@NotNull
public JsPropertyInitializer translateAsMethod() {
JsName functionName = context().getNameForElement(functionDeclaration);
assert functionDeclaration instanceof JetElement;
JsName functionName = context().getNameForElement((JetElement) functionDeclaration);
JsFunction function = generateFunctionObject();
return new JsPropertyInitializer(functionName.makeRef(), function);
}
@@ -53,16 +56,25 @@ public final class FunctionTranslator extends AbstractTranslator {
}
private JsFunction createFunctionObject() {
if (functionDeclaration instanceof JetNamedFunction) {
if (isDeclaration()) {
return JsFunction.getAnonymousFunctionWithScope
(context().getScopeForElement(functionDeclaration));
(context().getScopeForElement((JetDeclaration) functionDeclaration));
}
if (functionDeclaration instanceof JetFunctionLiteral) {
if (isLiteral()) {
return new JsFunction(context().enclosingScope());
}
throw new AssertionError("Unsupported type of functionDeclaration.");
}
private boolean isLiteral() {
return functionDeclaration instanceof JetFunctionLiteral;
}
private boolean isDeclaration() {
return (functionDeclaration instanceof JetNamedFunction) ||
(functionDeclaration instanceof JetPropertyAccessor);
}
@NotNull
private JsBlock translateBody() {
JetExpression jetBodyExpression = functionDeclaration.getBodyExpression();
@@ -101,7 +113,10 @@ public final class FunctionTranslator extends AbstractTranslator {
if (functionDeclaration instanceof JetNamedFunction) {
return context().newFunctionDeclaration((JetNamedFunction) functionDeclaration);
}
if (functionDeclaration instanceof JetFunctionLiteral) {
if (functionDeclaration instanceof JetPropertyAccessor) {
return context().newPropertyAccess((JetPropertyAccessor) functionDeclaration);
}
if (isLiteral()) {
return context().newEnclosingScope(functionObject.getScope());
}
throw new AssertionError("Unsupported type of functionDeclaration.");
@@ -26,7 +26,7 @@ import org.jetbrains.k2js.translate.reference.ReferenceTranslator;
public final class Translation {
@NotNull
static public FunctionTranslator functionTranslator(@NotNull JetFunction function,
static public FunctionTranslator functionTranslator(@NotNull JetDeclarationWithBody function,
@NotNull TranslationContext context) {
return FunctionTranslator.newInstance(function, context);
}
@@ -6,6 +6,7 @@ import org.junit.Test;
* @author Talanov Pavel
*/
public class ConditionalTest extends AbstractExpressionTest {
final private static String MAIN = "conditional/";
@Override
@@ -0,0 +1,18 @@
package org.jetbrains.k2js.test;
/**
* @author Talanov Pavel
*/
public final class ExampleTest extends TranslationTest {
final private static String MAIN = "examples/";
@Override
protected String mainDirectory() {
return MAIN;
}
public void runBoxTest(String filename) throws Exception {
testFunctionOutput(filename, "Anonymous", "box", "OK");
}
}
@@ -76,6 +76,8 @@ public class KotlinLibTest extends TranslationTest {
new RhinoPropertyTypesChecker("foo", propertyToType));
}
//
// TODO:Refactor calls to function result checker with test
@Test
public void namespaceHasDeclaredFunction() throws Exception {
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")),
@@ -14,7 +14,7 @@ import java.util.List;
*/
public abstract class TranslationTest {
final protected static String TEST_FILES = "testFiles/";
final protected static String TEST_FILES = "translator/testFiles/";
final private static String CASES = "cases/";
final private static String OUT = "out/";
final private static String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
@@ -0,0 +1,7 @@
fun box() : String {
return apply( "OK", {(arg: String) => arg } )
}
fun apply(arg : String, f : fun (p:String) : String) : String {
return f(arg)
}
@@ -0,0 +1,7 @@
fun box() : String {
return if (apply( 5, {(arg: Int) => arg + 13 } ) == 18) "OK" else "fail"
}
fun apply(arg : Int, f : fun (p:Int) : Int) : Int {
return f(arg)
}
@@ -0,0 +1,24 @@
// Changed when traits were introduced. May not make sense any more
open class Base() {
public var v : Int = 0
}
open class Left() : Base() {}
trait Right : Base {}
class D() : Left(), Right
fun vl(l : Left) : Int = l.v
fun vr(r : Right) : Int = r.v
fun box() : String {
val d = D()
d.v = 42
if (d.v != 42) return "Fail #1"
if (vl(d) != 42) return "Fail #2"
if (vr(d) != 42) return "Fail #3"
return "OK"
}
@@ -0,0 +1,8 @@
fun box() : String {
val cl = 39
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL"
}
fun sum(arg:Int, f : fun () : Int) : Int {
return arg + f()
}
@@ -0,0 +1,8 @@
fun box() : String {
val cl = 39
return if (sum(200, { val m = { val r = { cl }; r() }; m() }) == 239) "OK" else "FAIL"
}
fun sum(arg:Int, f : fun () : Int) : Int {
return arg + f()
}
@@ -0,0 +1,17 @@
open class Base() {
fun n(n : Int) : Int = n + 1
}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
fun test(s : Base) : Boolean = s.n(238) == 239
fun box() : String {
if (!test(Base())) return "Fail #1"
if (!test(Derived1())) return "Fail #2"
if (!test(Derived2())) return "Fail #3"
return "OK"
}
@@ -0,0 +1,13 @@
class C() {
public var f: Int
{
$f = 610
}
}
fun box(): String {
val c = C()
if (c.f != 610) return "fail"
return "OK"
}
@@ -0,0 +1,19 @@
fun box() : String {
val i: Int? = 7
val j: Int? = null
val k = 7
//verify errors
if (i == 7) {}
if (7 == i) {}
if (j == 7) {}
if (7 == j) {}
if (i == k) {}
if (k == i) {}
if (j == k) {}
if (k == j) {}
return "OK"
}
@@ -0,0 +1,11 @@
class SimpleClass() {
fun foo() = 610
}
fun box() : String {
val c = SimpleClass()
if (c.foo() == 610) {
return "OK"
}
return "FAIL"
}
@@ -0,0 +1,33 @@
open class Base() {
val plain = 239
public val read : Int
get() = 239
public var readwrite : Int = 0
get() = $readwrite + 1
set(n : Int) {
$readwrite = n
}
}
trait Abstract {}
class Derived1() : Base(), Abstract {}
class Derived2() : Abstract, Base() {}
fun code(s : Base) : Int {
if (s.plain != 239) return 1
if (s.read != 239) return 2
s.readwrite = 238
if (s.readwrite != 239) return 3
return 0
}
fun test(s : Base) : Boolean = code(s) == 0
fun box() : String {
if (!test(Base())) return "Fail #1"
if (!test(Derived1())) return "Fail #2"
if (!test(Derived2())) return "Fail #3"
return "OK"
}
@@ -0,0 +1,20 @@
// Changed when traits were introduced. May not make sense any more
trait Left {}
open class Right() {
open fun f() = 42
}
class D() : Left, Right() {
override fun f() = 239
}
fun box() : String {
val r : Right = Right()
val d : D = D()
if (r.f() != 42) return "Fail #1"
if (d.f() != 239) return "Fail #2"
return "OK"
}
@@ -0,0 +1,7 @@
fun box() : String {
return invoker( {"OK"} )
}
fun invoker(gen : fun () : String) : String {
return gen()
}
@@ -0,0 +1,7 @@
fun box() : String {
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
}
fun int_invoker(gen : fun () : Int) : Int {
return gen()
}
@@ -0,0 +1,12 @@
class Point(val x:Int, val y:Int) {
fun mul() : fun (scalar:Int):Point {
return { (scalar:Int):Point => Point(x * scalar, y * scalar) }
}
}
val m = Point(2, 3).mul() : fun (scalar:Int):Point
fun box() : String {
val answer = m(5)
return if (answer.x == 10 && answer.y == 15) "OK" else "FAIL"
}
@@ -0,0 +1,8 @@
class Box<T>(t: T) {
var value = t
}
fun box(): String {
val box: Box<Int> = Box<Int>(1)
return if (box.value == 1) "OK" else "fail"
}
@@ -0,0 +1,13 @@
open class Foo {
fun xyzzy(): String = "xyzzy"
}
class Bar(): Foo {
fun test(): String = xyzzy()
}
fun box() : String {
val bar = Bar()
val f = bar.test()
return if (f == "xyzzy") "OK" else "fail"
}
@@ -0,0 +1,7 @@
class GameError(msg: String): Exception(msg) {
}
fun box(): String {
val e = GameError("foo")
return if (e.getMessage() == "foo") "OK" else "fail"
}
@@ -0,0 +1,22 @@
open class M() {
open var b: Int = 0
}
class N() : M() {
val a : Int
get() {
super.b = super.b + 1
return super.b + 1
}
override var b: Int = a + 1
val superb : Int
get() = super.b
}
fun box(): String {
val n = N()
System.out?.println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
return "fail";
}
@@ -0,0 +1,11 @@
class C() {
class object {
fun create() = C()
}
}
fun box(): String {
val c = C.create()
return if (c is C) "OK" else "fail"
}
@@ -0,0 +1,9 @@
class C() {
fun getInstance(): Runnable = C
class object: Runnable {
override fun run(): Unit { }
}
}
fun foo() = C().getInstance()
@@ -0,0 +1,13 @@
abstract open class Default {
abstract fun defaultValue(): Int
}
class MyInt() {
class object : Default {
override fun defaultValue(): Int = 610
}
}
fun toDefault<T: Any>(t: T) where class object T: Default = T.defaultValue()
fun box(): String = if (toDefault<MyInt>(MyInt()) == 610) "OK" else "fail"
@@ -0,0 +1,42 @@
trait BK {
fun x() : Int = 50
}
trait K : BK {
override fun x() : Int = super.x() * 2
}
open class M() {
open fun x() : Int = 10
open var y = 500
}
open class N() : M(), K {
override fun x() : Int = 20
override var y = 200
open class C() : K {
fun test1() = x()
fun test2() = super<M>@N.x()
fun test3() = super<K>@N.x()
fun test4() = super<K>.x()
fun test5() = y
fun test6() : Int {
super<M>@N.y += 200
return super<M>@N.y
}
}
}
fun box(): String {
if (N().C().test1() != 100) return "test1 fail";
if (N().C().test2() != 10) return "test2 fail";
if (N().C().test3() != 100) return "test3 fail";
if (N().C().test4() != 100) return "test4 fail";
if (N().C().test5() != 200) return "test5 fail";
if (N().C().test6() != 700) return "test6 fail";
return "OK";
}
@@ -0,0 +1,13 @@
class Point(val x : Int, val y : Int)
fun box() : String {
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point =>
Point(x * scalar, y * scalar)
})
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
}
fun apply(arg:Point, f : fun Point.(scalar : Int) : Point) : Point {
return arg.f(2)
}
@@ -0,0 +1,41 @@
// Changed when traits were introduced. May not make sense any more
open class X(val x : Int) {}
trait Y {
abstract val y : Int
}
class YImpl(override val y : Int) : Y {}
class Point(x : Int, yy : Int) : X(x) , Y {
override val y : Int = yy
}
trait Abstract {}
class P1(x : Int, yy : Y) : Abstract, X(x), Y by yy {}
class P2(x : Int, yy : Y) : X(x), Abstract, Y by yy {}
class P3(x : Int, yy : Y) : X(x), Y by yy, Abstract {}
class P4(x : Int, yy : Y) : Y by yy, Abstract, X(x) {}
fun box() : String {
if (X(239).x != 239) return "FAIL #1"
if (YImpl(239).y != 239) return "FAIL #2"
val p = Point(240, -1)
if (p.x + p.y != 239) return "FAIL #3"
val y = YImpl(-1)
val p1 = P1(240, y)
if (p1.x + p1.y != 239) return "FAIL #4"
val p2 = P2(240, y)
if (p2.x + p2.y != 239) return "FAIL #5"
val p3 = P3(240, y)
if (p3.x + p3.y != 239) return "FAIL #6"
val p4 = P4(240, y)
if (p4.x + p4.y != 239) return "FAIL #7"
return "OK"
}
@@ -0,0 +1,14 @@
class Outer() {
open class InnerBase() {
}
class InnerDerived(): InnerBase() {
}
public val foo: InnerBase? = InnerDerived()
}
fun box() : String {
val o = Outer()
return if (o.foo === null) "fail" else "OK"
}
@@ -0,0 +1,16 @@
class Outer() {
val s = "xyzzy"
open class InnerBase(public val name: String) {
}
class InnerDerived(): InnerBase(s) {
}
val x = InnerDerived()
}
fun box() : String {
val o = Outer()
return if (o.x.name != "xyzzy") "fail" else "OK"
}
@@ -0,0 +1,29 @@
trait M {
var backingB : Int
var b : Int
get() = backingB
set(value: Int) {
backingB = value
}
}
class N() : M {
override var backingB : Int = 0
val a : Int
get() {
super.b = super.b + 1
return super.b + 1
}
override var b: Int = a + 1
val superb : Int
get() = super.b
}
fun box(): String {
val n = N()
System.out?.println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
return "fail";
}
@@ -0,0 +1,21 @@
import java.util.ArrayList
trait Tr {
fun extra() : String = "_"
}
class N() : ArrayList<Any>(), Tr {
override fun add(el: Any) : Boolean {
super<ArrayList>.add(el)
return super<ArrayList>.add(el.toString() + super<Tr>.extra() + el + extra())
}
override fun extra() : String = super<Tr>.extra() + super<Tr>.extra()
}
fun box(): String {
val n = N()
n.add("239")
if (n.get(0) == "239" && n.get(1) == "239_239__") return "OK";
return "fail";
}
@@ -0,0 +1 @@
class Foo() : java.util.ArrayList<Int>()
@@ -0,0 +1,20 @@
import java.util.*
import java.io.*
class World() {
public val items: ArrayList<Item> = ArrayList<Item>
class Item() {
{
items.add(this)
}
}
val foo = Item()
}
fun box() : String {
val w = World()
if (w.items.size() != 1) return "fail"
return "OK"
}
@@ -0,0 +1,19 @@
class Outer(val foo: StringBuilder) {
class Inner() {
fun len() : Int {
return foo.length()
}
}
fun test() : Inner {
return Inner()
}
}
fun box() : String {
val sb = StringBuilder("xyzzy")
val o = Outer(sb)
val i = o.test()
val l = i.len()
return if (l != 5) "fail" else "OK"
}
@@ -0,0 +1,25 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plus(b: ArrayWrapper<T>): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
result.contents.addAll(b.contents)
return result
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
v2.add("bar")
val v3 = v1 + v2
return if (v3.contents.size() == 2) "OK" else "fail"
}
@@ -0,0 +1,26 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plusAssign(rhs: ArrayWrapper<T>) {
contents.addAll(rhs.contents)
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
var v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
v2.add("bar")
v1 += v2
return if (v1.contents.size() == 2) "OK" else "fail"
}
@@ -0,0 +1,30 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plusAssign(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
result.contents.addAll(rhs.contents)
return result
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
var v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
val v3 = v1
v2.add("bar")
v1 += v2
return if (v1.contents.size() == 2 && v3.contents.size() == 1) "OK" else "fail"
}
@@ -0,0 +1,30 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun plus(rhs: ArrayWrapper<T>): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
result.contents.addAll(rhs.contents)
return result
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
var v1 = ArrayWrapper<String>()
val v2 = ArrayWrapper<String>()
v1.add("foo")
val v3 = v1
v2.add("bar")
v1 += v2
return if (v1.contents.size() == 2 && v3.contents.size() == 1) "OK" else "fail"
}
@@ -0,0 +1,28 @@
import java.util.*
class ArrayWrapper<T>() {
val contents = ArrayList<T>()
fun add(item: T) {
contents.add(item)
}
fun minus(): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
Collections.reverse(result.contents)
return result
}
fun get(index: Int): T {
return contents.get(index)
}
}
fun box(): String {
val v1 = ArrayWrapper<String>()
v1.add("foo")
v1.add("bar")
val v2 = -v1
return if (v2[0] == "bar" && v2[1] == "foo") "OK" else "fail"
}
+1
View File
@@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/examples" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />