aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-26 11:30:17 +0100
committereunhhu <[email protected]>2026-09-26 11:30:17 +0100
commitb5cb79948d52fe9dd918a10a446dcf183c35d10d (patch)
tree68120df2b5287c8eec8ca03f1c738a6aac963652 /tests
parentdb28e3401e5a137845fdb1661e1af6297477b0c8 (diff)
downloadaup-b5cb79948d52fe9dd918a10a446dcf183c35d10d.tar.gz
aup-b5cb79948d52fe9dd918a10a446dcf183c35d10d.zip
Filter a table view with where
view open_list = each t in tasks where !t.done { ... } has a row for each item the condition keeps, in the list's order; the condition compiles to the table's filter block, generated like a column so it reads the row's item, and the view entry names the list in the byte after its type. A count, sum, max or min inside the condition is a compile error, as Pure refuses a fold in a filter. The random model check now compares a filtered table too; two diagnostics join.
Diffstat (limited to 'tests')
-rw-r--r--tests/check.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/tests/check.py b/tests/check.py
index ef8549f..3716ff6 100644
--- a/tests/check.py
+++ b/tests/check.py
@@ -176,6 +176,9 @@ DIAGNOSTICS = [
"'n' is a parameter outside this count, sum, max or min"),
(LIST + 'view v = sum(dt for x in xs)\n', '6:14', 'dt is not available in count, sum, max or min'),
(LIST + 'view v = sum(x.a for x xs)\n', '6:24', "expected 'in' and a list, as in sum(x in tasks)"),
+ (LIST + 'view w = each r in xs where r {\n n = r.a\n}\n', '6:29', 'expected a number, not an index'),
+ (LIST + 'view w = each r in xs where count(y in xs) > 0 {\n n = r.a\n}\n', '6:29',
+ "a table's where cannot hold a count, sum, max or min"),
]
ACCEPTED = [
@@ -989,13 +992,18 @@ view done_points = sum(
view longest = max(t.title.chars for t in tasks)
view fewest_open = min(t.points for t in tasks where !t.done)
view summary = "{count(t in tasks where !t.done)} open of {tasks.count}"
+view open_list = each t in tasks where !t.done {
+ label = t.title
+ item = t.position
+}
"""
def folds(aup, pure_run, work, seeds, steps=300):
- """count, sum, max and min over a list against a Python model after
- random adds, toggles, moves and removals (an empty max or min has no
- value)."""
+ """count, sum, max and min over a list, and a table filtered by a where,
+ against a Python model after random adds, toggles, moves and removals (an
+ empty max or min has no value; a filtered table's rows keep the list's
+ order and its columns read the item)."""
source = work / 'folds.aup'
source.write_text(FOLDS_SOURCE)
compile_module(aup, source, work / 'folds.pmod')
@@ -1024,7 +1032,8 @@ def folds(aup, pure_run, work, seeds, steps=300):
'done_points': sum(t['points'] for t in tasks if t['done']),
'longest': max((len(t['title']) for t in tasks), default=None),
'fewest_open': min((t['points'] for t in open_tasks), default=None),
- 'summary': f'{len(open_tasks)} open of {len(tasks)}'})
+ 'summary': f'{len(open_tasks)} open of {len(tasks)}',
+ 'open_list': [{'label': t['title'], 'item': i} for i, t in enumerate(tasks) if not t['done']]})
# Toggling or removing in an empty list fails; pure-run then exits 1 but shows every event.
lines = run(pure_run, work / 'folds.pmod', stdin='\n'.join(commands) + '\n', check=False).stdout.splitlines()
shown = [json.loads(line)['views'] for line in lines]