Debian Codegraph @

io/+test/limit_test.ha

raw
1 // SPDX-License-Identifier: MPL-2.0
2 // (c) Hare authors <https://harelang.org>
3
4 use errors;
5
6 @test fn limit() void = {
7 let buf: [15z]u8 = [0...];
8 let source = teststream_open();
9
10 let rlimit = limitreader(&source, 20);
11 match (write(&rlimit, buf)) {
12 case errors::unsupported => void;
13 case =>
14 abort();
15 };
16 match (read(&rlimit, buf)) {
17 case let n: size =>
18 assert(n == 15);
19 case error =>
20 abort();
21 };
22 match (read(&rlimit, buf)) {
23 case let n: size =>
24 assert(n == 5);
25 case error =>
26 abort();
27 };
28 assert(read(&rlimit, buf) is EOF);
29
30 let wlimit = limitwriter(&source, 20);
31 match (read(&wlimit, buf)) {
32 case errors::unsupported => void;
33 case =>
34 abort();
35 };
36 match (write(&wlimit, buf)) {
37 case let n: size =>
38 assert(n == 15);
39 case error =>
40 abort();
41 };
42 match (write(&wlimit, buf)) {
43 case let n: size =>
44 assert(n == 5);
45 case error =>
46 abort();
47 };
48 assert(write(&wlimit, buf) as size == 0z);
49 };