103 lines
3.0 KiB
Python
103 lines
3.0 KiB
Python
"""Tests for BigTitle and font rendering."""
|
|
|
|
import uframe
|
|
from uframe.fonts import render_big_text, get_text_width, FONTS, FONT_HEIGHTS
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Unit tests for font module
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_font_registry():
|
|
assert "block" in FONTS
|
|
assert "thin" in FONTS
|
|
assert "pixel" in FONTS
|
|
|
|
|
|
def test_font_heights():
|
|
assert FONT_HEIGHTS["block"] == 6
|
|
assert FONT_HEIGHTS["thin"] == 3
|
|
assert FONT_HEIGHTS["pixel"] == 3
|
|
|
|
|
|
def test_render_big_text_block():
|
|
lines = render_big_text("HI", "block")
|
|
assert len(lines) == 6
|
|
# Should contain block characters
|
|
assert any("█" in line for line in lines)
|
|
|
|
|
|
def test_render_big_text_thin():
|
|
lines = render_big_text("AB", "thin")
|
|
assert len(lines) == 3
|
|
assert any("┌" in line or "├" in line for line in lines)
|
|
|
|
|
|
def test_render_big_text_pixel():
|
|
lines = render_big_text("OK", "pixel")
|
|
assert len(lines) == 3
|
|
assert any("▀" in line or "█" in line for line in lines)
|
|
|
|
|
|
def test_get_text_width():
|
|
w = get_text_width("A", "block")
|
|
assert w > 0
|
|
w2 = get_text_width("AB", "block")
|
|
assert w2 > w # two chars wider than one
|
|
|
|
|
|
def test_kerning():
|
|
w_tight = get_text_width("AB", "block", kerning=0)
|
|
w_normal = get_text_width("AB", "block", kerning=1)
|
|
w_wide = get_text_width("AB", "block", kerning=2)
|
|
assert w_tight < w_normal < w_wide
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Integration tests — bigtitle through compile pipeline
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_bigtitle_block_font():
|
|
source = '''page "Test" 80
|
|
bigtitle "HI" block'''
|
|
result = uframe.compile(source)
|
|
assert "█" in result.ascii
|
|
lines = result.ascii.strip().split("\n")
|
|
assert len(lines) >= 6 # block font is 6 lines tall
|
|
|
|
|
|
def test_bigtitle_thin_font():
|
|
source = '''page "Test" 80
|
|
bigtitle "OK" thin'''
|
|
result = uframe.compile(source)
|
|
# Thin font uses box-drawing characters
|
|
assert any(c in result.ascii for c in "┌├┐┘└┬")
|
|
|
|
|
|
def test_bigtitle_pixel_font():
|
|
source = '''page "Test" 80
|
|
bigtitle "GO" pixel'''
|
|
result = uframe.compile(source)
|
|
assert any(c in result.ascii for c in "▀▄█")
|
|
|
|
|
|
def test_bigtitle_fallback_to_smaller_font():
|
|
"""When text is too wide for block font, should fall back to smaller fonts."""
|
|
source = '''page "Test" 40
|
|
bigtitle "ABCDEFGHIJ" block'''
|
|
result = uframe.compile(source)
|
|
# Should still render with a fallback font (thin uses box-drawing)
|
|
assert result.ascii.strip() != ""
|
|
# Thin font characters should be present (fell back from block)
|
|
assert any(c in result.ascii for c in "┌├┐┘└┬─")
|
|
|
|
|
|
def test_bigtitle_with_alignment():
|
|
source = '''page "Test" 80
|
|
bigtitle "HI" block
|
|
align center'''
|
|
result = uframe.compile(source)
|
|
assert "█" in result.ascii
|