Skip to content

Commit

Permalink
Better assert cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
intoinside committed Jun 20, 2023
1 parent 2344f93 commit 9651dac
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 16 deletions.
12 changes: 7 additions & 5 deletions KickAssemblerToDoxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ def replace_body_in_curly_brackets(string_to_elaborate):

def remove_assert(content):
"""Function printing python version."""
# match .assert "macroName(x)", { macroName(1) }, { lda #1 }
content = re.sub(r".assert [\.\|\"\w\(\)\,\s+\{\}\%\#\$\;\[\]]+\}", "", content)
# match .assert "macroName(x)", macroName(1), lda #0
# on single line without curly braces
content = re.sub(r".assert (?:(?!}).)*?(?=\n|$)", r"", content)

# match .assert "macroName(x)", macroName(1), 1
content = re.sub(r"(.assert [^\,]+\,[^\,]+\,[^\n]+)", r"", content)
# match .assert "macroName(x)", { macroName(1) }, { lda #0 }
# on single or multiple line with curly braces
content = re.sub(r".assert [^\}]+\}[^\}]+\}", r"", content)

return content

def remove_assert_error(content):
"""Function printing python version."""
# match .asserterror "macroName(x)", { macroName(1) }
content = re.sub(r"(.asserterror [^\,]+\,[^\}]+\})", r"", content)
content = re.sub(r".asserterror [^\}]+\}", r"", content)

return content

Expand Down
4 changes: 2 additions & 2 deletions coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 132 additions & 9 deletions test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,42 @@

class TestClass(unittest.TestCase):
def testremoveAssert(self):
sourceCode = ".assert \"macroName(x)\", { macroName(1) }, { lda #1 }"
sourceCode = ".assert \"macroName()\", { macroName() }, { lda #1; bpl *+5; jmp $0000 }"
expected = ""
self.assertEqual(remove_assert(sourceCode), expected, "Should be empty")

def testremoveAssertWithoutCurlyBraces(self):
sourceCode = ".assert \"macroName(x)\", macroName(1), 1"
def testremoveAssert2(self):
sourceCode = ".assert \"macroName(x)\", { macroName(1) }, { lda #1; bpl *+5; jmp $0000 }"
expected = ""
self.assertEqual(remove_assert(sourceCode), expected, "Should be empty")

def testremoveAssert3(self):
sourceCode = ".assert \"macroName(x, y)\", { macroName(1, 2) }, { lda #1; bpl *+5; jmp $0000 }"
expected = ""
self.assertEqual(remove_assert(sourceCode), expected, "Should be empty")

def testremoveAssert4(self):
sourceCode = ".assert \"SetSpriteXPosition stores X in SPRITE_X reg\", { SetSpriteXPosition(3, 5) }, {\n lda #$05\n sta $d006\n}"
expected = ""
self.assertEqual(remove_assert(sourceCode), expected, "Should be empty")

def testremoveAssert5(self):
sourceCode = ".assert \"macroName(x, y)\", macroName(1, 2), $0000\n"
expected = "\n"
self.assertEqual(remove_assert(sourceCode), expected, "Should be empty")

def testremoveAssertError(self):
sourceCode = ".asserterror \"macroName(x)\", { macroName(1) }"
sourceCode = ".asserterror \"macroName()\", { macroName() }"
expected = ""
self.assertEqual(remove_assert_error(sourceCode), expected, "Should be empty")

def testremoveAssertError2(self):
sourceCode = ".asserterror \"macroName(10)\", { macroName(10) }"
expected = ""
self.assertEqual(remove_assert_error(sourceCode), expected, "Should be empty")

def testremoveAssertError3(self):
sourceCode = ".asserterror \"macroName(20, 10)\", { macroName(20, 10) }"
expected = ""
self.assertEqual(remove_assert_error(sourceCode), expected, "Should be empty")

Expand All @@ -28,11 +53,6 @@ def testremoveImportDoubleQuote(self):
expected = ""
self.assertEqual(remove_import(sourceCode), expected, "Should be empty")

def testremoveImportDoubleQuote(self):
sourceCode = "#import \"fileToImport.asm\"\n"
expected = ""
self.assertEqual(remove_import(sourceCode), expected, "Should be empty")

def testremoveImportOnce(self):
sourceCode = "#importonce\n"
expected = ""
Expand Down Expand Up @@ -207,6 +227,109 @@ def testFullFile(self):
macro configureMemory(config) ;
/*
Disable NMI by pointing NMI vector to rti
*/
macro disableNMI() ;
"""
self.assertEqual(convert_file(sourceCode), expected, "Should clean everything")

def testFullFileWithoutNamespace(self):
sourceCode = """/*
* c128lib - 8502
*
* References available at
* https://www.cubic.org/~doj/c64/mapping128.pdf
*/
#importonce
.filenamespace c128lib
/*
MOS8502 Registers
*/
.label MOS_8502_DIRECTION = $00
.label MOS_8502_IO = $01
/*
I/O Register bits.
*/
.label CASETTE_MOTOR_OFF = %00100000
.label CASETTE_SWITCH_CLOSED = %00010000
.label CASETTE_DATA = %00001000
.label PLA_CHAREN = %00000100
.label PLA_HIRAM = %00000010
.label PLA_LORAM = %00000001
/*
Possible I/O & PLA configurations.
*/
.label RAM_RAM_RAM = %000
.label RAM_CHAR_RAM = PLA_LORAM
.label RAM_CHAR_KERNAL = PLA_HIRAM
.label BASIC_CHAR_KERNAL = PLA_LORAM | PLA_HIRAM
.label RAM_IO_RAM = PLA_CHAREN | PLA_LORAM
.label RAM_IO_KERNAL = PLA_CHAREN | PLA_HIRAM
.label BASIC_IO_KERNAL = PLA_CHAREN | PLA_LORAM | PLA_HIRAM
.macro configureMemory(config) {
lda Mos8502.MOS_8502_IO
and #%11111000
ora #[config & %00000111]
sta Mos8502.MOS_8502_IO
}
/*
Disable NMI by pointing NMI vector to rti
*/
.macro disableNMI() {
lda #<nmi
sta c128lib.NMI_LO
lda #>nmi
sta c128lib.NMI_HI
jmp end
nmi:
rti
end:
}
"""
expected = """/*
* c128lib - 8502
*
* References available at
* https://www.cubic.org/~doj/c64/mapping128.pdf
*/
/*
MOS8502 Registers
*/
label MOS_8502_DIRECTION = $00;
label MOS_8502_IO = $01;
/*
I/O Register bits.
*/
label CASETTE_MOTOR_OFF = %00100000;
label CASETTE_SWITCH_CLOSED = %00010000;
label CASETTE_DATA = %00001000;
label PLA_CHAREN = %00000100;
label PLA_HIRAM = %00000010;
label PLA_LORAM = %00000001;
/*
Possible I/O & PLA configurations.
*/
label RAM_RAM_RAM = %000;
label RAM_CHAR_RAM = PLA_LORAM;
label RAM_CHAR_KERNAL = PLA_HIRAM;
label BASIC_CHAR_KERNAL = PLA_LORAM | PLA_HIRAM;
label RAM_IO_RAM = PLA_CHAREN | PLA_LORAM;
label RAM_IO_KERNAL = PLA_CHAREN | PLA_HIRAM;
label BASIC_IO_KERNAL = PLA_CHAREN | PLA_LORAM | PLA_HIRAM;
macro configureMemory(config) ;
/*
Disable NMI by pointing NMI vector to rti
*/
Expand Down

0 comments on commit 9651dac

Please sign in to comment.