fixed few bugs in compiler and plugin
This commit is contained in:
1 parent
37d093817e
commit
e447c778ed
10 files changed
+243
-45
No files matched your search
@@ -565,19 +565,6 @@ class TypesTest {
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
// @Test
|
||||
// fun testNullableGenericTypes() = runTest {
|
||||
// eval("""
|
||||
// fun t<T>(): String =
|
||||
// when(T) {
|
||||
// is Object -> "%s is Object"(T::class.name)
|
||||
// else -> throw "It should not happen"
|
||||
// }
|
||||
// assert( Int is Object)
|
||||
// assertEquals( t<Int>(), "Class is Object")
|
||||
// """.trimIndent())
|
||||
// }
|
||||
|
||||
@Test fun testIndexer() = runTest {
|
||||
eval("""
|
||||
class Greeter {
|
||||
@@ -596,6 +583,38 @@ class TypesTest {
|
||||
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@Test fun testIndexer2() = runTest {
|
||||
eval("""
|
||||
class Foo(bar)
|
||||
|
||||
class Greeter {
|
||||
override fun getAt(name): Foo = Foo("Hello, %s!"(name))
|
||||
}
|
||||
assertEquals("Hello, Bob!",Greeter()["Bob"].bar)
|
||||
val g = Greeter()
|
||||
assertEquals("Hello, Bob!",g["Bob"].bar)
|
||||
|
||||
// it should work with objects too:
|
||||
object Polite {
|
||||
override fun getAt(name): Foo? = Foo("How do you do, %s?"(name))
|
||||
}
|
||||
|
||||
assertEquals("How do you do, Bob?",Polite["Bob"].bar)
|
||||
assertEquals("How do you do, Bob?",Polite["Bob"]?.bar)
|
||||
assertEquals("How do you do, Bob?",Polite["Bob"]!!.bar)
|
||||
|
||||
class Greeter2 {
|
||||
override fun getAt(name): Foo? = Foo("How do you do, %s?"(name))
|
||||
}
|
||||
val g2 = Greeter2()
|
||||
assertEquals("How do you do, Bob?",g2["Bob"]?.bar)
|
||||
val g2v: Foo = g2["Bob"]!!
|
||||
assertEquals("How do you do, Bob?",g2v.bar)
|
||||
assertEquals("How do you do, Bob?",Greeter2()["Bob"].bar)
|
||||
|
||||
""".trimIndent())
|
||||
}
|
||||
// @Test fun nonTrivialOperatorsTest() = runTest {
|
||||
// val s = Script.newScope()
|
||||
// s.eval("""
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
package net.sergeych.lyng.tools
|
||||
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.lyng.miniast.MiniClassDecl
|
||||
import net.sergeych.lyng.miniast.MiniMemberTypeAliasDecl
|
||||
import net.sergeych.lyng.Pos
|
||||
import net.sergeych.lyng.Source
|
||||
import net.sergeych.lyng.miniast.*
|
||||
import net.sergeych.lyng.stdlib_included.rootLyng
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
@@ -127,4 +128,48 @@ class LyngLanguageToolsTest {
|
||||
val dis = LyngLanguageTools.disassembleSymbol(code, "add")
|
||||
assertTrue(!dis.contains("not a compiled body"), "Disassembly should be produced, got: $dis")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun languageTools_semanticHighlights_ignore_foreign_sources() {
|
||||
val localSource = Source("local.lyng", "val x = 1")
|
||||
val foreignSource = Source("defs.lyng.d", "val y = 2")
|
||||
val localStart = Pos(localSource, 0, 0)
|
||||
val foreignStart = Pos(foreignSource, 0, 0)
|
||||
|
||||
val mini = MiniScript(
|
||||
range = MiniRange(localStart, localStart),
|
||||
declarations = mutableListOf(
|
||||
MiniValDecl(
|
||||
range = MiniRange(foreignStart, foreignStart),
|
||||
name = "y",
|
||||
mutable = false,
|
||||
type = null,
|
||||
initRange = null,
|
||||
doc = null,
|
||||
nameStart = foreignStart
|
||||
)
|
||||
),
|
||||
imports = mutableListOf(
|
||||
MiniImport(
|
||||
range = MiniRange(foreignStart, foreignStart),
|
||||
segments = listOf(
|
||||
MiniImport.Segment("defs", MiniRange(foreignStart, foreignStart))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
val analysis = LyngAnalysisResult(
|
||||
source = localSource,
|
||||
text = localSource.text,
|
||||
mini = mini,
|
||||
binding = null,
|
||||
resolution = null,
|
||||
importedModules = emptyList(),
|
||||
diagnostics = emptyList(),
|
||||
lexicalHighlights = emptyList()
|
||||
)
|
||||
|
||||
val spans = LyngLanguageTools.semanticHighlights(analysis)
|
||||
assertTrue(spans.isEmpty(), "Semantic spans should ignore positions from foreign sources, got $spans")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user