Added first tests, improved BNF and Lexer. Fixed extra space in assignment symbol.

This commit is contained in:
2021-07-15 12:04:05 +02:00
parent 1dc418ae84
commit 2fe70deee2
33 changed files with 982 additions and 464 deletions
@@ -0,0 +1,16 @@
package de.platon42.intellij.plugins.m68k
import org.junit.jupiter.api.DisplayNameGeneration
import org.junit.jupiter.api.DisplayNameGenerator
import java.lang.reflect.Method
@DisplayNameGeneration(AbstractM68kTest.CutOffFixtureDisplayNameGenerator::class)
abstract class AbstractM68kTest {
class CutOffFixtureDisplayNameGenerator : DisplayNameGenerator.ReplaceUnderscores() {
override fun generateDisplayNameForMethod(testClass: Class<*>?, testMethod: Method?): String {
val nameForMethod = super.generateDisplayNameForMethod(testClass, testMethod)
return nameForMethod.substringBefore("$")
}
}
}
@@ -0,0 +1,24 @@
package de.platon42.intellij.plugins.m68k.parser
import de.platon42.intellij.jupiter.MyParser
import de.platon42.intellij.jupiter.ParsingTestExtension
import de.platon42.intellij.jupiter.TestDataPath
import de.platon42.intellij.plugins.m68k.AbstractM68kTest
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(ParsingTestExtension::class)
@TestDataPath("src/test/resources/parser")
@MyParser(value = M68kParserDefinition::class, extension = "asm")
abstract class AbstractParsingTest : AbstractM68kTest() {
fun testGoodSyntax(testCase: ParsingTestExtension.IParsingTestCase, code: String) {
testCase.doCodeTest(code)
testCase.ensureCorrectReparse()
testCase.ensureNoErrorElements()
}
fun testBadSyntax(testCase: ParsingTestExtension.IParsingTestCase, code: String) {
testCase.doCodeTest(code)
testCase.ensureCorrectReparse()
}
}
@@ -0,0 +1,25 @@
package de.platon42.intellij.plugins.m68k.parser
import de.platon42.intellij.jupiter.MyTestCase
import de.platon42.intellij.jupiter.ParserResultFile
import de.platon42.intellij.jupiter.ParsingTestExtension
import de.platon42.intellij.jupiter.TestDataSubPath
import org.junit.jupiter.api.Test
@TestDataSubPath("basic")
internal class BasicAsmInstTest : AbstractParsingTest() {
@Test
@ParserResultFile("basic_block_of_code")
internal fun parser_can_parse_basic_block_of_code(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(
testCase, "\tadd.l d0,d0\n"
+ "\tmoveq #10,d1\n"
+ " rts\n"
+ "\n"
+ "; comment\n"
+ " jmp\tresetcode ; unreachable\n"
+ " \n"
)
}
}
@@ -0,0 +1,50 @@
package de.platon42.intellij.plugins.m68k.parser
import de.platon42.intellij.jupiter.MyTestCase
import de.platon42.intellij.jupiter.ParsingTestExtension
import de.platon42.intellij.jupiter.TestDataSubPath
import org.junit.jupiter.api.Test
@TestDataSubPath("comments")
internal class CommentsTest : AbstractParsingTest() {
@Test
internal fun asterisk_comment_at_sol(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "*********** comment\n")
}
@Test
internal fun asterisk_comment_after_space(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " *********** comment\n")
}
@Test
internal fun hash_comment_at_sol(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "#comment \n")
}
@Test
internal fun hash_comment_after_space(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " #comment \n")
}
@Test
internal fun semicolon_comment_at_sol(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "; comment \n")
}
@Test
internal fun semicolon_comment_after_space(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " ; comment \n")
}
@Test
internal fun empty_and_blank_lines(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "; hi\n\n\n * foo\n\n\n \n\n # bar\n\n")
}
@Test
internal fun end_of_line_comments(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "foo = 1234; hi\n\n\nlabel; foo\n\n\n add.w d0,d0;narf \n\n")
}
}
@@ -0,0 +1,87 @@
package de.platon42.intellij.plugins.m68k.parser
import de.platon42.intellij.jupiter.MyTestCase
import de.platon42.intellij.jupiter.ParsingTestExtension
import de.platon42.intellij.jupiter.TestDataSubPath
import org.junit.jupiter.api.Test
@TestDataSubPath("labels")
internal class LabelsTest : AbstractParsingTest() {
@Test
internal fun plain_global_label(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "Global_Label\n")
}
@Test
internal fun global_label_with_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "Global_Label:\n")
}
@Test
internal fun external_label_with_double_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "External_Label::\n")
}
@Test
internal fun indented_global_label_with_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " Global_Label:\n")
}
@Test
internal fun indented_external_label_with_double_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " External_Label::\n")
}
@Test
internal fun plain_dot_local_label(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, ".local_label\n")
}
@Test
internal fun dot_local_label_with_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, ".local_label:\n")
}
@Test
internal fun indented_dot_local_label_with_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "\t.local_label:\n")
}
@Test
internal fun plain_local_label_dollar(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "local_label$\n")
}
@Test
internal fun local_label_dollar_with_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, "local_label$:\n")
}
@Test
internal fun indented_local_label_dollar_with_colon(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " local_label$:\n")
}
@Test
internal fun bad_indented_dot_local_label_without_label(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testBadSyntax(testCase, " .local_label\n")
}
@Test
internal fun bad_indented_local_label_dollar_without_label(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testBadSyntax(testCase, " local_label$\n")
}
@Test
internal fun complex_label_test(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(
testCase, "start_demo: ; here we will do some cool stuff\n"
+ ".outerloop moveq.l #17-1,d7 ; this is the outer loop\n"
+ "innerloop$ move.l (a0)+,(a1)+ ; copy stuff\n"
+ " dbne d7,innerloop$ ; copy more\n"
+ " .skip: bne.s .outerloop ; end of chunk?\n"
+ " GlobalExit:: rts\n"
)
}
}