Added support for extern declarations and enhanced .lyng.d merging
- Implemented `extern` support for functions, classes, objects, enums, and properties in the `MiniAST`. - Updated `MiniAST` to include `isExtern` field for applicable nodes. - Enabled merging of `.lyng.d` declaration files into main `.lyng` scripts. - Adjusted tests to validate `extern` behavior and documentation handling. - Minor fixes to parser logic for improved robustness.
This commit is contained in:
1 parent
44675b976d
commit
fdc044d1e0
8 files changed
+310
-95
No files matched your search
@@ -3043,32 +3043,34 @@ class ScriptTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMapWithNonStringKeys() = runTest {
|
||||
fun testExternDeclarations() = runTest {
|
||||
eval(
|
||||
"""
|
||||
val map = Map( 1 => "one", 2 => "two" )
|
||||
assertEquals( "one", map[1] )
|
||||
assertEquals( "two", map[2] )
|
||||
assertEquals( null, map[3] )
|
||||
map[3] = "three"
|
||||
assertEquals( "three", map[3] )
|
||||
map += (4 => "four")
|
||||
assertEquals( "four", map[4] )
|
||||
extern fun hostFunction(a: Int, b: String): String
|
||||
extern class HostClass(name: String) {
|
||||
fun doSomething(): Int
|
||||
val status: String
|
||||
}
|
||||
extern object HostObject {
|
||||
fun getInstance(): HostClass
|
||||
}
|
||||
extern enum HostEnum {
|
||||
VALUE1, VALUE2
|
||||
}
|
||||
|
||||
// Test toMap()
|
||||
val map2 = [1 => "a", 2 => "b"].toMap()
|
||||
assertEquals("a", map2[1])
|
||||
assertEquals("b", map2[2])
|
||||
|
||||
// Test Map constructor with mixed entries and arrays
|
||||
val map3 = Map( 1 => "a", [2, "b"] )
|
||||
assertEquals("a", map3[1])
|
||||
assertEquals("b", map3[2])
|
||||
|
||||
// Test plus
|
||||
val map4 = map3 + (3 => "c")
|
||||
assertEquals("c", map4[3])
|
||||
assertEquals("a", map4[1])
|
||||
// These should not throw errors during compilation
|
||||
// and should be registered in the scope (though they won't have implementations here)
|
||||
// In this test environment, they might fail at runtime if called, but we just check compilation.
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExternExtension() = runTest {
|
||||
eval(
|
||||
"""
|
||||
extern fun String.pretty(): String
|
||||
// Compiles without error
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user