Phase 5: add rename and find usages
This commit is contained in:
37
src/test/kotlin/dev/hgh/jai/findusages/JaiFindUsagesTest.kt
Normal file
37
src/test/kotlin/dev/hgh/jai/findusages/JaiFindUsagesTest.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
package dev.hgh.jai.findusages
|
||||
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||
import dev.hgh.jai.psi.JaiDeclName
|
||||
|
||||
class JaiFindUsagesTest : BasePlatformTestCase() {
|
||||
fun testFindUsagesActionFindsProcedureReference() {
|
||||
val usages = myFixture.testFindUsages("Declaration.jai", "Usage.jai")
|
||||
|
||||
assertEquals(1, usages.size)
|
||||
}
|
||||
|
||||
fun testFindsProcedureReferencesFromDeclaration() {
|
||||
val source =
|
||||
myFixture.addFileToProject(
|
||||
"find-usages.jai",
|
||||
"""
|
||||
helper :: () {}
|
||||
first :: () { helper(); }
|
||||
second :: () { helper(); }
|
||||
""".trimIndent(),
|
||||
)
|
||||
val declaration =
|
||||
PsiTreeUtil
|
||||
.findChildrenOfType(source, JaiDeclName::class.java)
|
||||
.single { it.text == "helper" }
|
||||
|
||||
val usages = ReferencesSearch.search(declaration).findAll()
|
||||
|
||||
assertEquals(2, usages.size)
|
||||
assertTrue(usages.all { it.element.text == "helper" })
|
||||
}
|
||||
|
||||
override fun getTestDataPath(): String = "src/test/testData/findusages"
|
||||
}
|
||||
59
src/test/kotlin/dev/hgh/jai/refactoring/JaiRenameTest.kt
Normal file
59
src/test/kotlin/dev/hgh/jai/refactoring/JaiRenameTest.kt
Normal file
@@ -0,0 +1,59 @@
|
||||
package dev.hgh.jai.refactoring
|
||||
|
||||
import com.intellij.psi.PsiNameIdentifierOwner
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||
|
||||
class JaiRenameTest : BasePlatformTestCase() {
|
||||
fun testDeclarationNamesParticipateInRename() {
|
||||
myFixture.configureByText(
|
||||
"rename.jai",
|
||||
"""
|
||||
helper<caret> :: () {}
|
||||
main :: () { helper(); }
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
val declaration = myFixture.elementAtCaret
|
||||
|
||||
assertTrue("declaration name should be a named PSI element", declaration is PsiNameIdentifierOwner)
|
||||
assertEquals("helper", (declaration as PsiNameIdentifierOwner).name)
|
||||
}
|
||||
|
||||
fun testRenameProcedureUpdatesSameFileReferences() {
|
||||
myFixture.configureByText(
|
||||
"rename.jai",
|
||||
"""
|
||||
helper<caret> :: () {}
|
||||
main :: () { helper(); }
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
myFixture.renameElementAtCaret("renamed")
|
||||
|
||||
myFixture.checkResult(
|
||||
"""
|
||||
renamed :: () {}
|
||||
main :: () { renamed(); }
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
|
||||
fun testRenameTypeUpdatesTypeReferences() {
|
||||
myFixture.configureByText(
|
||||
"rename-type.jai",
|
||||
"""
|
||||
Point<caret> :: struct { x: int; }
|
||||
use_point :: (point: Point) -> int { return point.x; }
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
myFixture.renameElementAtCaret("Coordinate")
|
||||
|
||||
myFixture.checkResult(
|
||||
"""
|
||||
Coordinate :: struct { x: int; }
|
||||
use_point :: (point: Coordinate) -> int { return point.x; }
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user