Skip to content

test(compiler): achieve 100% test coverage for compiler.py - #51

Merged
sql-hkr merged 1 commit into
mainfrom
test/compiler-coverage-100
Oct 27, 2026
Merged

sql-hkr merged 1 commit into
mainfrom
test/compiler-coverage-100

Conversation

@sql-hkr

@sql-hkr sql-hkr commented Oct 27, 2026

Copy link
Copy Markdown
Owner

What changed

Achieved 100% statement coverage for src/tiny8/compiler.py (321 total test suite passing):

  • Fixed Lexer.TOKEN_SPEC by adding the ~ operator to the OP token pattern so that unary bitwise NOT expressions can be tokenized properly.
  • Added comprehensive unit tests in tests/test_compiler.py:
    • Constant folding across all binary and unary operators, including divide/modulo by zero fallback.
    • Parser consume errors (unexpected EOF and token mismatch) and statement syntax errors.
    • Global variable and array declarations (auto-sizing arrays, local/global missing size errors).
    • For-loop inline variations (omitted init, compound assignment, prefix inc/dec, expression statement).
    • Character literal escape sequences (\n, \t, \0, \\, \') and unknown escape fallback.
    • Runtime code generation for unary operators (-, ~, !), bitwise, and logical operators on variables.
    • Peephole optimization rules 3 and 5.
    • Hardware builtins (vram_clear, in, out) and function calls with > 4 arguments.
    • High RAM addresses (>= 256) requiring R31 high-byte pointer manipulation and VRAM skip boundary (0x0200..0x05FF).
    • compile_c_file and compile_c_file_with_symbols.

How tested

  • uv run pytest --cov=tiny8.compiler --cov-report=term-missing:
    • src/tiny8/compiler.py: 1165/1165 statements, 100% coverage (0 missing lines).
    • 321/321 tests passed.
  • uv run ruff check src/tiny8/compiler.py tests/test_compiler.py: passed.
  • uv run ruff format --check src/tiny8/compiler.py tests/test_compiler.py: passed.

- Add ~ operator to Lexer.TOKEN_SPEC OP pattern to match unary bitwise NOT
- Add unit tests for constant folding across all binary and unary operators
- Add unit tests for parser consume and statement syntax errors
- Add unit tests for global variables and arrays (auto-sizing and syntax errors)
- Add unit tests for for-loop inline variations (omitted init, compound assign, expressions)
- Add unit tests for character literal escape sequences and unknown escape fallback
- Add unit tests for runtime codegen of unary, bitwise, and logical operators
- Add unit tests for peephole optimization rules 3 and 5
- Add unit tests for hardware builtins (vram_clear, in, out, and >4 function call arguments)
- Add unit tests for RAM allocation boundary (VRAM skip) and high RAM addresses (>= 256)
- Add unit tests for compile_c_file and compile_c_file_with_symbols
@sql-hkr
sql-hkr merged commit c1d394b into main Oct 27, 2026
4 checks passed
@sql-hkr
sql-hkr deleted the test/compiler-coverage-100 branch October 27, 2026 16:10
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant