Added M68kGlobalLabelSymbolCompletionContributor to replace variants returned by M68kGlobalLabelSymbolReference, to have more control over resolution. Contributor also adds registers to code completion. Code tidying.
This commit is contained in:
+86
@@ -0,0 +1,86 @@
|
||||
package de.platon42.intellij.plugins.m68k.refs
|
||||
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||
import de.platon42.intellij.jupiter.LightCodeInsightExtension
|
||||
import de.platon42.intellij.jupiter.MyFixture
|
||||
import de.platon42.intellij.jupiter.TestDataPath
|
||||
import de.platon42.intellij.jupiter.TestDataSubPath
|
||||
import de.platon42.intellij.plugins.m68k.AbstractM68kTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@TestDataPath("src/test/resources/references")
|
||||
@TestDataSubPath("completion")
|
||||
@ExtendWith(LightCodeInsightExtension::class)
|
||||
internal class M68kGlobalLabelSymbolCompletionContributorTest : AbstractM68kTest() {
|
||||
|
||||
@Test
|
||||
internal fun completion_shows_fitting_symbols_and_labels_after_first_letter(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByText(
|
||||
"completeme.asm", """
|
||||
PIC_WIDTH = 100
|
||||
PIC_HEIGHT = 100
|
||||
platon = 42
|
||||
HURZ = 220
|
||||
NP equ 10
|
||||
|
||||
Irrelevant_Label:
|
||||
Problem_solver:
|
||||
move.l P<caret>
|
||||
"""
|
||||
)
|
||||
myFixture.completeBasic()
|
||||
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder("PIC_HEIGHT", "PIC_WIDTH", "Problem_solver", "NP")
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun completion_shows_all_symbols_and_labels_inside_expr(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByText(
|
||||
"completeme.asm", """
|
||||
PIC_WIDTH = 100
|
||||
HURZ = 220
|
||||
NP equ 10
|
||||
|
||||
Problem_solver:
|
||||
move.l 145+<caret>
|
||||
"""
|
||||
)
|
||||
myFixture.completeBasic()
|
||||
assertThat(myFixture.lookupElementStrings).containsExactlyInAnyOrder(
|
||||
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
|
||||
"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
|
||||
"pc",
|
||||
"HURZ", "NP", "PIC_WIDTH", "Problem_solver"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun completion_puts_register_on_top(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByText(
|
||||
"completeme.asm", """
|
||||
PIC_WIDTH = 320
|
||||
PIC_HEIGHT equ 256
|
||||
DEBUG_LEVEL set 10
|
||||
double_buffer_1 = 1
|
||||
auto_complete_2 = 1
|
||||
|
||||
entry:
|
||||
bsr init
|
||||
bsr main
|
||||
bsr exit
|
||||
move.l d1<caret>
|
||||
rts
|
||||
"""
|
||||
)
|
||||
myFixture.completeBasic()
|
||||
assertThat(myFixture.lookupElementStrings).containsExactly("d1", "double_buffer_1")
|
||||
}
|
||||
|
||||
@Test
|
||||
internal fun complete_several_basic_symbols_or_labels(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByFile("basic_completion.asm")
|
||||
myFixture.completeBasicAllCarets(null)
|
||||
myFixture.checkResultByFile("basic_completion_after_op.asm")
|
||||
}
|
||||
}
|
||||
+6
-7
@@ -17,11 +17,11 @@ import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@TestDataPath("src/test/resources/references")
|
||||
@TestDataSubPath("labels")
|
||||
@ExtendWith(LightCodeInsightExtension::class)
|
||||
internal class M68kReferenceContributorTest : AbstractM68kTest() {
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("labels")
|
||||
internal fun reference_to_dot_local_label_can_be_renamed(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
myFixture.configureByFile("dot_local_label.asm")
|
||||
assertThat(myFixture.elementAtCaret).isInstanceOf(M68kLocalLabel::class.java)
|
||||
@@ -31,6 +31,7 @@ internal class M68kReferenceContributorTest : AbstractM68kTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("labels")
|
||||
internal fun reference_to_multiple_conditional_local_label_dollar_and_variants(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
val reference = myFixture.getReferenceAtCaretPositionWithAssertion("multiple_conditional_local_label_dollar.asm")
|
||||
assertThat(reference.element).isInstanceOf(M68kSymbolReference::class.java)
|
||||
@@ -40,6 +41,7 @@ internal class M68kReferenceContributorTest : AbstractM68kTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("labels")
|
||||
internal fun reference_to_global_label_can_be_renamed(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
val file = myFixture.configureByFile("global_labels.asm")
|
||||
assertThat(myFixture.elementAtCaret).isInstanceOf(M68kGlobalLabel::class.java)
|
||||
@@ -47,9 +49,7 @@ internal class M68kReferenceContributorTest : AbstractM68kTest() {
|
||||
|
||||
val reference = file.findReferenceAt(myFixture.editor.caretModel.offset - 1)!!
|
||||
assertThat(reference).isInstanceOf(M68kGlobalLabelSymbolReference::class.java)
|
||||
assertThat(reference.variants).hasOnlyElementsOfType(LookupElementBuilder::class.java)
|
||||
.extracting<String> { (it as LookupElementBuilder).lookupString }
|
||||
.containsExactlyInAnyOrder("main", "init", "exit")
|
||||
assertThat(reference.variants).isEmpty()
|
||||
|
||||
myFixture.renameElementAtCaret("intro_main")
|
||||
|
||||
@@ -57,6 +57,7 @@ internal class M68kReferenceContributorTest : AbstractM68kTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestDataSubPath("symbols")
|
||||
internal fun reference_to_symbol_can_be_renamed(@MyFixture myFixture: CodeInsightTestFixture) {
|
||||
val file = myFixture.configureByFile("symbol_assignment.asm")
|
||||
assertThat(myFixture.elementAtCaret).isInstanceOf(M68kSymbolDefinition::class.java)
|
||||
@@ -66,9 +67,7 @@ internal class M68kReferenceContributorTest : AbstractM68kTest() {
|
||||
|
||||
val reference = file.findReferenceAt(myFixture.editor.caretModel.offset)!!
|
||||
assertThat(reference).isInstanceOf(M68kGlobalLabelSymbolReference::class.java)
|
||||
assertThat(reference.variants).hasOnlyElementsOfType(LookupElementBuilder::class.java)
|
||||
.extracting<String> { (it as LookupElementBuilder).lookupString }
|
||||
.containsExactlyInAnyOrder("main", "init", "exit", "PIC_WIDTH", "PIC_HEIGHT")
|
||||
assertThat(reference.variants).isEmpty()
|
||||
|
||||
myFixture.checkResultByFile("symbol_assignment_after_rename.asm")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
PIC_WIDTH = 320
|
||||
PIC_HEIGHT equ 256
|
||||
DEBUG_LEVEL set 10
|
||||
DOUBLE_BUFFER_1 = 1
|
||||
AUTO_COMPLETE_2 = 1
|
||||
dood2 = 1
|
||||
|
||||
entry:
|
||||
bsr init
|
||||
bsr main
|
||||
bsr exit
|
||||
rts
|
||||
|
||||
init
|
||||
move.w #PIC_HEIGHT,d1
|
||||
.looph move.w #PIC_WIDTH,d0
|
||||
.loopw clr.b (a0)+
|
||||
subq.w #1,d0
|
||||
bne.s .loopw
|
||||
subq.w #1,d1
|
||||
bne.s .looph
|
||||
move.w a1,d2<caret>
|
||||
move.w e<caret>
|
||||
move.w ex<caret>
|
||||
move.w PW<caret>
|
||||
move.w A<caret>
|
||||
move.w DEB<caret>
|
||||
move.w A2<caret>
|
||||
move.w D1<caret>
|
||||
rts
|
||||
|
||||
main moveq.l #0,d0
|
||||
rts
|
||||
|
||||
exit illegal
|
||||
rts
|
||||
@@ -0,0 +1,36 @@
|
||||
PIC_WIDTH = 320
|
||||
PIC_HEIGHT equ 256
|
||||
DEBUG_LEVEL set 10
|
||||
DOUBLE_BUFFER_1 = 1
|
||||
AUTO_COMPLETE_2 = 1
|
||||
dood2 = 1
|
||||
|
||||
entry:
|
||||
bsr init
|
||||
bsr main
|
||||
bsr exit
|
||||
rts
|
||||
|
||||
init
|
||||
move.w #PIC_HEIGHT,d1
|
||||
.looph move.w #PIC_WIDTH,d0
|
||||
.loopw clr.b (a0)+
|
||||
subq.w #1,d0
|
||||
bne.s .loopw
|
||||
subq.w #1,d1
|
||||
bne.s .looph
|
||||
move.w a1,d2
|
||||
move.w e
|
||||
move.w exit
|
||||
move.w PIC_WIDTH
|
||||
move.w AUTO_COMPLETE_2
|
||||
move.w DEBUG_LEVEL
|
||||
move.w AUTO_COMPLETE_2
|
||||
move.w DOUBLE_BUFFER_1
|
||||
rts
|
||||
|
||||
main moveq.l #0,d0
|
||||
rts
|
||||
|
||||
exit illegal
|
||||
rts
|
||||
Reference in New Issue
Block a user