Added "table" and "tables" in the DSL

This commit is contained in:
2026-02-07 22:48:51 +01:00
parent 08c8c00e28
commit 6160e91665
18 changed files with 717 additions and 54 deletions

View File

@@ -142,6 +142,49 @@ def test_i_can_detect_scope_with_multiple_declarations():
assert scope.column_name == "amount"
def test_i_can_detect_table_scope():
"""Test detection of table scope."""
text = 'table "products":\n style()'
scope = detect_scope(text, current_line=1)
assert scope.scope_type == "table"
assert scope.table_name == "products"
def test_i_can_detect_table_scope_with_spaces():
"""Test detection of table scope with spaces in name."""
text = 'table "financial report":\n format()'
scope = detect_scope(text, current_line=1)
assert scope.scope_type == "table"
assert scope.table_name == "financial report"
def test_i_can_detect_tables_scope():
"""Test detection of global tables scope."""
text = "tables:\n style()"
scope = detect_scope(text, current_line=1)
assert scope.scope_type == "tables"
assert scope.table_name is None
@pytest.mark.parametrize("scope_def,expected_type,expected_attrs", [
('column amount:\n style()', "column", {"column_name": "amount"}),
('row 5:\n style()', "row", {"row_index": 5}),
('cell (amount, 3):\n style()', "cell", {"column_name": "amount", "row_index": 3}),
('table "products":\n style()', "table", {"table_name": "products"}),
('tables:\n style()', "tables", {}),
])
def test_i_can_detect_all_scope_types(scope_def, expected_type, expected_attrs):
"""Test detection of all 5 scope types."""
scope = detect_scope(scope_def, current_line=1)
assert scope.scope_type == expected_type
for attr, value in expected_attrs.items():
assert getattr(scope, attr) == value
# =============================================================================
# Context Detection - Scope Contexts
# =============================================================================
@@ -227,6 +270,42 @@ def test_context_cell_row_after_comma_quoted():
assert context == Context.CELL_ROW
def test_context_table_name_after_table():
"""Test TABLE_NAME context after 'table '."""
text = "table "
cursor = Position(line=0, ch=6)
scope = DetectedScope()
context = detect_context(text, cursor, scope)
assert context == Context.TABLE_NAME
def test_context_tables_scope_after_tables():
"""Test TABLES_SCOPE context after 'tables'."""
text = "tables"
cursor = Position(line=0, ch=6)
scope = DetectedScope()
context = detect_context(text, cursor, scope)
assert context == Context.TABLES_SCOPE
@pytest.mark.parametrize("text,cursor_ch,expected_context", [
("column ", 7, Context.COLUMN_NAME),
("row ", 4, Context.ROW_INDEX),
("cell ", 5, Context.CELL_START),
("table ", 6, Context.TABLE_NAME),
("tables", 6, Context.TABLES_SCOPE),
])
def test_i_can_detect_all_scope_contexts(text, cursor_ch, expected_context):
"""Test detection of all scope-related contexts."""
cursor = Position(line=0, ch=cursor_ch)
scope = DetectedScope()
context = detect_context(text, cursor, scope)
assert context == expected_context
# =============================================================================
# Context Detection - Rule Contexts
# =============================================================================
@@ -553,6 +632,32 @@ def test_suggestions_scope_keyword(provider):
assert "column" in labels
assert "row" in labels
assert "cell" in labels
assert "table" in labels
assert "tables" in labels
def test_suggestions_table_name(provider):
"""Test suggestions for TABLE_NAME context."""
engine = FormattingCompletionEngine(provider, "app.orders")
scope = DetectedScope()
suggestions = engine.get_suggestions(Context.TABLE_NAME, scope, "")
labels = [s.label for s in suggestions]
# Should suggest the current table name in quotes
assert '"app.orders"' in labels
def test_suggestions_tables_scope(provider):
"""Test suggestions for TABLES_SCOPE context."""
engine = FormattingCompletionEngine(provider, "app.orders")
scope = DetectedScope()
suggestions = engine.get_suggestions(Context.TABLES_SCOPE, scope, "")
labels = [s.label for s in suggestions]
# Should suggest colon to complete the scope
assert ":" in labels
def test_suggestions_style_preset(provider):