Intrinsic default objects implementation: tests
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
testDefaultObjectAccess()
|
||||
testInCall()
|
||||
testDoubleConstants()
|
||||
testFloatConstants()
|
||||
testCallInterface()
|
||||
testLocalFun()
|
||||
testTopLevelFun()
|
||||
testVarTopField()
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "Error: \n" + e
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun testDefaultObjectAccess() {
|
||||
val i = Int
|
||||
val d = Double
|
||||
val f = Float
|
||||
val l = Long
|
||||
val sh = Short
|
||||
val b = Byte
|
||||
val st = String
|
||||
val en = Enum
|
||||
}
|
||||
|
||||
fun testInCall() {
|
||||
test(Int)
|
||||
test(Double)
|
||||
test(Float)
|
||||
test(Long)
|
||||
test(Short)
|
||||
test(Byte)
|
||||
test(String)
|
||||
test(Enum)
|
||||
}
|
||||
|
||||
fun testDoubleConstants() {
|
||||
val pi = Double.POSITIVE_INFINITY
|
||||
val ni = Double.NEGATIVE_INFINITY
|
||||
val nan = Double.NaN
|
||||
|
||||
myAssertEquals(pi, Double.POSITIVE_INFINITY)
|
||||
myAssertEquals(ni, Double.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
fun testFloatConstants() {
|
||||
val pi = Float.POSITIVE_INFINITY
|
||||
val ni = Float.NEGATIVE_INFINITY
|
||||
val nan = Float.NaN
|
||||
|
||||
myAssertEquals(pi, Float.POSITIVE_INFINITY)
|
||||
myAssertEquals(ni, Float.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
fun testCallInterface() {
|
||||
fun <T> floatPointConstants(a: FloatingPointConstants<T>) {
|
||||
val pi = a.POSITIVE_INFINITY
|
||||
val ni = a.NEGATIVE_INFINITY
|
||||
val nan = a.NaN
|
||||
|
||||
myAssertEquals(pi, a.POSITIVE_INFINITY)
|
||||
myAssertEquals(ni, a.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
floatPointConstants(Double)
|
||||
floatPointConstants(Float)
|
||||
}
|
||||
|
||||
fun testLocalFun() {
|
||||
fun Int.Default.LocalFun() : String = "LocalFun"
|
||||
myAssertEquals("LocalFun", Int.LocalFun())
|
||||
}
|
||||
|
||||
fun testTopLevelFun() {
|
||||
myAssertEquals("TopFun", Int.TopFun())
|
||||
}
|
||||
|
||||
fun testVarTopField() {
|
||||
myAssertEquals(0, Int.TopField)
|
||||
|
||||
Int.TopField++
|
||||
myAssertEquals(1, Int.TopField)
|
||||
|
||||
Int.TopField += 5
|
||||
myAssertEquals(6, Int.TopField)
|
||||
}
|
||||
|
||||
fun test(a: Any) {}
|
||||
|
||||
var _field: Int = 0
|
||||
var Int.Default.TopField : Int
|
||||
get() = _field
|
||||
set(value) { _field = value };
|
||||
|
||||
fun Int.Default.TopFun() : String = "TopFun"
|
||||
|
||||
fun myAssertEquals<T>(a: T, b: T) {
|
||||
if (a != b) throw Exception("$a != $b")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
|
||||
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
|
||||
|
||||
assertEquals("MIN_VALUE", (Int.Default::MIN_VALUE).name)
|
||||
assertEquals("MAX_VALUE", (Double.Default::MAX_VALUE).name)
|
||||
assertEquals("MIN_VALUE", (Float.Default::MIN_VALUE).name)
|
||||
assertEquals("MAX_VALUE", (Long.Default::MAX_VALUE).name)
|
||||
assertEquals("MIN_VALUE", (Short.Default::MIN_VALUE).name)
|
||||
assertEquals("MAX_VALUE", (Byte.Default::MAX_VALUE).name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
// Objects
|
||||
val i = Int
|
||||
val d = Double
|
||||
val f = Float
|
||||
val l = Long
|
||||
val sh = Short
|
||||
val b = Byte
|
||||
val st = String
|
||||
|
||||
test(Int)
|
||||
test(Double)
|
||||
test(Float)
|
||||
test(Long)
|
||||
test(Short)
|
||||
test(Byte)
|
||||
test(String)
|
||||
|
||||
// Common Double
|
||||
Double.POSITIVE_INFINITY
|
||||
Double.NEGATIVE_INFINITY
|
||||
Double.NaN
|
||||
|
||||
// Common Float
|
||||
Float.POSITIVE_INFINITY
|
||||
Float.NEGATIVE_INFINITY
|
||||
Float.NaN
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "Error: \n" + e
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun test(a: Any) {}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
internal fun box(): kotlin.String
|
||||
internal fun test(/*0*/ a: kotlin.Any): kotlin.Unit
|
||||
@@ -1498,6 +1498,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/classObjects"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("builtInClassObjects.kt")
|
||||
public void testBuiltInClassObjects() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classObjects/builtInClassObjects.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassObjectCannotAccessClassFields.kt")
|
||||
public void testClassObjectCannotAccessClassFields() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/classObjects/ClassObjectCannotAccessClassFields.kt");
|
||||
|
||||
+16
@@ -59,6 +59,7 @@ import java.util.regex.Pattern;
|
||||
BlackBoxCodegenTestGenerated.Labels.class,
|
||||
BlackBoxCodegenTestGenerated.LocalClasses.class,
|
||||
BlackBoxCodegenTestGenerated.MultiDecl.class,
|
||||
BlackBoxCodegenTestGenerated.ObjectIntrinsics.class,
|
||||
BlackBoxCodegenTestGenerated.Objects.class,
|
||||
BlackBoxCodegenTestGenerated.OperatorConventions.class,
|
||||
BlackBoxCodegenTestGenerated.Package.class,
|
||||
@@ -4934,6 +4935,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/objectIntrinsics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ObjectIntrinsics extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInObjectIntrinsics() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/objectIntrinsics"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("objects.kt")
|
||||
public void testObjects() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objectIntrinsics/objects.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/objects")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+6
@@ -1570,6 +1570,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/intrinsics"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("defaultObjectMapping.kt")
|
||||
public void testDefaultObjectMapping() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/intrinsics/defaultObjectMapping.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt5937.kt")
|
||||
public void testKt5937() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/intrinsics/kt5937.kt");
|
||||
|
||||
@@ -118,9 +118,7 @@ import org.jetbrains.kotlin.psi.patternMatching.AbstractJetPsiUnifierTest
|
||||
import org.jetbrains.kotlin.completion.weighers.AbstractBasicCompletionWeigherTest
|
||||
import org.jetbrains.kotlin.completion.weighers.AbstractSmartCompletionWeigherTest
|
||||
import org.jetbrains.kotlin.generators.tests.reservedWords.generateTestDataForReservedWords
|
||||
import org.jetbrains.kotlin.js.test.semantics.AbstractReservedWordTest
|
||||
import org.jetbrains.kotlin.idea.resolve.AbstractReferenceResolveInJavaTest
|
||||
import org.jetbrains.kotlin.js.test.semantics.AbstractBridgeTest
|
||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
|
||||
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractDecompiledTextTest
|
||||
@@ -133,8 +131,6 @@ import org.jetbrains.kotlin.renderer.AbstractDescriptorRendererTest
|
||||
import org.jetbrains.kotlin.types.AbstractJetTypeBindingTest
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.AbstractCodeFragmentCompletionHandlerTest
|
||||
import org.jetbrains.kotlin.idea.coverage.AbstractKotlinCoverageOutputFilesTest
|
||||
import org.jetbrains.kotlin.js.test.semantics.AbstractDynamicTest
|
||||
import org.jetbrains.kotlin.js.test.semantics.AbstractMultiModuleTest
|
||||
import org.jetbrains.kotlin.completion.handlers.AbstractBasicCompletionHandlerTest
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.AbstractClsStubBuilderTest
|
||||
import org.jetbrains.kotlin.codegen.AbstractLineNumberTest
|
||||
@@ -151,6 +147,7 @@ import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBytecodeSha
|
||||
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidXml2KConversionTest
|
||||
import org.jetbrains.kotlin.lang.resolve.android.test.AbstractAndroidBoxTest
|
||||
import org.jetbrains.kotlin.android.AbstractParserResultEqualityTest
|
||||
import org.jetbrains.kotlin.js.test.semantics.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -800,6 +797,10 @@ fun main(args: Array<String>) {
|
||||
testClass(javaClass<AbstractBridgeTest>()) {
|
||||
model("codegen/box/bridges", targetBackend = TargetBackend.JS)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractDefaultObjectTest>()) {
|
||||
model("codegen/box/objectIntrinsics", targetBackend = TargetBackend.JS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.js.test.semantics
|
||||
|
||||
import org.jetbrains.kotlin.js.test.SingleFileTranslationTest
|
||||
|
||||
public abstract class AbstractDefaultObjectTest : SingleFileTranslationTest("objectIntrinsics/")
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.kotlin.js.test.semantics;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.InnerTestClasses;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/codegen/box/objectIntrinsics")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class DefaultObjectTestGenerated extends AbstractDefaultObjectTest {
|
||||
public void testAllFilesPresentInObjectIntrinsics() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/objectIntrinsics"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("objects.kt")
|
||||
public void testObjects() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/objectIntrinsics/objects.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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 test.numbers
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import java.util.*
|
||||
import kotlin.test.*
|
||||
import org.junit.Test as test
|
||||
|
||||
class DefaultObjectsExtensionsTest {
|
||||
test fun intTest() {
|
||||
val i = Int
|
||||
|
||||
assertEquals(java.lang.Integer.MAX_VALUE, Int.MAX_VALUE)
|
||||
assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE)
|
||||
}
|
||||
|
||||
test fun doubleTest() {
|
||||
val d = Double
|
||||
|
||||
assertEquals(java.lang.Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
|
||||
assertEquals(java.lang.Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)
|
||||
assertEquals(java.lang.Double.NaN, Double.NaN)
|
||||
|
||||
assertEquals(java.lang.Double.MAX_VALUE, Double.MAX_VALUE)
|
||||
assertEquals(java.lang.Double.MIN_VALUE, Double.MIN_VALUE)
|
||||
}
|
||||
|
||||
test fun floatTest() {
|
||||
val f = Float
|
||||
|
||||
assertEquals(java.lang.Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
|
||||
assertEquals(java.lang.Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY)
|
||||
assertEquals(java.lang.Float.NaN, Float.NaN)
|
||||
|
||||
assertEquals(java.lang.Float.MAX_VALUE, Float.MAX_VALUE)
|
||||
assertEquals(java.lang.Float.MIN_VALUE, Float.MAX_VALUE)
|
||||
}
|
||||
|
||||
test fun longTest() {
|
||||
val l = Long
|
||||
|
||||
assertEquals(java.lang.Long.MAX_VALUE, Long.MAX_VALUE)
|
||||
assertEquals(java.lang.Long.MIN_VALUE, Long.MIN_VALUE)
|
||||
}
|
||||
|
||||
test fun shortTest() {
|
||||
val s = Short
|
||||
|
||||
assertEquals(java.lang.Short.MAX_VALUE, Short.MAX_VALUE)
|
||||
assertEquals(java.lang.Short.MIN_VALUE, Short.MIN_VALUE)
|
||||
}
|
||||
|
||||
test fun byteTest() {
|
||||
val b = Byte
|
||||
|
||||
assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE)
|
||||
assertEquals(java.lang.Byte.MIN_VALUE, Byte.MIN_VALUE)
|
||||
}
|
||||
|
||||
test fun stringTest() {
|
||||
val s = String
|
||||
|
||||
assertEquals(s, String)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user