Parser: Support multiple components in one file, change args to params with defaults

This commit is contained in:
Aaron Sinclair committed 2025-11-15 03:25:13 -08:00
1 parent 635d466874
commit 81d51d5617
38 files changed
+2151 -455

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
"""Tests for match/case statement parsing."""
import pytest
from ritz.parser import parse_component
def test_match_statement():
"""Test parsing match statement."""
source = """
from ritz.syntax import *
@component
def Tabs():
tab = signal(0)
match tab:
case 0:
with P():
yield "First"
case 1:
with P():
yield "Second"
"""
ir = parse_component(source)
# Find the match statement
match_stmt = None
for stmt in ir["body"]:
if stmt["type"] == "match":
match_stmt = stmt
break
assert match_stmt is not None
assert match_stmt["subject"]["type"] == "name"
assert match_stmt["subject"]["id"] == "tab"
assert len(match_stmt["cases"]) == 2
def test_match_with_wildcard():
"""Test match with wildcard case."""
source = """
from ritz.syntax import *
@component
def Tabs():
tab = signal(0)
match tab:
case 0:
with P():
yield "Home"
case _:
with P():
yield "Other"
"""
ir = parse_component(source)
# Find the match statement
match_stmt = None
for stmt in ir["body"]:
if stmt["type"] == "match":
match_stmt = stmt
break
assert match_stmt is not None
assert len(match_stmt["cases"]) == 2
# Wildcard should be the last case
assert match_stmt["cases"][1]["pattern"]["type"] == "wildcard"