Update compile-time resolution and tests
This commit is contained in:
1 parent
8f60a84e3b
commit
523b9d338b
46 files changed
+3771
-967
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package net.sergeych.lyng
|
||||
|
||||
import net.sergeych.lyng.obj.ObjArrayIterator
|
||||
import net.sergeych.lyng.obj.ObjIterable
|
||||
import net.sergeych.lyng.obj.ObjIterator
|
||||
import net.sergeych.lyng.obj.ObjList
|
||||
import net.sergeych.lyng.obj.ObjRange
|
||||
import net.sergeych.lyng.obj.ObjRangeIterator
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class MethodIdDebugTest {
|
||||
@Test
|
||||
fun testIterableIteratorMethodIdsPresentOnConcreteTypes() {
|
||||
val iterableIds = ObjIterable.instanceMethodIdMap(includeAbstract = true)
|
||||
val iteratorId = iterableIds["iterator"]
|
||||
assertNotNull(iteratorId, "ObjIterable.iterator methodId missing")
|
||||
val listRec = ObjList.type.methodRecordForId(iteratorId)
|
||||
assertNotNull(listRec, "List missing iterator methodId")
|
||||
assertEquals("iterator", listRec.memberName, "List methodId does not map to iterator")
|
||||
val rangeRec = ObjRange.type.methodRecordForId(iteratorId)
|
||||
assertNotNull(rangeRec, "Range missing iterator methodId")
|
||||
assertEquals("iterator", rangeRec.memberName, "Range methodId does not map to iterator")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIteratorMethodsPresentOnConcreteIterators() {
|
||||
val iteratorIds = ObjIterator.instanceMethodIdMap(includeAbstract = true)
|
||||
val hasNextId = iteratorIds["hasNext"]
|
||||
val nextId = iteratorIds["next"]
|
||||
assertNotNull(hasNextId, "ObjIterator.hasNext methodId missing")
|
||||
assertNotNull(nextId, "ObjIterator.next methodId missing")
|
||||
val arrayHasNext = ObjArrayIterator.type.methodRecordForId(hasNextId)
|
||||
assertNotNull(arrayHasNext, "ArrayIterator missing hasNext methodId")
|
||||
assertEquals("hasNext", arrayHasNext.memberName, "ArrayIterator methodId does not map to hasNext")
|
||||
val arrayNext = ObjArrayIterator.type.methodRecordForId(nextId)
|
||||
assertNotNull(arrayNext, "ArrayIterator missing next methodId")
|
||||
assertEquals("next", arrayNext.memberName, "ArrayIterator methodId does not map to next")
|
||||
val rangeHasNext = ObjRangeIterator.type.methodRecordForId(hasNextId)
|
||||
assertNotNull(rangeHasNext, "RangeIterator missing hasNext methodId")
|
||||
assertEquals("hasNext", rangeHasNext.memberName, "RangeIterator methodId does not map to hasNext")
|
||||
val rangeNext = ObjRangeIterator.type.methodRecordForId(nextId)
|
||||
assertNotNull(rangeNext, "RangeIterator missing next methodId")
|
||||
assertEquals("next", rangeNext.memberName, "RangeIterator methodId does not map to next")
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,8 @@ class ScriptSubsetJvmTest {
|
||||
@Test
|
||||
fun optionalChainingIndexField_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
val a = null
|
||||
class C() { var x = 1 }
|
||||
val a: C? = null
|
||||
val r1 = a?.x
|
||||
val lst = [1,2,3]
|
||||
val r2 = lst[1]
|
||||
|
||||
@@ -37,7 +37,7 @@ class ScriptSubsetJvmTest_Additions3 {
|
||||
@Test
|
||||
fun controlFlow_when_and_ifElse_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
fun classify(x) {
|
||||
fun classify(x: Int) {
|
||||
when(x) {
|
||||
0 -> 100
|
||||
1 -> 200
|
||||
@@ -60,9 +60,9 @@ class ScriptSubsetJvmTest_Additions3 {
|
||||
val code = """
|
||||
class Box() {
|
||||
var xs = [10,20,30]
|
||||
fun get(i) { xs[i] }
|
||||
fun get(i: Int) { xs[i] }
|
||||
}
|
||||
val maybe = null
|
||||
val maybe: Box? = null
|
||||
val b = Box()
|
||||
// optional on null yields null
|
||||
val r1 = maybe?.xs
|
||||
@@ -77,7 +77,7 @@ class ScriptSubsetJvmTest_Additions3 {
|
||||
@Test
|
||||
fun exceptions_try_catch_finally_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
fun risky(x) { if (x == 0) throw "boom" else 7 }
|
||||
fun risky(x: Int) { if (x == 0) throw "boom" else 7 }
|
||||
var s = 0
|
||||
try { s = risky(0) } catch (e) { s = 1 } finally { s = s + 2 }
|
||||
s
|
||||
@@ -95,7 +95,7 @@ class ScriptSubsetJvmTest_Additions3 {
|
||||
private var hidden = 9
|
||||
fun getPub() { pub }
|
||||
fun getHidden() { hidden }
|
||||
fun setPub(v) { pub = v }
|
||||
fun setPub(v: Int) { pub = v }
|
||||
}
|
||||
val c = C()
|
||||
c.setPub(5)
|
||||
@@ -109,7 +109,7 @@ class ScriptSubsetJvmTest_Additions3 {
|
||||
@Test
|
||||
fun collections_insert_remove_and_maps_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
val lst = []
|
||||
val lst: List<Int> = []
|
||||
lst.insertAt(0, 2)
|
||||
lst.insertAt(0, 1)
|
||||
lst.removeAt(1)
|
||||
@@ -144,8 +144,8 @@ class ScriptSubsetJvmTest_Additions3 {
|
||||
try {
|
||||
PerfFlags.SCOPE_POOL = true
|
||||
val code = """
|
||||
fun outer(a) {
|
||||
fun inner(b) { if (b == 0) throw "err" else a + b }
|
||||
fun outer(a: Int) {
|
||||
fun inner(b: Int) { if (b == 0) throw "err" else a + b }
|
||||
try { inner(0) } catch (e) { a + 2 }
|
||||
}
|
||||
outer(5)
|
||||
|
||||
@@ -51,7 +51,8 @@ class ScriptSubsetJvmTest_Additions4 {
|
||||
@Test
|
||||
fun optionalChainingDeep_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
class A() { fun b() { null } }
|
||||
class B() { val c = 7 }
|
||||
class A() { fun b(): B? { null } }
|
||||
val a = A()
|
||||
val r1 = a?.b()?.c
|
||||
val r2 = (a?.b()?.c ?: 7)
|
||||
@@ -64,7 +65,7 @@ class ScriptSubsetJvmTest_Additions4 {
|
||||
@Test
|
||||
fun whenExpressionBasics_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
fun f(x) {
|
||||
fun f(x: Int) {
|
||||
when(x) {
|
||||
0 -> 100
|
||||
1 -> 200
|
||||
@@ -80,7 +81,7 @@ class ScriptSubsetJvmTest_Additions4 {
|
||||
@Test
|
||||
fun tryCatchFinallyWithReturn_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
fun g(x) {
|
||||
fun g(x: Int) {
|
||||
var t = 0
|
||||
try {
|
||||
if (x < 0) throw("oops")
|
||||
@@ -102,7 +103,7 @@ class ScriptSubsetJvmTest_Additions4 {
|
||||
@Test
|
||||
fun pooling_edge_case_closure_and_exception_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
fun maker(base) { { base + 1 } }
|
||||
fun maker(base: Int) { { base + 1 } }
|
||||
val c = maker(41)
|
||||
var r = 0
|
||||
try {
|
||||
|
||||
@@ -81,7 +81,7 @@ class ScriptSubsetJvmTest_Additions5 {
|
||||
fun pooled_frames_closure_this_capture_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
class Box() { var x = 40; fun inc() { x = x + 1 } fun get() { x } }
|
||||
fun make(block) { block }
|
||||
fun make(block: () -> Int) { block }
|
||||
val b = Box()
|
||||
val f = make { b.inc(); b.get() }
|
||||
var r = 0
|
||||
|
||||
@@ -65,7 +65,7 @@ class ScriptSubsetJvmTest_Additions {
|
||||
fun elvisAndLogicalChains_jvm_only() = runBlocking {
|
||||
val n = 10000
|
||||
val code = """
|
||||
val maybe = null
|
||||
val maybe: Int? = null
|
||||
var s = 0
|
||||
var i = 0
|
||||
while (i < $n) {
|
||||
@@ -92,7 +92,7 @@ class ScriptSubsetJvmTest_Additions {
|
||||
fun sortedInsertWithBinarySearch_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
val src = [3,1,2]
|
||||
val result = []
|
||||
val result: List<Int> = []
|
||||
for (x in src) {
|
||||
val i = result.binarySearch(x)
|
||||
result.insertAt(if (i < 0) -i-1 else i, x)
|
||||
@@ -113,7 +113,7 @@ class ScriptSubsetJvmTest_Additions2 {
|
||||
fun optionalMethodCallWithElvis_jvm_only() = runBlocking {
|
||||
val code = """
|
||||
class C() { fun get() { 5 } }
|
||||
val a = null
|
||||
val a: C? = null
|
||||
(a?.get() ?: 7)
|
||||
""".trimIndent()
|
||||
val r = evalInt(code)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.lyng.Script
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertNotNull
|
||||
|
||||
class StdlibWrapperTest {
|
||||
@Test
|
||||
fun testStdlibExtensionWrapperPresent() = runTest {
|
||||
val scope = Script.newScope()
|
||||
val rec = scope.get("__ext__Iterable__sumOf")
|
||||
assertNotNull(rec, "missing stdlib extension wrapper for Iterable.sumOf")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user