Adapt some tests from codegen for k2js translator.
Tests for default arguments.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2010-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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.test.BasicTest;
|
||||
import org.jetbrains.k2js.test.SingleFileTranslationTest;
|
||||
import org.jetbrains.k2js.translate.context.Namer;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@SuppressWarnings("JUnitTestCaseWithNoTests")
|
||||
public final class AdditionalTest extends SingleFileTranslationTest {
|
||||
|
||||
@NotNull
|
||||
private final String filename;
|
||||
|
||||
@SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
|
||||
public AdditionalTest(@NotNull String filename) {
|
||||
super("additional/");
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest() throws Exception {
|
||||
runFunctionOutputTest(filename, Namer.getRootNamespaceName(), "box", "OK");
|
||||
}
|
||||
|
||||
public static Test suite() throws Exception {
|
||||
return TranslatorTestCaseBuilder
|
||||
.suiteForDirectory(BasicTest.pathToTestFilesRoot() + "additional/cases/", new TranslatorTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String filename) {
|
||||
AdditionalTest examplesTest = new AdditionalTest(filename);
|
||||
examplesTest.setName(filename);
|
||||
return examplesTest;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
open abstract class B() {
|
||||
fun foo(arg: Int = 239 + 1) : Int = arg
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().foo(10) != 10) return "fail"
|
||||
if(C().foo() != 240) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun <T> T.toPrefixedString(prefix: String = "", suffix: String="") = prefix + toString() + suffix
|
||||
|
||||
fun box() : String {
|
||||
if("mama".toPrefixedString(suffix="321", prefix="papa") != "papamama321") return "fail1"
|
||||
if("mama".toPrefixedString(prefix="papa") != "papamama") return "fail2"
|
||||
if("mama".toPrefixedString("papa", "239") != "papamama239") return "fail3"
|
||||
if("mama".toPrefixedString("papa") != "papamama") return "fail4"
|
||||
if("mama".toPrefixedString() != "mama") return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fun reformat(
|
||||
str : String,
|
||||
normalizeCase : Boolean = true,
|
||||
uppercaseFirstLetter : Boolean = true,
|
||||
divideByCamelHumps : Boolean = true,
|
||||
wordSeparator : String = " "
|
||||
) =
|
||||
#(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
|
||||
|
||||
|
||||
fun box() : String {
|
||||
val expected = #(true, true, true, " ")
|
||||
if(reformat("", true, true, true, " ") != expected) return "fail1"
|
||||
if(reformat("", true, true, true) != expected) return "fail2"
|
||||
if(reformat("", true, true) != expected) return "fail3"
|
||||
if(reformat("", true) != expected) return "fail4"
|
||||
if(reformat("") != expected) return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
class C() {
|
||||
fun Any.toMyPrefixedString(prefix: String = "", suffix: String="") : String = prefix + " " + suffix
|
||||
|
||||
fun testReceiver() : String {
|
||||
val res : String = "mama".toMyPrefixedString("111", "222")
|
||||
return res
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().testReceiver() != "111 222") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
trait A {
|
||||
fun bar2(arg: Int = 239) : Int
|
||||
|
||||
fun bar(arg: Int = 240) : Int = bar2(arg/2)
|
||||
}
|
||||
|
||||
open abstract class B() : A {
|
||||
override fun bar2(arg: Int) : Int = arg
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().bar(10) != 5) return "fail"
|
||||
if(C().bar() != 120) return "fail"
|
||||
if(C().bar2() != 239) return "fail"
|
||||
if(C().bar2(10) != 10) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
open abstract class B() {
|
||||
abstract fun foo2(arg: Int = 239) : Int
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
override fun foo2(arg: Int) : Int = arg
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().foo2() != 239) return "fail"
|
||||
if(C().foo2(10) != 10) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user