blacken sources
This commit is contained in:
20
test/cases/format.yaml
Normal file
20
test/cases/format.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: two_nop
|
||||
program: |
|
||||
NOP
|
||||
NOP
|
||||
expected:
|
||||
- 0x00
|
||||
- 0x00
|
||||
---
|
||||
name: unused_labels
|
||||
program: |
|
||||
start:
|
||||
NOP
|
||||
middle:
|
||||
NOP
|
||||
end:
|
||||
expected:
|
||||
- 0x00
|
||||
- 0x00
|
||||
---
|
||||
19
test/cases/format/format.yaml
Normal file
19
test/cases/format/format.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: two_nop
|
||||
program: |
|
||||
NOP
|
||||
NOP
|
||||
expected:
|
||||
- 0x00
|
||||
- 0x00
|
||||
---
|
||||
name: unused_labels
|
||||
program: |
|
||||
start:
|
||||
NOP
|
||||
middle:
|
||||
NOP
|
||||
end:
|
||||
expected:
|
||||
- 0x00
|
||||
- 0x00
|
||||
74
test/cases/instructions/dec.yaml
Normal file
74
test/cases/instructions/dec.yaml
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
name: dec_a
|
||||
program: |
|
||||
DEC A
|
||||
expected:
|
||||
- 0x3D
|
||||
|
||||
---
|
||||
name: dec_b
|
||||
program: |
|
||||
DEC B
|
||||
expected:
|
||||
- 0x05
|
||||
---
|
||||
name: dec_c
|
||||
program: |
|
||||
DEC C
|
||||
expected:
|
||||
- 0x0D
|
||||
---
|
||||
name: dec_d
|
||||
program: |
|
||||
DEC D
|
||||
expected:
|
||||
- 0x15
|
||||
---
|
||||
name: dec_e
|
||||
program: |
|
||||
DEC E
|
||||
expected:
|
||||
- 0x1D
|
||||
---
|
||||
name: dec_h
|
||||
program: |
|
||||
DEC H
|
||||
expected:
|
||||
- 0x25
|
||||
---
|
||||
name: dec_l
|
||||
program: |
|
||||
DEC L
|
||||
expected:
|
||||
- 0x2D
|
||||
---
|
||||
name: dec_(hl)
|
||||
program: |
|
||||
DEC (HL)
|
||||
expected:
|
||||
- 0x35
|
||||
|
||||
---
|
||||
name: dec_bc
|
||||
program: |
|
||||
DEC BC
|
||||
expected:
|
||||
- 0x0B
|
||||
---
|
||||
name: dec_de
|
||||
program: |
|
||||
DEC DE
|
||||
expected:
|
||||
- 0x1B
|
||||
---
|
||||
name: dec_hl
|
||||
program: |
|
||||
DEC HL
|
||||
expected:
|
||||
- 0x2B
|
||||
---
|
||||
name: dec_sp
|
||||
program: |
|
||||
DEC SP
|
||||
expected:
|
||||
- 0x3B
|
||||
74
test/cases/instructions/inc.yaml
Normal file
74
test/cases/instructions/inc.yaml
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
name: inc_a
|
||||
program: |
|
||||
INC A
|
||||
expected:
|
||||
- 0x3c
|
||||
|
||||
---
|
||||
name: inc_b
|
||||
program: |
|
||||
INC B
|
||||
expected:
|
||||
- 0x04
|
||||
---
|
||||
name: inc_c
|
||||
program: |
|
||||
INC C
|
||||
expected:
|
||||
- 0x0c
|
||||
---
|
||||
name: inc_d
|
||||
program: |
|
||||
INC D
|
||||
expected:
|
||||
- 0x14
|
||||
---
|
||||
name: inc_e
|
||||
program: |
|
||||
INC E
|
||||
expected:
|
||||
- 0x1c
|
||||
---
|
||||
name: inc_h
|
||||
program: |
|
||||
INC H
|
||||
expected:
|
||||
- 0x24
|
||||
---
|
||||
name: inc_l
|
||||
program: |
|
||||
INC L
|
||||
expected:
|
||||
- 0x2c
|
||||
---
|
||||
name: inc_(hl)
|
||||
program: |
|
||||
INC (HL)
|
||||
expected:
|
||||
- 0x34
|
||||
|
||||
---
|
||||
name: inc_bc
|
||||
program: |
|
||||
INC BC
|
||||
expected:
|
||||
- 0x03
|
||||
---
|
||||
name: inc_de
|
||||
program: |
|
||||
INC DE
|
||||
expected:
|
||||
- 0x13
|
||||
---
|
||||
name: inc_hl
|
||||
program: |
|
||||
INC HL
|
||||
expected:
|
||||
- 0x23
|
||||
---
|
||||
name: inc_sp
|
||||
program: |
|
||||
INC SP
|
||||
expected:
|
||||
- 0x33
|
||||
370
test/cases/instructions/jr.yaml
Normal file
370
test/cases/instructions/jr.yaml
Normal file
@@ -0,0 +1,370 @@
|
||||
---
|
||||
name: jr_bkwd
|
||||
program: |
|
||||
label:
|
||||
JR label
|
||||
expected:
|
||||
- 0x18
|
||||
- 0xFE
|
||||
---
|
||||
name: jr_fwd
|
||||
program: |
|
||||
JR label
|
||||
label:
|
||||
expected:
|
||||
- 0x18
|
||||
- 0x00
|
||||
|
||||
---
|
||||
name: jr_z_bkwd
|
||||
program: |
|
||||
label:
|
||||
JR Z label
|
||||
expected:
|
||||
- 0x28
|
||||
- 0xFE
|
||||
---
|
||||
name: jr_z_fwd
|
||||
program: |
|
||||
JR Z label
|
||||
label:
|
||||
expected:
|
||||
- 0x28
|
||||
- 0x00
|
||||
|
||||
---
|
||||
name: jr_nz_bkwd
|
||||
program: |
|
||||
label:
|
||||
JR NZ label
|
||||
expected:
|
||||
- 0x20
|
||||
- 0xFE
|
||||
---
|
||||
name: jr_nz_fwd
|
||||
program: |
|
||||
JR NZ label
|
||||
label:
|
||||
expected:
|
||||
- 0x20
|
||||
- 0x00
|
||||
|
||||
---
|
||||
name: jr_c_bkwd
|
||||
program: |
|
||||
label:
|
||||
JR C label
|
||||
expected:
|
||||
- 0x38
|
||||
- 0xFE
|
||||
---
|
||||
name: jr_c_fwd
|
||||
program: |
|
||||
JR C label
|
||||
label:
|
||||
expected:
|
||||
- 0x38
|
||||
- 0x00
|
||||
|
||||
---
|
||||
name: jr_nc_bkwd
|
||||
program: |
|
||||
label:
|
||||
JR NC label
|
||||
expected:
|
||||
- 0x30
|
||||
- 0xFE
|
||||
---
|
||||
name: jr_nc_fwd
|
||||
program: |
|
||||
JR NC label
|
||||
label:
|
||||
expected:
|
||||
- 0x30
|
||||
- 0x00
|
||||
|
||||
---
|
||||
# Jump backward by the maximum amount
|
||||
name: jr_far_bkwd
|
||||
program: |
|
||||
far_label:
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
JR far_label
|
||||
expected: [
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x18, 0x80 ]
|
||||
|
||||
---
|
||||
# Jump forward by the maximum amount
|
||||
name: jr_far_fwd
|
||||
program: |
|
||||
JR far_label
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
far_label:
|
||||
expected: [ 0x18, 0x7F,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]
|
||||
81
test/cases/instructions/ld_reg16.yaml
Normal file
81
test/cases/instructions/ld_reg16.yaml
Normal file
@@ -0,0 +1,81 @@
|
||||
---
|
||||
name: ld_bc
|
||||
program: |
|
||||
LD BC 0
|
||||
expected:
|
||||
- 0x01
|
||||
- 0x00
|
||||
- 0x00
|
||||
---
|
||||
name: ld_de
|
||||
program: |
|
||||
LD DE 0
|
||||
expected:
|
||||
- 0x11
|
||||
- 0x00
|
||||
- 0x00
|
||||
---
|
||||
name: ld_hl
|
||||
program: |
|
||||
LD HL 0
|
||||
expected:
|
||||
- 0x21
|
||||
- 0x00
|
||||
- 0x00
|
||||
---
|
||||
name: ld_sp
|
||||
program: |
|
||||
LD SP 0
|
||||
expected:
|
||||
- 0x31
|
||||
- 0x00
|
||||
- 0x00
|
||||
|
||||
---
|
||||
name: ld_16_max
|
||||
program: |
|
||||
LD BC 65535
|
||||
expected:
|
||||
- 0x01
|
||||
- 0xFF
|
||||
- 0xFF
|
||||
---
|
||||
name: ld_16_negative
|
||||
program: |
|
||||
LD BC -1
|
||||
expected:
|
||||
- 0x01
|
||||
- 0xFF
|
||||
- 0xFF
|
||||
---
|
||||
name: ld_16_min
|
||||
program: |
|
||||
LD BC -32768
|
||||
expected:
|
||||
- 0x01
|
||||
- 0x00
|
||||
- 0x80
|
||||
---
|
||||
name: ld_16_00FF
|
||||
program: |
|
||||
LD BC 0x00FF
|
||||
expected:
|
||||
- 0x01
|
||||
- 0xFF
|
||||
- 0x00
|
||||
---
|
||||
name: ld_16_FF00
|
||||
program: |
|
||||
LD BC 0xFF00
|
||||
expected:
|
||||
- 0x01
|
||||
- 0x00
|
||||
- 0xFF
|
||||
---
|
||||
name: ld_16_100
|
||||
program: |
|
||||
LD BC 10
|
||||
expected:
|
||||
- 0x01
|
||||
- 0x0A
|
||||
- 0x00
|
||||
12
test/cases/instructions/special.yaml
Normal file
12
test/cases/instructions/special.yaml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
name: nop
|
||||
program: |
|
||||
NOP
|
||||
expected:
|
||||
- 0x00
|
||||
---
|
||||
name: stop
|
||||
program: |
|
||||
STOP
|
||||
expected:
|
||||
- 0x10
|
||||
66
test/test_assemble.py
Normal file
66
test/test_assemble.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from gbasm.gbasm import assemble
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
import yaml
|
||||
import pytest
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(format="")
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
|
||||
class AssembleCase(object):
|
||||
def __init__(self, name: str, program: str, expected: bytes):
|
||||
self.name = name
|
||||
self.program = program
|
||||
self.expected = expected
|
||||
|
||||
|
||||
def find_case_files(subdir: str):
|
||||
test_root = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
case_root = test_root / "cases" / subdir
|
||||
return case_root.glob("**/*.yaml")
|
||||
|
||||
|
||||
def get_test_cases(subdir: str):
|
||||
cases = []
|
||||
files = find_case_files(subdir)
|
||||
for f in files:
|
||||
index = 0
|
||||
with open(str(f), "r") as yaml_file:
|
||||
test_descs = yaml.safe_load_all(yaml_file)
|
||||
for desc in test_descs:
|
||||
try:
|
||||
case = AssembleCase(
|
||||
desc["name"], desc["program"], bytes(desc["expected"])
|
||||
)
|
||||
except TypeError:
|
||||
logger.exception("Failed to parse yaml: %s", desc)
|
||||
cases.append(case)
|
||||
return cases
|
||||
|
||||
|
||||
instruction_cases = get_test_cases("instructions")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"case", instruction_cases, ids=[case.name for case in instruction_cases]
|
||||
)
|
||||
def test_assemble_instruction(case):
|
||||
lines = case.program.split("\n")
|
||||
assembled = assemble(lines)
|
||||
assert assembled == case.expected
|
||||
|
||||
|
||||
format_cases = get_test_cases("format")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("case", format_cases, ids=[case.name for case in format_cases])
|
||||
def test_format_instruction(case):
|
||||
lines = case.program.split("\n")
|
||||
assembled = assemble(lines)
|
||||
assert assembled == case.expected
|
||||
Reference in New Issue
Block a user