source: tests/result.cfa @ 16e6905

Last change on this file since 16e6905 was 55b060d, checked in by Peter A. Buhr <pabuhr@…>, 14 months ago

rename directories containers to collections

  • Property mode set to 100644
File size: 1.5 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// result.c --
8//
9// Author           : Andrew Beach
10// Created On       : Thr May 25 16:50:00 2017
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Aug 30 21:46:34 2023
13// Update Count     : 3
14//
15
16#include <assert.h>
17#include <collections/result.hfa>
18
19void checkPredicates() {
20        result(int, char) pass = {1, 4};
21        assert(pass);
22        assert(has_value(&pass));
23
24        result(int, char) fail = {0, '!'};
25        assert((fail ? false : true));
26        assert(!has_value(&fail));
27}
28
29/* Waiting for bug#11 to be fixed.
30void checkNamedConstructors() {
31        result(int, char) = result_value(4);
32        assert(has_value(&pass));
33
34        result(int, char) fail = result_error('!');
35        assert(!has_value(&fail));
36}
37*/
38
39void checkGetters() {
40        result(int, char) pass = {1, 4};
41        assert(4 == get(&pass));
42
43        result(int, char) fail = {0, '!'};
44        assert('!' == get_error(&fail));
45}
46
47void checkSetters() {
48        result(int, char) fee = {1, -7};
49        assert(-7 == get(&fee));
50        set(&fee, 42);
51        assert(42 == get(&fee));
52        set_error(&fee, '@');
53        assert('@' == get_error(&fee));
54
55        result(int, char) fy = {1, -7};
56        fee = fy;
57        assert(-7 == get(&fee));
58        result(int, char) foe = {0, '!'};
59        fee = foe;
60        assert('!' == get_error(&fee));
61}
62
63int main(int argc, char * argv[]) {
64        checkPredicates();
65        //checkNamedConstructors();
66        checkGetters();
67        checkSetters();
68        printf( "done\n" );                             // non-empty .expect file
69}
Note: See TracBrowser for help on using the repository browser.