aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check.py
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-28 05:22:14 +0100
committereunhhu <[email protected]>2026-09-28 05:22:14 +0100
commit25af3db3643c7a4e961b172104ca289f5923e83a (patch)
tree8d431d9dc0e6d0f455fe5d0fb93b726c6a3a134a /tests/check.py
parent0134f492c9fcb4ecf079a9dad93db1f8c70ced79 (diff)
downloadaup-25af3db3643c7a4e961b172104ca289f5923e83a.tar.gz
aup-25af3db3643c7a4e961b172104ca289f5923e83a.zip
Slice a keyed list by its keys
list[low .. high], as a fold's or a for's list, is the items whose keys are from low up to before high (a list keyed by a number), read by key: distinct(l.item for l in lines[o * 16 .. o * 16 + 16] where stock[l.item].quantity < t) reads one order's lines, whatever its test does outside them. It compiles to Pure's sliced folds and walks; an empty for over a slice still computes its keys. Two diagnostics and an app of slices are checked.
Diffstat (limited to 'tests/check.py')
-rw-r--r--tests/check.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/check.py b/tests/check.py
index 9b10f02..06e029b 100644
--- a/tests/check.py
+++ b/tests/check.py
@@ -270,6 +270,9 @@ DIAGNOSTICS = [
(LETS + 'on k.down {\n for r in xs {\n let r = 1\n }\n}\n', '11:9', "'r' is the item this for walks"),
(LETS + 'view v = x\non k.down {\n let x = 1\n}\n', '9:10', "unknown state 'x'"),
(LETS + 'on k.down {\n let let = 1\n}\n', '10:7', "'let' is reserved"),
+ # A slice takes a list keyed by a number.
+ (LETS + 'view v = count(x in xs[0 .. 3])\n', '9:10', "'xs' is not keyed by a number: a slice takes one"),
+ (LETS + 'on k.down {\n for x in xs[0 .. 1] {\n n = 1\n }\n}\n', '10:12', "'xs' is not keyed by a number: a slice takes one"),
]
ACCEPTED = [
@@ -279,6 +282,11 @@ ACCEPTED = [
' for l in lines where l.id >= start && l.id < start + 16 {\n l.done = 1\n }\n}\n'
'view items(order: u32) = distinct(l.item for l in lines where l.id >= order * 16 && l.id < order * 16 + 16)\n'
'view level = distinct(l.item for l in lines where l.qty < 10)\n',
+ # Slices: a fold over the keys of one order whose test may fault, a walk over them, one that does nothing.
+ 'record L {\n id = 0\n item = 0\n qty = 0\n}\nrecord S {\n id = 0\n quantity = 0\n}\nstate lines: list of L by id\n'
+ 'state stock: list of S by id\ninput k = message {\n o: u32\n}\n'
+ 'view level(o: u32, t: number) = distinct(l.item for l in lines[o * 16 .. o * 16 + 16] where stock[l.item].quantity < t)\n'
+ 'on k {\n for l in lines[k.o * 16 .. k.o * 16 + 16] {\n l.qty = 0\n }\n for l in lines[0 .. 1] {\n }\n}\n',
# Lets: a sum in a for, an index let changing an item, a let in a for, one read in a fold, one per branch.
'record Stock {\n item = 0\n left = 0\n price = 0\n}\nrecord Line {\n item = 0\n qty = 1\n}\n'
'state stock: list of Stock by item\nstate revenue = 0\nstate sold = 0\ninput order = message {\n lines: list of Line\n}\n'