Adafruit_CircuitPython_PIOASM/tests/test_label.py
Jeff Epler b746aec729 Add public_labels, test of labels
Now, a label declared with `public foo:` will be exported in the
`public_labels` property of `Program` objects.

Additionally, a test of this feature as well as the existing
duplicate label detection feature is added.

Change the return type of `assemble` so that it better reflects reality

Add docstrings for the public properties of Program objects
2024-09-19 22:13:14 -05:00

63 lines
1.4 KiB
Python

# SPDX-FileCopyrightText: 2024 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Tests out
"""
from pytest_helpers import assert_assembly_fails
import adafruit_pioasm
def test_label() -> None:
source = [
" jmp label1",
"label1:",
" jmp label2",
"public label2:",
" nop",
]
program = adafruit_pioasm.Program("\n".join(source))
assert program.public_labels == {"label2": 2}
# Test each combination of public/privagte label duplication
source = [
"label1:\n",
"nop\n",
"public label1:\n",
"nop\n",
]
assert_assembly_fails(
"\n".join(source), match="Duplicate label", errtype=SyntaxError
)
source = [
"label1:\n",
" nop\n",
"label1:\n",
" nop\n",
]
assert_assembly_fails(
"\n".join(source), match="Duplicate label", errtype=SyntaxError
)
source = [
"public label1:\n",
" nop\n",
"label1:\n",
" nop\n",
]
assert_assembly_fails(
"\n".join(source), match="Duplicate label", errtype=SyntaxError
)
source = [
"public label1:\n",
" nop\n",
"public label1:\n",
" nop\n",
]
assert_assembly_fails(
"\n".join(source), match="Duplicate label", errtype=SyntaxError
)