feat: added a twist
This commit is contained in:
0
backend/uframe/tests/__init__.py
Normal file
0
backend/uframe/tests/__init__.py
Normal file
212
backend/uframe/tests/test_compile.py
Normal file
212
backend/uframe/tests/test_compile.py
Normal file
@@ -0,0 +1,212 @@
|
||||
"""End-to-end tests for the µFrame compile pipeline."""
|
||||
|
||||
import uframe
|
||||
|
||||
|
||||
def test_empty_source():
|
||||
result = uframe.compile("")
|
||||
assert result.ascii == ""
|
||||
assert result.micron == ""
|
||||
|
||||
|
||||
def test_simple_heading():
|
||||
result = uframe.compile('page "Test" 40\n heading 1 "Hello World"')
|
||||
assert "Hello World" in result.ascii
|
||||
assert "Hello World" in result.micron
|
||||
|
||||
|
||||
def test_box_with_title():
|
||||
source = '''page "Demo" 40
|
||||
box light "Status"
|
||||
text "All systems go"'''
|
||||
result = uframe.compile(source)
|
||||
# ASCII should have box-drawing characters
|
||||
assert "┌" in result.ascii
|
||||
assert "└" in result.ascii
|
||||
assert "Status" in result.ascii
|
||||
assert "All systems go" in result.ascii
|
||||
|
||||
|
||||
def test_box_heavy():
|
||||
source = '''page "Demo" 40
|
||||
box heavy "Alert"
|
||||
text "Warning"'''
|
||||
result = uframe.compile(source)
|
||||
assert "┏" in result.ascii
|
||||
assert "Alert" in result.ascii
|
||||
|
||||
|
||||
def test_box_double():
|
||||
source = '''page "Demo" 40
|
||||
box double "Title"
|
||||
text "Content"'''
|
||||
result = uframe.compile(source)
|
||||
assert "╔" in result.ascii
|
||||
assert "Title" in result.ascii
|
||||
|
||||
|
||||
def test_box_rounded():
|
||||
source = '''page "Demo" 40
|
||||
box rounded "Panel"
|
||||
text "Inside"'''
|
||||
result = uframe.compile(source)
|
||||
assert "╭" in result.ascii
|
||||
assert "Panel" in result.ascii
|
||||
|
||||
|
||||
def test_row_with_columns():
|
||||
source = '''page "Demo" 40
|
||||
row 2
|
||||
col 18
|
||||
text "Left"
|
||||
col 18
|
||||
text "Right"'''
|
||||
result = uframe.compile(source)
|
||||
assert "Left" in result.ascii
|
||||
assert "Right" in result.ascii
|
||||
|
||||
|
||||
def test_label():
|
||||
source = '''page "Demo" 40
|
||||
label "Name" "Alice"'''
|
||||
result = uframe.compile(source)
|
||||
assert "Name:" in result.ascii
|
||||
assert "Alice" in result.ascii
|
||||
|
||||
|
||||
def test_divider():
|
||||
source = '''page "Demo" 40
|
||||
divider heavy'''
|
||||
result = uframe.compile(source)
|
||||
assert "━" in result.ascii
|
||||
|
||||
|
||||
def test_link():
|
||||
source = '''page "Demo" 40
|
||||
link "Home" "/page/index.mu"'''
|
||||
result = uframe.compile(source)
|
||||
assert "Home" in result.ascii
|
||||
# Micron should have link syntax
|
||||
assert "index.mu" in result.micron
|
||||
|
||||
|
||||
def test_list():
|
||||
source = '''page "Demo" 40
|
||||
list bullet
|
||||
item "First"
|
||||
item "Second"'''
|
||||
result = uframe.compile(source)
|
||||
assert "First" in result.ascii
|
||||
assert "Second" in result.ascii
|
||||
|
||||
|
||||
def test_spacer():
|
||||
source = '''page "Demo" 40
|
||||
text "Before"
|
||||
spacer 2
|
||||
text "After"'''
|
||||
result = uframe.compile(source)
|
||||
lines = result.ascii.split("\n")
|
||||
# Should have blank lines between Before and After
|
||||
before_idx = next(i for i, l in enumerate(lines) if "Before" in l)
|
||||
after_idx = next(i for i, l in enumerate(lines) if "After" in l)
|
||||
assert after_idx - before_idx >= 3 # at least 2 blank lines between
|
||||
|
||||
|
||||
def test_nested_boxes():
|
||||
source = '''page "Demo" 40
|
||||
box light "Outer"
|
||||
box heavy "Inner"
|
||||
text "Deep"'''
|
||||
result = uframe.compile(source)
|
||||
assert "Outer" in result.ascii
|
||||
assert "Inner" in result.ascii
|
||||
assert "Deep" in result.ascii
|
||||
|
||||
|
||||
def test_micron_has_style_tags():
|
||||
source = '''page "Demo" 40
|
||||
heading 1 "Title"'''
|
||||
result = uframe.compile(source)
|
||||
# Micron should contain color tags for the heading
|
||||
assert "`F" in result.micron or "Title" in result.micron
|
||||
|
||||
|
||||
def test_gauge():
|
||||
source = '''page "Demo" 40
|
||||
gauge "CPU" 62 100 20 warn=75 crit=90'''
|
||||
result = uframe.compile(source)
|
||||
assert "CPU" in result.ascii
|
||||
assert "█" in result.ascii
|
||||
assert "62%" in result.ascii
|
||||
|
||||
|
||||
def test_comment_ignored():
|
||||
source = '''page "Demo" 40
|
||||
# this is a comment
|
||||
text "Visible"'''
|
||||
result = uframe.compile(source)
|
||||
assert "Visible" in result.ascii
|
||||
assert "comment" not in result.ascii
|
||||
|
||||
|
||||
def test_inline_modifiers():
|
||||
source = '''page "Demo" 40
|
||||
text "Hello @bold{world} today"'''
|
||||
result = uframe.compile(source)
|
||||
assert "Hello" in result.ascii
|
||||
assert "world" in result.ascii
|
||||
# Micron should have bold tags around "world"
|
||||
assert "`!" in result.micron
|
||||
|
||||
|
||||
def test_status():
|
||||
source = '''page "Demo" 40
|
||||
status "Server" online'''
|
||||
result = uframe.compile(source)
|
||||
assert "●" in result.ascii
|
||||
assert "Server" in result.ascii
|
||||
|
||||
|
||||
def test_full_dashboard():
|
||||
"""Integration test: a realistic dashboard layout."""
|
||||
source = '''page "Node Status" 60
|
||||
box double "Relay Alpha-7"
|
||||
align center
|
||||
text "Reticulum Network Node"
|
||||
|
||||
spacer
|
||||
|
||||
heading 1 "Resources"
|
||||
|
||||
gauge "CPU" 62 100 28 warn=75 crit=90
|
||||
gauge "MEM" 84 100 28 warn=80 crit=95
|
||||
|
||||
spacer
|
||||
|
||||
heading 2 "Peers"
|
||||
|
||||
label "Active" "7 / 12"
|
||||
status "East Relay" online
|
||||
status "South Bridge" online
|
||||
status "Node Gamma" degraded
|
||||
|
||||
divider heavy
|
||||
|
||||
link "Home" "/page/index.mu"'''
|
||||
|
||||
result = uframe.compile(source)
|
||||
|
||||
# Verify key elements are present
|
||||
assert "Relay Alpha-7" in result.ascii
|
||||
assert "╔" in result.ascii # double box
|
||||
assert "CPU" in result.ascii
|
||||
assert "MEM" in result.ascii
|
||||
assert "█" in result.ascii # gauge bars
|
||||
assert "●" in result.ascii # status indicators
|
||||
assert "━" in result.ascii # heavy divider
|
||||
assert "Home" in result.ascii
|
||||
|
||||
# Micron should have color tags
|
||||
assert "`F" in result.micron
|
||||
assert result.micron # non-empty
|
||||
Reference in New Issue
Block a user