https://github.com/akkartik/mu/blob/master/404stream.mu
 1 # Tests for Mu's stream primitives.
 2 
 3 fn test-stream {
 4   # - write an int to a stream, then read it back
 5   # step 1: initialize
 6   var s: (stream int 4)
 7   var s2/ecx: (addr stream int) <- address s
 8   var tmp/eax: boolean <- stream-empty? s2
 9   check-true tmp, "F - test-stream/empty?/0"
10   tmp <- stream-full? s2
11   check-false tmp, "F - test-stream/full?/0"
12   # step 2: write to stream
13   var x: int
14   copy-to x, 0x34
15   var x2/edx: (addr int) <- address x
16   write-to-stream s2, x2
17   tmp <- stream-empty? s2
18   check-false tmp, "F - test-stream/empty?/1"
19   tmp <- stream-full? s2
20   check-false tmp, "F - test-stream/full?/1"
21   # step 3: modify the value written (should make no difference)
22   copy-to x, 0
23   # step 4: read back
24   var y: int
25   var y2/ebx: (addr int) <- address y
26   read-from-stream s2, y2
27   tmp <- stream-empty? s2
28   check-true tmp, "F - test-stream/empty?/2"
29   tmp <- stream-full? s2
30   check-false tmp, "F - test-stream/full?/2"
31   # we read back what was written
32   check-ints-equal y, 0x34, "F - test-stream"
33 }
34 
35 fn test-stream-full {
36   # write an int to a stream of capacity 1
37   var s: (stream int 1)
38   var s2/ecx: (addr stream int) <- address s
39   var tmp/eax: boolean <- stream-full? s2
40   check-false tmp, "F - test-stream-full?/pre"
41   var x: int
42   var x2/edx: (addr int) <- address x
43   write-to-stream s2, x2
44   tmp <- stream-full? s2
45   check-true tmp, "F - test-stream-full?"
46 }