42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
"""Tests for formula content: correct paths and valid Ruby class name."""
|
|
import re
|
|
|
|
import pytest
|
|
|
|
from tests.conftest import FONT_FILES_DIR, FORMULA_DIR, get_font_dir_names
|
|
|
|
|
|
def formula_name_to_class(formula_name: str) -> str:
|
|
"""Same logic as generator: formula name to PascalCase (no hyphens)."""
|
|
parts = re.split(r"[-_]+", formula_name)
|
|
return "".join(p.capitalize() for p in parts if p)
|
|
|
|
|
|
@pytest.mark.parametrize("font_name", get_font_dir_names())
|
|
def test_formula_references_correct_font_path(font_name):
|
|
"""Generated formula contains the correct font_files/font-<name>/ path."""
|
|
formula_path = FORMULA_DIR / f"{font_name}.rb"
|
|
content = formula_path.read_text()
|
|
# Install block should reference this font path
|
|
assert f"font_files/{font_name}/" in content, (
|
|
f"{font_name}: formula does not reference font_files/{font_name}/"
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("font_name", get_font_dir_names())
|
|
def test_formula_class_name_valid_and_matches(font_name):
|
|
"""Formula defines class Font<PascalCase> with no hyphens (valid Ruby)."""
|
|
formula_path = FORMULA_DIR / f"{font_name}.rb"
|
|
content = formula_path.read_text()
|
|
formula_name = font_name.replace("font-", "", 1)
|
|
expected_class = "Font" + formula_name_to_class(formula_name)
|
|
# Class line: class FontSomething < Formula
|
|
match = re.search(r"class\s+(Font\w+)\s+<\s+Formula", content)
|
|
assert match, f"{font_name}: no 'class Font... < Formula' found"
|
|
actual_class = match.group(1)
|
|
assert "-" not in actual_class, (
|
|
f"{font_name}: Ruby class name must not contain hyphens (got {actual_class})"
|
|
)
|
|
assert actual_class == expected_class, (
|
|
f"{font_name}: expected class {expected_class}, got {actual_class}"
|
|
)
|