src/ez/gate.bend
ezx@1.9.0.0 · 27 lines · 0 definitions
1# ez/gate: what a test file says its run must print. A test states that in a
2# `#|` trailer, one line for each line of output, and `ez test` holds the run
3# to it.
4#
5# This file imports nothing but Base, so a law about the trailer walk costs a
6# compile of that and no more.
7import Base
8
9# a trailer line kept, with its `#|` dropped, or a source line ignored
10def want.put(is_want: Bool, line: String, rest: List<&2, String>) -> List<&2, String>:
11 match is_want:
12 case True{}:
13 String.drop(line, 2n) <> rest
14 case False{}:
15 rest
16
17# the `#|` lines of a source file, in order
18def want(ls: List<&2, String>) -> List<&2, String>:
19 match ls:
20 case []:
21 []
22 case +h <> t:
23 want.put(String.starts_with(h, "#|"), h, want(t))
24
25# what a test file says its run must print
26def trailer(text: String) -> String:
27 String.join(want(String.lines(text)), "\n")