hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

limit.ha (1020B)


      1 // License: MPL-2.0
      2 // (c) 2021-2022 Bor Grošelj Simić <bor.groseljsimic@telemach.net>
      3 // (c) 2021-2022 Drew DeVault <sir@cmpwn.com>
      4 // (c) 2021 Ember Sawady <ecs@d2evs.net>
      5 use errors;
      6 
      7 @test fn limit() void = {
      8 	let buf: [15z]u8 = [0...];
      9 	let source = teststream_open();
     10 
     11 	let rlimit = limitreader(&source, 20);
     12 	match (write(&rlimit, buf)) {
     13 	case errors::unsupported => void;
     14 	case =>
     15 		abort();
     16 	};
     17 	match (read(&rlimit, buf)) {
     18 	case let n: size =>
     19 		assert(n == 15);
     20 	case error =>
     21 		abort();
     22 	};
     23 	match (read(&rlimit, buf)) {
     24 	case let n: size =>
     25 		assert(n == 5);
     26 	case error =>
     27 		abort();
     28 	};
     29 	assert(read(&rlimit, buf) is EOF);
     30 
     31 	let wlimit = limitwriter(&source, 20);
     32 	match (read(&wlimit, buf)) {
     33 	case errors::unsupported => void;
     34 	case =>
     35 		abort();
     36 	};
     37 	match (write(&wlimit, buf)) {
     38 	case let n: size =>
     39 		assert(n == 15);
     40 	case error =>
     41 		abort();
     42 	};
     43 	match (write(&wlimit, buf)) {
     44 	case let n: size =>
     45 		assert(n == 5);
     46 	case error =>
     47 		abort();
     48 	};
     49 	assert(write(&wlimit, buf) as size == 0z);
     50 };